func (u *User) Valid(v *ValidMap) { if u.Password != u.PassConf { v.SetError("PassConf", T("valid_passmatch")) } if dm.Find(&Role{}, Sf{}, Where{And: W{"Id": u.Role}}) != nil { v.SetError("Role", T("valid_role")) } andW := W{"Login": u.Login, "Active": true} if u.Id > 0 { andW["Id!="] = u.Id } if dm.Find(&User{}, Sf{"Id"}, Where{And: andW, Or: W{"Login": u.Login, "Active": false}}) == nil { v.SetError("Login", T("valid_userex")) } if !v.HasErrors() { if pass, err := utils.HashPass(u.Password); err != nil { v.SetError("Password", T("valid_hash")) } else { u.Password = pass } } }
func (m *Profile) Valid(v *ValidMap) { if m.Password == "" { return } if m.Password != m.PassConf { v.SetError("PassConf", T("valid_passmatch")) return } pass, err := utils.HashPass(m.Password) if err != nil { v.SetError("Password", T("valid_hash")) return } m.Password = pass }