mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +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)
|
||||
if affected {
|
||||
original.AddUserToOriginalDatabase(user)
|
||||
if !affected {
|
||||
c.ResponseError(fmt.Sprintf("Failed to create user, user information is invalid: %s", util.StructToJson(user)))
|
||||
return
|
||||
}
|
||||
|
||||
original.AddUserToOriginalDatabase(user)
|
||||
|
||||
if application.HasPromptPage() {
|
||||
// The prompt page needs the user to be signed in
|
||||
c.SetSessionUsername(user.GetId())
|
||||
|
@ -300,7 +300,11 @@ func (c *ApiController) Login() {
|
||||
// sync info from 3rd-party if possible
|
||||
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)
|
||||
|
||||
|
@ -228,7 +228,7 @@ func (c *ApiController) SetPassword() {
|
||||
userId := fmt.Sprintf("%s/%s", userOwner, userName)
|
||||
targetUser := object.GetUser(userId)
|
||||
if targetUser == nil {
|
||||
c.ResponseError("Invalid user id.")
|
||||
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", userId))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
||||
user := GetUser(userId)
|
||||
if user == nil {
|
||||
return &Code{
|
||||
Message: "Invalid user_id",
|
||||
Message: fmt.Sprintf("The user: %s doesn't exist", userId),
|
||||
Code: "",
|
||||
}
|
||||
}
|
||||
|
@ -313,6 +313,10 @@ func AddUser(user *User) bool {
|
||||
user.Id = util.GenerateId()
|
||||
}
|
||||
|
||||
if user.Owner == "" || user.Name == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
organization := GetOrganizationByUser(user)
|
||||
user.UpdateUserPassword(organization)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user