mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 18:54:03 +08:00
Improve user error handling.
This commit is contained in:
parent
96e2f286ee
commit
f4265d015a
@ -162,10 +162,13 @@ func (c *ApiController) Signup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
affected := object.AddUser(user)
|
affected := object.AddUser(user)
|
||||||
if affected {
|
if !affected {
|
||||||
original.AddUserToOriginalDatabase(user)
|
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
original.AddUserToOriginalDatabase(user)
|
||||||
|
|
||||||
if application.HasPromptPage() {
|
if application.HasPromptPage() {
|
||||||
// The prompt page needs the user to be signed in
|
// The prompt page needs the user to be signed in
|
||||||
c.SetSessionUsername(user.GetId())
|
c.SetSessionUsername(user.GetId())
|
||||||
|
@ -300,7 +300,11 @@ 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)
|
||||||
|
|
||||||
object.AddUser(user)
|
affected := object.AddUser(user)
|
||||||
|
if !affected {
|
||||||
|
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
object.LinkUserAccount(user, provider.Type, userInfo.Id)
|
object.LinkUserAccount(user, provider.Type, userInfo.Id)
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
||||||
targetUser := object.GetUser(userId)
|
targetUser := object.GetUser(userId)
|
||||||
if targetUser == nil {
|
if targetUser == nil {
|
||||||
c.ResponseError("Invalid user id.")
|
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", userId))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
|||||||
user := GetUser(userId)
|
user := GetUser(userId)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return &Code{
|
return &Code{
|
||||||
Message: "Invalid user_id",
|
Message: fmt.Sprintf("The user: %s doesn't exist", userId),
|
||||||
Code: "",
|
Code: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,6 +313,10 @@ func AddUser(user *User) bool {
|
|||||||
user.Id = util.GenerateId()
|
user.Id = util.GenerateId()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.Owner == "" || user.Name == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
organization := GetOrganizationByUser(user)
|
organization := GetOrganizationByUser(user)
|
||||||
user.UpdateUserPassword(organization)
|
user.UpdateUserPassword(organization)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user