Compare commits

..

5 Commits

Author SHA1 Message Date
chao
dffa68cbce feat: fix SAML login error bug (#1228)
* Update LoginPage.js

* fix saml login error
2022-10-20 01:14:38 +08:00
Gucheng Wang
fad209a7a3 Don't check username in UpdateUser() API 2022-10-19 22:50:19 +08:00
Gucheng Wang
8b222ce2e3 Use Steam ID as username 2022-10-18 22:07:20 +08:00
YunShu
c5293f428d fix: delete this accidentally added files (#1229)
* fix: delete this accidentally added files

* fix: ignore build result

* fix: remove unnecessary asterisk
2022-10-18 21:55:34 +08:00
Gucheng
146aec9ee8 feat: skip username restriction for new users coming from OAuth providers. (#1225) 2022-10-17 18:01:01 +08:00
8 changed files with 15 additions and 25 deletions

3
.gitignore vendored
View File

@@ -27,3 +27,6 @@ logs/
files/ files/
lastupdate.tmp lastupdate.tmp
commentsRouter*.go commentsRouter*.go
# ignore build result
casdoor

BIN
casdoor

Binary file not shown.

View File

@@ -203,12 +203,6 @@ func (c *ApiController) Signup() {
} }
} }
msg = object.CheckUsername(user.Name)
if msg != "" {
c.ResponseError(msg)
return
}
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)))

View File

@@ -411,12 +411,6 @@ func (c *ApiController) Login() {
// sync info from 3rd-party if possible // sync info from 3rd-party if possible
object.SetUserOAuthProperties(organization, user, provider.Type, userInfo) object.SetUserOAuthProperties(organization, user, provider.Type, userInfo)
msg := object.CheckUsername(user.Name)
if msg != "" {
c.ResponseError(msg)
return
}
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)))

View File

@@ -158,12 +158,6 @@ func (c *ApiController) UpdateUser() {
columns = strings.Split(columnsStr, ",") columns = strings.Split(columnsStr, ",")
} }
msg := object.CheckUsername(user.Name)
if msg != "" {
c.ResponseError(msg)
return
}
isGlobalAdmin := c.IsGlobalAdmin() isGlobalAdmin := c.IsGlobalAdmin()
affected := object.UpdateUser(id, &user, columns, isGlobalAdmin) affected := object.UpdateUser(id, &user, columns, isGlobalAdmin)
if affected { if affected {

View File

@@ -282,7 +282,7 @@ func getUser(gothUser goth.User, provider string) *UserInfo {
} }
} }
if provider == "steam" { if provider == "steam" {
user.Username = user.DisplayName user.Username = user.Id
user.Email = "" user.Email = ""
} }
return &user return &user

View File

@@ -59,6 +59,11 @@ func CheckUserSignup(application *Application, organization *Organization, usern
if reWhiteSpace.MatchString(username) { if reWhiteSpace.MatchString(username) {
return "username cannot contain white spaces" return "username cannot contain white spaces"
} }
msg := CheckUsername(username)
if msg != "" {
return msg
}
if HasUserByField(organization.Name, "name", username) { if HasUserByField(organization.Name, "name", username) {
return "username already exists" return "username already exists"
} }
@@ -314,16 +319,16 @@ func CheckAccessPermission(userId string, application *Application) (bool, error
return allowed, err return allowed, err
} }
func CheckUsername(name string) string { func CheckUsername(username string) string {
if name == "" { if username == "" {
return "Empty username." return "Empty username."
} else if len(name) > 39 { } else if len(username) > 39 {
return "Username is too long (maximum is 39 characters)." return "Username is too long (maximum is 39 characters)."
} }
// https://stackoverflow.com/questions/58726546/github-username-convention-using-regex // https://stackoverflow.com/questions/58726546/github-username-convention-using-regex
re, _ := regexp.Compile("^[a-zA-Z0-9]+((?:-[a-zA-Z0-9]+)|(?:_[a-zA-Z0-9]+))*$") re, _ := regexp.Compile("^[a-zA-Z0-9]+((?:-[a-zA-Z0-9]+)|(?:_[a-zA-Z0-9]+))*$")
if !re.MatchString(name) { if !re.MatchString(username) {
return "The username may only contain alphanumeric characters, underlines or hyphens, cannot have consecutive hyphens or underlines, and cannot begin or end with a hyphen or underline." return "The username may only contain alphanumeric characters, underlines or hyphens, cannot have consecutive hyphens or underlines, and cannot begin or end with a hyphen or underline."
} }

View File

@@ -156,8 +156,8 @@ class LoginPage extends React.Component {
values["type"] = "saml"; values["type"] = "saml";
} }
if (this.state.owner !== null && this.state.owner !== undefined) { if (this.state.application.organization !== null && this.state.application.organization !== undefined) {
values["organization"] = this.state.owner; values["organization"] = this.state.application.organization;
} }
} }
postCodeLoginAction(res) { postCodeLoginAction(res) {