MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / ValidateAndFill

Method ValidateAndFill

model/user.go:412–428  ·  view source on GitHub ↗

ValidateAndFill check password & user status

()

Source from the content-addressed store, hash-verified

410
411// ValidateAndFill check password & user status
412func (user *User) ValidateAndFill() (err error) {
413 // When querying with struct, GORM will only query with non-zero fields,
414 // that means if your field's value is 0, '', false or other zero values,
415 // it won't be used to build query conditions
416 password := user.Password
417 username := strings.TrimSpace(user.Username)
418 if username == "" || password == "" {
419 return errors.New("用户名或密码为空")
420 }
421 // find buy username or email
422 DB.Where("username = ? OR email = ?", username, username).First(user)
423 okay := common.ValidatePasswordAndHash(password, user.Password)
424 if !okay || user.Status != common.UserStatusEnabled {
425 return errors.New("用户名或密码错误,或用户已被封禁")
426 }
427 return nil
428}
429
430func (user *User) FillUserById() error {
431 if user.Id == 0 {

Callers 1

LoginFunction · 0.95

Calls 1

ValidatePasswordAndHashFunction · 0.92

Tested by

no test coverage detected