mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Use signup table in Signup API.
This commit is contained in:
@ -208,3 +208,34 @@ func (application *Application) GetEmailProvider() *Provider {
|
||||
func (application *Application) GetSmsProvider() *Provider {
|
||||
return application.getProviderByCategory("SMS")
|
||||
}
|
||||
|
||||
func (application *Application) getSignupItem(itemName string) *SignupItem {
|
||||
for _, signupItem := range application.SignupItems {
|
||||
if signupItem.Name == itemName {
|
||||
return signupItem
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (application *Application) IsSignupItemEnabled(itemName string) bool {
|
||||
return application.getSignupItem(itemName) != nil
|
||||
}
|
||||
|
||||
func (application *Application) IsSignupItemVisible(itemName string) bool {
|
||||
signupItem := application.getSignupItem(itemName)
|
||||
if signupItem == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return signupItem.Visible
|
||||
}
|
||||
|
||||
func (application *Application) GetSignupItemRule(itemName string) string {
|
||||
signupItem := application.getSignupItem(itemName)
|
||||
if signupItem == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return signupItem.Rule
|
||||
}
|
||||
|
@ -27,34 +27,54 @@ func init() {
|
||||
reWhiteSpace, _ = regexp.Compile("\\s")
|
||||
}
|
||||
|
||||
func CheckUserSignup(organizationName string, username string, password string, displayName string, email string, phone string, affiliation string) string {
|
||||
organization := getOrganization("admin", organizationName)
|
||||
|
||||
if len(username) <= 2 {
|
||||
return "username must have at least 3 characters"
|
||||
} else if len(password) <= 5 {
|
||||
return "password must have at least 6 characters"
|
||||
} else if organization == nil {
|
||||
func CheckUserSignup(application *Application, organization *Organization, username string, password string, displayName string, email string, phone string, affiliation string) string {
|
||||
if organization == nil {
|
||||
return "organization does not exist"
|
||||
} else if reWhiteSpace.MatchString(username) {
|
||||
return "username cannot contain white spaces"
|
||||
} else if HasUserByField(organizationName, "name", username) {
|
||||
return "username already exists"
|
||||
} else if HasUserByField(organizationName, "email", email) {
|
||||
return "email already exists"
|
||||
} else if HasUserByField(organizationName, "phone", phone) {
|
||||
return "phone already exists"
|
||||
} else if displayName == "" {
|
||||
return "displayName cannot be blank"
|
||||
} else if affiliation == "" {
|
||||
return "affiliation cannot be blank"
|
||||
} else if !util.IsEmailValid(email) {
|
||||
return "email is invalid"
|
||||
} else if organization.PhonePrefix == "86" && !util.IsPhoneCnValid(phone) {
|
||||
return "phone number is invalid"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
if application.IsSignupItemVisible("Username") {
|
||||
if len(username) <= 1 {
|
||||
return "username must have at least 2 characters"
|
||||
} else if reWhiteSpace.MatchString(username) {
|
||||
return "username cannot contain white spaces"
|
||||
} else if HasUserByField(organization.Name, "name", username) {
|
||||
return "username already exists"
|
||||
}
|
||||
}
|
||||
|
||||
if len(password) <= 5 {
|
||||
return "password must have at least 6 characters"
|
||||
}
|
||||
|
||||
if application.IsSignupItemVisible("Email") {
|
||||
if HasUserByField(organization.Name, "email", email) {
|
||||
return "email already exists"
|
||||
} else if !util.IsEmailValid(email) {
|
||||
return "email is invalid"
|
||||
}
|
||||
}
|
||||
|
||||
if application.IsSignupItemVisible("Phone") {
|
||||
if HasUserByField(organization.Name, "phone", phone) {
|
||||
return "phone already exists"
|
||||
} else if organization.PhonePrefix == "86" && !util.IsPhoneCnValid(phone) {
|
||||
return "phone number is invalid"
|
||||
}
|
||||
}
|
||||
|
||||
if application.IsSignupItemVisible("Display name") {
|
||||
if displayName == "" {
|
||||
return "displayName cannot be blank"
|
||||
}
|
||||
}
|
||||
|
||||
if application.IsSignupItemVisible("Affiliation") {
|
||||
if affiliation == "" {
|
||||
return "affiliation cannot be blank"
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func CheckPassword(user *User, password string) string {
|
||||
|
@ -114,6 +114,20 @@ func GetMaskedUsers(users []*User) []*User {
|
||||
return users
|
||||
}
|
||||
|
||||
func GetLastUser(owner string) *User {
|
||||
user := User{Owner: owner}
|
||||
existed, err := adapter.Engine.Desc("created_time", "id").Get(&user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if existed {
|
||||
return &user
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateUser(id string, user *User) bool {
|
||||
owner, name := util.GetOwnerAndNameFromId(id)
|
||||
if getUser(owner, name) == nil {
|
||||
|
Reference in New Issue
Block a user