diff --git a/controllers/account.go b/controllers/account.go index d5950823..33eb3e1e 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -35,6 +35,8 @@ type RequestForm struct { Username string `json:"username"` Password string `json:"password"` Name string `json:"name"` + FirstName string `json:"firstName"` + LastName string `json:"lastName"` Email string `json:"email"` Phone string `json:"phone"` Affiliation string `json:"affiliation"` @@ -102,7 +104,7 @@ func (c *ApiController) Signup() { } organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", form.Organization)) - msg := object.CheckUserSignup(application, organization, form.Username, form.Password, form.Name, form.Email, form.Phone, form.Affiliation) + msg := object.CheckUserSignup(application, organization, form.Username, form.Password, form.Name, form.FirstName, form.LastName, form.Email, form.Phone, form.Affiliation) if msg != "" { c.ResponseError(msg) return @@ -169,6 +171,12 @@ func (c *ApiController) Signup() { Properties: map[string]string{}, } + if application.GetSignupItemRule("Display name") == "First, last" { + user.DisplayName = fmt.Sprintf("%s %s", form.FirstName, form.LastName) + user.FirstName = form.FirstName + user.LastName = form.LastName + } + affected := object.AddUser(user) if !affected { c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user))) diff --git a/object/check.go b/object/check.go index 3c970303..98b06c8f 100644 --- a/object/check.go +++ b/object/check.go @@ -33,7 +33,7 @@ func init() { reFieldWhiteList, _ = regexp.Compile(`^[A-Za-z0-9]+$`) } -func CheckUserSignup(application *Application, organization *Organization, username string, password string, displayName string, email string, phone string, affiliation string) string { +func CheckUserSignup(application *Application, organization *Organization, username string, password string, displayName string, firstName string, lastName string, email string, phone string, affiliation string) string { if organization == nil { return "organization does not exist" } @@ -85,11 +85,19 @@ func CheckUserSignup(application *Application, organization *Organization, usern } if application.IsSignupItemVisible("Display name") { - if displayName == "" { - return "displayName cannot be blank" - } else if application.GetSignupItemRule("Display name") == "Real name" { - if !isValidRealName(displayName) { - return "displayName is not valid real name" + if application.GetSignupItemRule("Display name") == "First, last" { + if firstName == "" { + return "firstName cannot be blank" + } else if lastName == "" { + return "lastName cannot be blank" + } + } else { + if displayName == "" { + return "displayName cannot be blank" + } else if application.GetSignupItemRule("Display name") == "Real name" { + if !isValidRealName(displayName) { + return "displayName is not valid real name" + } } } } diff --git a/object/user.go b/object/user.go index 081cd288..f4d25cbf 100644 --- a/object/user.go +++ b/object/user.go @@ -34,6 +34,8 @@ type User struct { Password string `xorm:"varchar(100)" json:"password"` PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"` DisplayName string `xorm:"varchar(100)" json:"displayName"` + FirstName string `xorm:"varchar(100)" json:"firstName"` + LastName string `xorm:"varchar(100)" json:"lastName"` Avatar string `xorm:"varchar(500)" json:"avatar"` PermanentAvatar string `xorm:"varchar(500)" json:"permanentAvatar"` Email string `xorm:"varchar(100) index" json:"email"` diff --git a/web/src/Setting.js b/web/src/Setting.js index 7c6a2f5b..8f2c2b7d 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -325,6 +325,10 @@ export function getAvatarColor(s) { return colorList[random % 4]; } +export function getLanguage() { + return i18next.language; +} + export function setLanguage(language) { localStorage.setItem("language", language); changeMomentLanguage(language); diff --git a/web/src/SignupTable.js b/web/src/SignupTable.js index 5683ec6c..468e118e 100644 --- a/web/src/SignupTable.js +++ b/web/src/SignupTable.js @@ -171,6 +171,7 @@ class SignupTable extends React.Component { options = [ {id: 'None', name: 'None'}, {id: 'Real name', name: 'Real name'}, + {id: 'First, last', name: 'First, last'}, ]; } diff --git a/web/src/auth/SignupPage.js b/web/src/auth/SignupPage.js index f5044928..93144639 100644 --- a/web/src/auth/SignupPage.js +++ b/web/src/auth/SignupPage.js @@ -192,15 +192,50 @@ class SignupPage extends React.Component { ) } else if (signupItem.name === "Display name") { + if (signupItem.rule === "First, last" && Setting.getLanguage() !== "zh") { + return ( + + + + + + + + + ) + } + return (