Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Error message on database user creation if user already exists #443

Merged
merged 9 commits into from Jul 10, 2017
Merged
2 changes: 2 additions & 0 deletions Lock/Base.lproj/Lock.strings
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
"com.auth0.lock.error.signup.password_no_user_info_error" = "PASSWORD IS BASED ON USER INFORMATION.";
// password_strength_error
"com.auth0.lock.error.signup.password_strength_error" = "PASSWORD IS TOO WEAK.";
// user_exists
"com.auth0.lock.error.signup.user_exists" = "THE USER ALREADY EXISTS.";
// Unrecoverable error button
"com.auth0.lock.error.unrecoverable.button" = "Contact support";
// Default error
Expand Down
3 changes: 3 additions & 0 deletions Lock/DatabaseInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ struct DatabaseInteractor: DatabaseAuthenticatable, DatabaseUserCreator, Loggabl
case .failure(let cause as AuthenticationError) where cause.code == "invalid_password":
callback(.passwordInvalid, nil)
self.dispatcher.dispatch(result: .error(DatabaseUserCreatorError.passwordInvalid))
case .failure(let cause as AuthenticationError) where cause.code == "user_exists":
callback(.userExists, nil)
self.dispatcher.dispatch(result: .error(DatabaseUserCreatorError.userExists))
case .failure:
callback(.couldNotCreateUser, nil)
self.dispatcher.dispatch(result: .error(DatabaseUserCreatorError.couldNotCreateUser))
Expand Down
3 changes: 3 additions & 0 deletions Lock/DatabaseUserCreatorError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum DatabaseUserCreatorError: Error, LocalizableError {
case passwordHasUserInfo
case passwordInvalid
case passwordAlreadyUsed
case userExists

var localizableMessage: String {
switch self {
Expand All @@ -43,6 +44,8 @@ enum DatabaseUserCreatorError: Error, LocalizableError {
return "PASSWORD HAS PREVIOUSLY BEEN USED.".i18n(key: "com.auth0.lock.error.signup.password_history", comment: "password_history")
case .passwordInvalid:
return "PASSWORD IS INVALID.".i18n(key: "com.auth0.lock.error.signup.invalid_password", comment: "invalid_password")
case .userExists:
return "THE USER ALREADY EXISTS.".i18n(key: "com.auth0.lock.error.signup.user_exists", comment: "user_exists")
default:
return "WE'RE SORRY, SOMETHING WENT WRONG WHEN ATTEMPTING TO SIGN UP.".i18n(key: "com.auth0.lock.error.signup.fallback", comment: "Generic sign up error")
}
Expand Down
6 changes: 5 additions & 1 deletion LockTests/DatabaseUserCreatorErrorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class DatabaseUserCreatorErrorSpec: QuickSpec {
let error = DatabaseUserCreatorError.nonValidInput
expect(error.localizableMessage).to(contain("SOMETHING WENT WRONG"))
}


it(".userExists should return relevant string") {
let error = DatabaseUserCreatorError.userExists
expect(error.localizableMessage).to(contain("USER ALREADY EXISTS"))
}
}

describe("user visibility") {
Expand Down