Sfoglia il codice sorgente

add:用户登录信息

zoie 2 anni fa
parent
commit
0dd882fbb5
3 ha cambiato i file con 22 aggiunte e 1 eliminazioni
  1. 19 1
      controllers/Login.go
  2. 1 0
      go.mod
  3. 2 0
      go.sum

+ 19 - 1
controllers/Login.go

@@ -5,6 +5,7 @@ import (
 	"Cold_Api/models/Account"
 	"Cold_Api/models/System"
 	beego "github.com/beego/beego/v2/server/web"
+	"github.com/mssola/user_agent"
 	"time"
 )
 
@@ -17,6 +18,23 @@ func (c *AdminController) Login() {
 
 }
 
+// 获取用户登录信息
+func (c *AdminController) GetUserLoginInfo() map[string]interface{} {
+	//Ipaddr      ip地址
+	//Browser     浏览器
+	//Os          系统
+	//Platform    固件
+	l := make(map[string]interface{})
+	ua := user_agent.New(c.Ctx.Request.UserAgent())
+	l["ipaddr"] = c.Ctx.Input.IP()
+	l["remark"] = c.Ctx.Request.UserAgent()
+	browserName, browserVersion := ua.Browser()
+	l["browser"] = browserName + " " + browserVersion
+	l["os"] = ua.OS()
+	l["platform"] = ua.Platform()
+	return l
+}
+
 func (c *AdminController) Login_verification() {
 	Admin_user := c.GetString("bzd_username")
 	Admin_pass := c.GetString("bzd_password")
@@ -31,7 +49,7 @@ func (c *AdminController) Login_verification() {
 		c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
 		c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
 
-		System.Add_UserLogs(admin_r.T_uuid, "登陆", "用户登陆", "")
+		System.Add_UserLogs_T(admin_r.T_uuid, "登陆", "用户登陆", c.GetUserLoginInfo())
 
 	}
 

+ 1 - 0
go.mod

@@ -6,6 +6,7 @@ require (
 	github.com/astaxie/beego v1.12.3
 	github.com/beego/beego/v2 v2.0.7
 	github.com/go-sql-driver/mysql v1.7.0
+	github.com/mssola/user_agent v0.6.0
 	github.com/nats-io/nats.go v1.22.1
 	github.com/qiniu/go-sdk/v7 v7.14.0
 	github.com/satori/go.uuid v1.2.0

+ 2 - 0
go.sum

@@ -207,6 +207,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
+github.com/mssola/user_agent v0.6.0 h1:uwPR4rtWlCHRFyyP9u2KOV0u8iQXmS7Z7feTrstQwk4=
+github.com/mssola/user_agent v0.6.0/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw=
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=