mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-24 08:20:31 +08:00
Check more in CheckUserSignup().
This commit is contained in:
parent
904faae6eb
commit
7b32207443
@ -79,7 +79,7 @@ func (c *ApiController) Signup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userId := fmt.Sprintf("%s/%s", form.Organization, form.Username)
|
userId := fmt.Sprintf("%s/%s", form.Organization, form.Username)
|
||||||
msg := object.CheckUserSignup(userId, form.Password, form.Name, form.Email, form.PhonePrefix, form.Phone, form.Affiliation)
|
msg := object.CheckUserSignup(form.Organization, form.Username, form.Password, form.Name, form.Email, form.PhonePrefix, form.Phone, form.Affiliation)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
resp = Response{Status: "error", Msg: msg, Data: ""}
|
resp = Response{Status: "error", Msg: msg, Data: ""}
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,13 +27,21 @@ func init() {
|
|||||||
reWhiteSpace, _ = regexp.Compile("\\s")
|
reWhiteSpace, _ = regexp.Compile("\\s")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckUserSignup(userId string, password string, displayName string, email string, phonePrefix string, phone string, affiliation string) string {
|
func CheckUserSignup(organization string, username string, password string, displayName string, email string, phonePrefix string, phone string, affiliation string) string {
|
||||||
if len(userId) == 0 || len(password) == 0 {
|
if len(username) == 0 {
|
||||||
return "username and password cannot be blank"
|
return "username cannot be blank"
|
||||||
} else if reWhiteSpace.MatchString(userId) {
|
} else if len(password) == 0 {
|
||||||
|
return "password cannot be blank"
|
||||||
|
} else if getOrganization("admin", organization) == nil {
|
||||||
|
return "organization does not exist"
|
||||||
|
} else if reWhiteSpace.MatchString(username) {
|
||||||
return "username cannot contain white spaces"
|
return "username cannot contain white spaces"
|
||||||
} else if HasUser(userId) {
|
} else if HasUserByField(organization, "name", username) {
|
||||||
return "username already exists"
|
return "username already exists"
|
||||||
|
} else if HasUserByField(organization, "email", email) {
|
||||||
|
return "email already exists"
|
||||||
|
} else if HasUserByField(organization, "phone", phone) {
|
||||||
|
return "phone already exists"
|
||||||
} else if displayName == "" {
|
} else if displayName == "" {
|
||||||
return "displayName cannot be blank"
|
return "displayName cannot be blank"
|
||||||
} else if affiliation == "" {
|
} else if affiliation == "" {
|
||||||
|
@ -142,6 +142,10 @@ func GetUserByField(organizationName string, field string, value string) *User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasUserByField(organizationName string, field string, value string) bool {
|
||||||
|
return GetUserByField(organizationName, field, value) != nil
|
||||||
|
}
|
||||||
|
|
||||||
func SetUserField(user *User, field string, value string) bool {
|
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})
|
affected, err := adapter.engine.Table(user).ID(core.PK{user.Owner, user.Name}).Update(map[string]interface{}{field: value})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user