When login, peer doesn't exist, it should create
This commit is contained in:
+9
-1
@@ -34,11 +34,19 @@ func (ps *PeerService) FindByUserIdAndUuid(uuid string,userId uint) *model.Peer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UuidBindUserId 绑定用户id
|
// UuidBindUserId 绑定用户id
|
||||||
func (ps *PeerService) UuidBindUserId(uuid string, userId uint) {
|
func (ps *PeerService) UuidBindUserId(deviceId string, uuid string, userId uint) {
|
||||||
peer := ps.FindByUuid(uuid)
|
peer := ps.FindByUuid(uuid)
|
||||||
|
// 如果存在则更新
|
||||||
if peer.RowId > 0 {
|
if peer.RowId > 0 {
|
||||||
peer.UserId = userId
|
peer.UserId = userId
|
||||||
ps.Update(peer)
|
ps.Update(peer)
|
||||||
|
} else {
|
||||||
|
// 不存在则创建
|
||||||
|
global.DB.Create(&model.Peer{
|
||||||
|
Id: deviceId,
|
||||||
|
Uuid: uuid,
|
||||||
|
UserId: userId,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -83,7 +83,7 @@ func (us *UserService) Login(u *model.User, llog *model.LoginLog) *model.UserTok
|
|||||||
llog.UserTokenId = ut.UserId
|
llog.UserTokenId = ut.UserId
|
||||||
global.DB.Create(llog)
|
global.DB.Create(llog)
|
||||||
if llog.Uuid != "" {
|
if llog.Uuid != "" {
|
||||||
AllService.PeerService.UuidBindUserId(llog.Uuid, u.Id)
|
AllService.PeerService.UuidBindUserId(llog.DeviceId, llog.Uuid, u.Id)
|
||||||
}
|
}
|
||||||
return ut
|
return ut
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user