mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
On signup, handle duplicate key errors on email and username better
This commit is contained in:
parent
1133d90dcc
commit
2ebe0336ae
4 changed files with 15 additions and 4 deletions
|
@ -266,7 +266,7 @@ Discourse.CreateAccountView = Discourse.ModalBodyView.extend({
|
||||||
_this.flash(result.message);
|
_this.flash(result.message);
|
||||||
_this.set('complete', true);
|
_this.set('complete', true);
|
||||||
} else {
|
} else {
|
||||||
_this.flash(result.message, 'error');
|
_this.flash(result.message || Em.String.i18n('create_account.failed'), 'error');
|
||||||
_this.set('formSubmitted', false);
|
_this.set('formSubmitted', false);
|
||||||
}
|
}
|
||||||
if (result.active) {
|
if (result.active) {
|
||||||
|
|
|
@ -192,6 +192,8 @@ class UsersController < ApplicationController
|
||||||
else
|
else
|
||||||
render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))}
|
render :json => {success: false, message: I18n.t("login.errors", errors: user.errors.full_messages.join("\n"))}
|
||||||
end
|
end
|
||||||
|
rescue ActiveRecord::StatementInvalid
|
||||||
|
render :json => {success: false, message: I18n.t("login.something_already_taken")}
|
||||||
rescue DiscourseHub::NicknameUnavailable
|
rescue DiscourseHub::NicknameUnavailable
|
||||||
render :json => {success: false, message: I18n.t("login.errors", errors:I18n.t("login.not_available", suggestion: User.suggest_username(params[:username])) )}
|
render :json => {success: false, message: I18n.t("login.errors", errors:I18n.t("login.not_available", suggestion: User.suggest_username(params[:username])) )}
|
||||||
rescue RestClient::Forbidden
|
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."
|
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}"
|
errors: "%{errors}"
|
||||||
not_available: "Not available. Try %{suggestion}?"
|
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: "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."
|
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'
|
it_should_behave_like 'honeypot fails'
|
||||||
end
|
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
|
it 'should not create a new User' do
|
||||||
expect { xhr :post, :create, create_params }.to_not change { User.count }
|
expect { xhr :post, :create, create_params }.to_not change { User.count }
|
||||||
end
|
end
|
||||||
|
@ -394,12 +394,20 @@ describe UsersController do
|
||||||
|
|
||||||
context 'when password is blank' do
|
context 'when password is blank' do
|
||||||
let(:create_params) { {:name => @user.name, :username => @user.username, :password => "", :email => @user.email} }
|
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
|
end
|
||||||
|
|
||||||
context 'when password param is missing' do
|
context 'when password param is missing' do
|
||||||
let(:create_params) { {:name => @user.name, :username => @user.username, :email => @user.email} }
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue