delete the token when delete a peer
This commit is contained in:
@@ -94,16 +94,40 @@ func (ps *PeerService) Create(u *model.Peer) error {
|
|||||||
res := global.DB.Create(u).Error
|
res := global.DB.Create(u).Error
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete 删除, 同时也应该删除token
|
||||||
func (ps *PeerService) Delete(u *model.Peer) error {
|
func (ps *PeerService) Delete(u *model.Peer) error {
|
||||||
return global.DB.Delete(u).Error
|
uuid := u.Uuid
|
||||||
|
err := global.DB.Delete(u).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 删除token
|
||||||
|
return AllService.UserService.FlushTokenByUuid(uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchDelete
|
// GetUuidListByIDs 根据ids获取uuid列表
|
||||||
|
func (ps *PeerService) GetUuidListByIDs(ids []uint) ([]string, error) {
|
||||||
|
var uuids []string
|
||||||
|
err := global.DB.Model(&model.Peer{}).
|
||||||
|
Where("row_id in (?)", ids).
|
||||||
|
Pluck("uuid", &uuids).Error
|
||||||
|
return uuids, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchDelete 批量删除, 同时也应该删除token
|
||||||
func (ps *PeerService) BatchDelete(ids []uint) error {
|
func (ps *PeerService) BatchDelete(ids []uint) error {
|
||||||
return global.DB.Where("row_id in (?)", ids).Delete(&model.Peer{}).Error
|
uuids, err := ps.GetUuidListByIDs(ids)
|
||||||
|
err = global.DB.Where("row_id in (?)", ids).Delete(&model.Peer{}).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 删除token
|
||||||
|
return AllService.UserService.FlushTokenByUuids(uuids)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update 更新
|
// Update 更新
|
||||||
func (ps *PeerService) Update(u *model.Peer) error {
|
func (ps *PeerService) Update(u *model.Peer) error {
|
||||||
return global.DB.Model(u).Updates(u).Error
|
return global.DB.Model(u).Updates(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,16 @@ func (us *UserService) FlushToken(u *model.User) error {
|
|||||||
return global.DB.Where("user_id = ?", u.Id).Delete(&model.UserToken{}).Error
|
return global.DB.Where("user_id = ?", u.Id).Delete(&model.UserToken{}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FlushTokenByUuid 清空token
|
||||||
|
func (us *UserService) FlushTokenByUuid(uuid string) error {
|
||||||
|
return global.DB.Where("device_uuid = ?", uuid).Delete(&model.UserToken{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// FlushTokenByUuids 清空token
|
||||||
|
func (us *UserService) FlushTokenByUuids(uuids []string) error {
|
||||||
|
return global.DB.Where("device_uuid in (?)", uuids).Delete(&model.UserToken{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
// UpdatePassword 更新密码
|
// UpdatePassword 更新密码
|
||||||
func (us *UserService) UpdatePassword(u *model.User, password string) error {
|
func (us *UserService) UpdatePassword(u *model.User, password string) error {
|
||||||
u.Password = us.EncryptPassword(password)
|
u.Password = us.EncryptPassword(password)
|
||||||
|
|||||||
Reference in New Issue
Block a user