|
|
|
@@ -1,31 +1,34 @@ |
|
|
|
package models |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"time" |
|
|
|
"net/http" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
) |
|
|
|
|
|
|
|
type UserLoginLog struct { |
|
|
|
ID int64 `xorm:"pk autoincr"` |
|
|
|
uid int64 `xorm:"NOT NULL"` |
|
|
|
ipAddr string `xorm:"default NULL"` |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"created"` |
|
|
|
ID int64 `xorm:"pk autoincr"` |
|
|
|
uid int64 `xorm:"NOT NULL"` |
|
|
|
ipAddr string `xorm:"default NULL"` |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"created"` |
|
|
|
} |
|
|
|
|
|
|
|
func SaveLoginInfoToDb(r *http.Request,u User){ |
|
|
|
func SaveLoginInfoToDb(r *http.Request, u *User) { |
|
|
|
statictisSess := xStatistic.NewSession() |
|
|
|
defer statictisSess.Close() |
|
|
|
|
|
|
|
|
|
|
|
var dateRecord UserLoginLog |
|
|
|
|
|
|
|
} |
|
|
|
dateRecord.uid = u.ID |
|
|
|
dateRecord.ipAddr = getIP(r) |
|
|
|
|
|
|
|
statictisSess.Insert(&dateRecord) |
|
|
|
} |
|
|
|
|
|
|
|
func getIP(r *http.Request) string { |
|
|
|
forwarded := r.Header.Get("X-FORWARDED-FOR") |
|
|
|
if forwarded != "" { |
|
|
|
return forwarded |
|
|
|
} |
|
|
|
func getIP(r *http.Request) string { |
|
|
|
forwarded := r.Header.Get("X-FORWARDED-FOR") |
|
|
|
if forwarded != "" { |
|
|
|
return forwarded |
|
|
|
} |
|
|
|
return r.RemoteAddr |
|
|
|
} |
|
|
|
} |