Support Email and phone login.

This commit is contained in:
Yang Luo
2021-05-01 20:23:20 +08:00
parent 5b1b8662ac
commit 0f7cd56441
5 changed files with 30 additions and 8 deletions

View File

@ -56,9 +56,9 @@ func CheckUserSignup(organization string, username string, password string, disp
}
func CheckUserLogin(organization string, username string, password string) (*User, string) {
user := GetUserByField(organization, "name", username)
user := GetUserByFields(organization, username)
if user == nil {
return nil, "username does not exist, please sign up first"
return nil, "the user does not exist, please sign up first"
}
if user.Password != password {

View File

@ -146,6 +146,28 @@ func HasUserByField(organizationName string, field string, value string) bool {
return GetUserByField(organizationName, field, value) != nil
}
func GetUserByFields(organization string, field string) *User {
// check username
user := GetUserByField(organization, "name", field)
if user != nil {
return user
}
// check email
user = GetUserByField(organization, "email", field)
if user != nil {
return user
}
// check phone
user = GetUserByField(organization, "phone", field)
if user != nil {
return user
}
return nil
}
func SetUserField(user *User, field string, value string) bool {
affected, err := adapter.engine.Table(user).ID(core.PK{user.Owner, user.Name}).Update(map[string]interface{}{field: value})
if err != nil {