On signup, handle duplicate key errors on email and username better
This commit is contained in:
parent
1133d90dcc
commit
2ebe0336ae
|
@ -266,7 +266,7 @@ Discourse.CreateAccountView = Discourse.ModalBodyView.extend({
|
|||
_this.flash(result.message);
|
||||
_this.set('complete', true);
|
||||
} else {
|
||||
_this.flash(result.message, 'error');
|
||||
_this.flash(result.message || Em.String.i18n('create_account.failed'), 'error');
|
||||
_this.set('formSubmitted', false);
|
||||
}
|
||||
if (result.active) {
|
||||
|
|
|
@ -192,6 +192,8 @@ class UsersController < ApplicationController
|
|||
else
|
||||
render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))}
|
||||
end
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
render :json => {success: false, message: I18n.t("login.something_already_taken")}
|
||||
rescue DiscourseHub::NicknameUnavailable
|
||||
render :json => {success: false, message: I18n.t("login.errors", errors:I18n.t("login.not_available", suggestion: User.suggest_username(params[:username])) )}
|
||||
rescue RestClient::Forbidden
|
||||
|
|
|
@ -456,6 +456,7 @@ en:
|
|||
not_activated: "You can't log in yet. We sent an activation email to you. Please follow the instructions in the email to activate your account."
|
||||
errors: "%{errors}"
|
||||
not_available: "Not available. Try %{suggestion}?"
|
||||
something_already_taken: "Something went wrong, perhaps the username or email is already registered. Try the forgot password link."
|
||||
omniauth_error: "Sorry, there was an error authorizing your %{strategy} account. Perhaps you did not approve authorization?"
|
||||
omniauth_error_unknown: "Something went wrong processing your log in, please try again."
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ describe UsersController do
|
|||
it_should_behave_like 'honeypot fails'
|
||||
end
|
||||
|
||||
shared_examples_for 'failed signup due to password problem' do
|
||||
shared_examples_for 'failed signup' do
|
||||
it 'should not create a new User' do
|
||||
expect { xhr :post, :create, create_params }.to_not change { User.count }
|
||||
end
|
||||
|
@ -394,12 +394,20 @@ describe UsersController do
|
|||
|
||||
context 'when password is blank' do
|
||||
let(:create_params) { {:name => @user.name, :username => @user.username, :password => "", :email => @user.email} }
|
||||
it_should_behave_like 'failed signup due to password problem'
|
||||
it_should_behave_like 'failed signup'
|
||||
end
|
||||
|
||||
context 'when password param is missing' do
|
||||
let(:create_params) { {:name => @user.name, :username => @user.username, :email => @user.email} }
|
||||
it_should_behave_like 'failed signup due to password problem'
|
||||
it_should_behave_like 'failed signup'
|
||||
end
|
||||
|
||||
context 'when InvalidStatement is raised' do
|
||||
before do
|
||||
User.any_instance.stubs(:save).raises(ActiveRecord::StatementInvalid)
|
||||
end
|
||||
let(:create_params) { {:name => @user.name, :username => @user.username, :password => "strongpassword", :email => @user.email} }
|
||||
it_should_behave_like 'failed signup'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue