Improve user error handling.

This commit is contained in:
Gucheng Wang 2021-12-12 19:59:55 +08:00
parent 96e2f286ee
commit f4265d015a
5 changed files with 16 additions and 5 deletions

View File

@ -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())

View File

@ -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)

View File

@ -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
}

View File

@ -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: "",
}
}

View File

@ -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)