Browse Source

add DeviceId to userToken

Tao Chen 1 year ago
parent
commit
75b997dcc4
5 changed files with 6 additions and 1 deletions
  1. 1 0
      http/controller/api/login.go
  2. 1 0
      http/controller/api/ouath.go
  3. 1 0
      model/loginLog.go
  4. 2 1
      model/userToken.go
  5. 1 0
      service/user.go

+ 1 - 0
http/controller/api/login.go

@@ -60,6 +60,7 @@ func (l *Login) Login(c *gin.Context) {
60
 	ut := service.AllService.UserService.Login(u, &model.LoginLog{
60
 	ut := service.AllService.UserService.Login(u, &model.LoginLog{
61
 		UserId:   u.Id,
61
 		UserId:   u.Id,
62
 		Client:   f.DeviceInfo.Type,
62
 		Client:   f.DeviceInfo.Type,
63
+		DeviceId:       f.Id,
63
 		Uuid:     f.Uuid,
64
 		Uuid:     f.Uuid,
64
 		Ip:       c.ClientIP(),
65
 		Ip:       c.ClientIP(),
65
 		Type:     model.LoginLogTypeAccount,
66
 		Type:     model.LoginLogTypeAccount,

+ 1 - 0
http/controller/api/ouath.go

@@ -94,6 +94,7 @@ func (o *Oauth) OidcAuthQueryPre(c *gin.Context) (*model.User, *model.UserToken)
94
 	ut = service.AllService.UserService.Login(u, &model.LoginLog{
94
 	ut = service.AllService.UserService.Login(u, &model.LoginLog{
95
 		UserId:   u.Id,
95
 		UserId:   u.Id,
96
 		Client:   v.DeviceType,
96
 		Client:   v.DeviceType,
97
+		DeviceId: v.Id,
97
 		Uuid:     v.Uuid,
98
 		Uuid:     v.Uuid,
98
 		Ip:       c.ClientIP(),
99
 		Ip:       c.ClientIP(),
99
 		Type:     model.LoginLogTypeOauth,
100
 		Type:     model.LoginLogTypeOauth,

+ 1 - 0
model/loginLog.go

@@ -4,6 +4,7 @@ type LoginLog struct {
4
 	IdModel
4
 	IdModel
5
 	UserId      uint   `json:"user_id" gorm:"default:0;not null;"`
5
 	UserId      uint   `json:"user_id" gorm:"default:0;not null;"`
6
 	Client      string `json:"client"` //webadmin,webclient,app,
6
 	Client      string `json:"client"` //webadmin,webclient,app,
7
+	DeviceId	string `json:"device_id"`
7
 	Uuid        string `json:"uuid"`
8
 	Uuid        string `json:"uuid"`
8
 	Ip          string `json:"ip"`
9
 	Ip          string `json:"ip"`
9
 	Type        string `json:"type"`     //account,oauth
10
 	Type        string `json:"type"`     //account,oauth

+ 2 - 1
model/userToken.go

@@ -3,7 +3,8 @@ package model
3
 type UserToken struct {
3
 type UserToken struct {
4
 	IdModel
4
 	IdModel
5
 	UserId    	uint   `json:"user_id" gorm:"default:0;not null;index"`
5
 	UserId    	uint   `json:"user_id" gorm:"default:0;not null;index"`
6
-	DeviceUuid 	string `json:"device_uuid"`
6
+	DeviceUuid 	string `json:"device_uuid" gorm:"default:'';omitempty;"`
7
+	DeviceId	string `json:"device_id" gorm:"default:'';omitempty;"`
7
 	Token     	string `json:"token" gorm:"default:'';not null;index"`
8
 	Token     	string `json:"token" gorm:"default:'';not null;index"`
8
 	ExpiredAt 	int64  `json:"expired_at" gorm:"default:0;not null;"`
9
 	ExpiredAt 	int64  `json:"expired_at" gorm:"default:0;not null;"`
9
 	TimeModel
10
 	TimeModel

+ 1 - 0
service/user.go

@@ -76,6 +76,7 @@ func (us *UserService) Login(u *model.User, llog *model.LoginLog) *model.UserTok
76
 		UserId:    	u.Id,
76
 		UserId:    	u.Id,
77
 		Token:     	token,
77
 		Token:     	token,
78
 		DeviceUuid: llog.Uuid,
78
 		DeviceUuid: llog.Uuid,
79
+		DeviceId:   llog.DeviceId,
79
 		ExpiredAt: 	time.Now().Add(time.Hour * 24 * 7).Unix(),
80
 		ExpiredAt: 	time.Now().Add(time.Hour * 24 * 7).Unix(),
80
 	}
81
 	}
81
 	global.DB.Create(ut)
82
 	global.DB.Create(ut)