You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_login_log.go 712 B

12345678910111213141516171819202122232425262728293031323334
  1. package models
  2. import (
  3. "net/http"
  4. "code.gitea.io/gitea/modules/timeutil"
  5. )
  6. type UserLoginLog struct {
  7. ID int64 `xorm:"pk autoincr"`
  8. UId int64 `xorm:"NOT NULL"`
  9. IpAddr string `xorm:"default NULL"`
  10. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  11. }
  12. func SaveLoginInfoToDb(r *http.Request, u *User) {
  13. statictisSess := xStatistic.NewSession()
  14. defer statictisSess.Close()
  15. var dateRecord UserLoginLog
  16. dateRecord.UId = u.ID
  17. dateRecord.IpAddr = getIP(r)
  18. statictisSess.Insert(&dateRecord)
  19. }
  20. func getIP(r *http.Request) string {
  21. forwarded := r.Header.Get("X-FORWARDED-FOR")
  22. if forwarded != "" {
  23. return forwarded
  24. }
  25. return r.RemoteAddr
  26. }