Browse Source

add IsPasswordEmpty...

Tao Chen 1 year ago
parent
commit
bd2eeae01a
1 changed files with 24 additions and 0 deletions
  1. 24 0
      service/user.go

+ 24 - 0
service/user.go

@@ -304,3 +304,27 @@ func (us *UserService) FindLatestUserIdFromLoginLogByUuid(uuid string) uint {
304 304
 	global.DB.Where("uuid = ?", uuid).Order("id desc").First(llog)
305 305
 	return llog.UserId
306 306
 }
307
+
308
+// IsPasswordEmptyById 根据用户id判断密码是否为空,主要用于第三方登录的自动注册
309
+func (us *UserService) IsPasswordEmptyById(id uint) bool {
310
+	u := &model.User{}
311
+	if global.DB.Where("id = ?", id).First(u).Error != nil {
312
+		return false
313
+	}
314
+	return u.Password == ""
315
+}
316
+
317
+// IsPasswordEmptyByUsername 根据用户id判断密码是否为空,主要用于第三方登录的自动注册
318
+func (us *UserService) IsPasswordEmptyByUsername(username string) bool {
319
+	u := &model.User{}
320
+	if global.DB.Where("username = ?", username).First(u).Error != nil {
321
+		return false
322
+	}
323
+	return u.Password == ""
324
+}
325
+
326
+// IsPasswordEmptyByUser 判断密码是否为空,主要用于第三方登录的自动注册
327
+func (us *UserService) IsPasswordEmptyByUser(u *model.User) bool {
328
+	return us.IsPasswordEmptyById(u.Id)
329
+}
330
+