Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1
zouap 4 years ago
parent
commit
f3b530b249
1 changed files with 19 additions and 16 deletions
  1. +19
    -16
      models/user_login_log.go

+ 19
- 16
models/user_login_log.go View File

@@ -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
}
}

Loading…
Cancel
Save