mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-09 21:32:56 +08:00
Support user's first name and last name.
This commit is contained in:
@@ -35,6 +35,8 @@ type RequestForm struct {
|
|||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
FirstName string `json:"firstName"`
|
||||||
|
LastName string `json:"lastName"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
Affiliation string `json:"affiliation"`
|
Affiliation string `json:"affiliation"`
|
||||||
@@ -102,7 +104,7 @@ func (c *ApiController) Signup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
organization := object.GetOrganization(fmt.Sprintf("%s/%s", "admin", form.Organization))
|
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 != "" {
|
if msg != "" {
|
||||||
c.ResponseError(msg)
|
c.ResponseError(msg)
|
||||||
return
|
return
|
||||||
@@ -169,6 +171,12 @@ func (c *ApiController) Signup() {
|
|||||||
Properties: map[string]string{},
|
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)
|
affected := object.AddUser(user)
|
||||||
if !affected {
|
if !affected {
|
||||||
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
||||||
|
@@ -33,7 +33,7 @@ func init() {
|
|||||||
reFieldWhiteList, _ = regexp.Compile(`^[A-Za-z0-9]+$`)
|
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 {
|
if organization == nil {
|
||||||
return "organization does not exist"
|
return "organization does not exist"
|
||||||
}
|
}
|
||||||
@@ -85,11 +85,19 @@ func CheckUserSignup(application *Application, organization *Organization, usern
|
|||||||
}
|
}
|
||||||
|
|
||||||
if application.IsSignupItemVisible("Display name") {
|
if application.IsSignupItemVisible("Display name") {
|
||||||
if displayName == "" {
|
if application.GetSignupItemRule("Display name") == "First, last" {
|
||||||
return "displayName cannot be blank"
|
if firstName == "" {
|
||||||
} else if application.GetSignupItemRule("Display name") == "Real name" {
|
return "firstName cannot be blank"
|
||||||
if !isValidRealName(displayName) {
|
} else if lastName == "" {
|
||||||
return "displayName is not valid real name"
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ type User struct {
|
|||||||
Password string `xorm:"varchar(100)" json:"password"`
|
Password string `xorm:"varchar(100)" json:"password"`
|
||||||
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
|
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
|
||||||
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
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"`
|
Avatar string `xorm:"varchar(500)" json:"avatar"`
|
||||||
PermanentAvatar string `xorm:"varchar(500)" json:"permanentAvatar"`
|
PermanentAvatar string `xorm:"varchar(500)" json:"permanentAvatar"`
|
||||||
Email string `xorm:"varchar(100) index" json:"email"`
|
Email string `xorm:"varchar(100) index" json:"email"`
|
||||||
|
@@ -325,6 +325,10 @@ export function getAvatarColor(s) {
|
|||||||
return colorList[random % 4];
|
return colorList[random % 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLanguage() {
|
||||||
|
return i18next.language;
|
||||||
|
}
|
||||||
|
|
||||||
export function setLanguage(language) {
|
export function setLanguage(language) {
|
||||||
localStorage.setItem("language", language);
|
localStorage.setItem("language", language);
|
||||||
changeMomentLanguage(language);
|
changeMomentLanguage(language);
|
||||||
|
@@ -171,6 +171,7 @@ class SignupTable extends React.Component {
|
|||||||
options = [
|
options = [
|
||||||
{id: 'None', name: 'None'},
|
{id: 'None', name: 'None'},
|
||||||
{id: 'Real name', name: 'Real name'},
|
{id: 'Real name', name: 'Real name'},
|
||||||
|
{id: 'First, last', name: 'First, last'},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -192,15 +192,50 @@ class SignupPage extends React.Component {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
)
|
)
|
||||||
} else if (signupItem.name === "Display name") {
|
} else if (signupItem.name === "Display name") {
|
||||||
|
if (signupItem.rule === "First, last" && Setting.getLanguage() !== "zh") {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<Form.Item
|
||||||
|
name="firstName"
|
||||||
|
key="firstName"
|
||||||
|
label={i18next.t("general:First name")}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: required,
|
||||||
|
message: i18next.t("signup:Please input your first name!"),
|
||||||
|
whitespace: true,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="lastName"
|
||||||
|
key="lastName"
|
||||||
|
label={i18next.t("general:Last name")}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: required,
|
||||||
|
message: i18next.t("signup:Please input your last name!"),
|
||||||
|
whitespace: true,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="name"
|
name="name"
|
||||||
key="name"
|
key="name"
|
||||||
label={signupItem.rule === "Real name" ? i18next.t("general:Real name") : i18next.t("general:Display name")}
|
label={(signupItem.rule === "Real name" || signupItem.rule === "First, last") ? i18next.t("general:Real name") : i18next.t("general:Display name")}
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: required,
|
required: required,
|
||||||
message: signupItem.rule === "Real name" ? i18next.t("signup:Please input your real name!") : i18next.t("signup:Please input your display name!"),
|
message: (signupItem.rule === "Real name" || signupItem.rule === "First, last") ? i18next.t("signup:Please input your real name!") : i18next.t("signup:Please input your display name!"),
|
||||||
whitespace: true,
|
whitespace: true,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
Reference in New Issue
Block a user