mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 11:59:17 -05:00
FIX: do not allow new email to be duplicate
FIX: return proper error message when email already exists
This commit is contained in:
parent
734450dcc3
commit
0064927077
3 changed files with 9 additions and 8 deletions
|
@ -9,10 +9,10 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
newEmailEmpty: Em.computed.empty('newEmail'),
|
newEmailEmpty: Em.computed.empty('newEmail'),
|
||||||
saveDisabled: Em.computed.or('saving', 'newEmailEmpty', 'taken', 'unchanged'),
|
saveDisabled: Em.computed.or('saving', 'newEmailEmpty', 'taken', 'unchanged'),
|
||||||
unchanged: propertyEqual('newEmailLower', 'email'),
|
unchanged: propertyEqual('newEmailLower', 'currentUser.email'),
|
||||||
|
|
||||||
newEmailLower: function() {
|
newEmailLower: function() {
|
||||||
return this.get('newEmail').toLowerCase();
|
return this.get('newEmail').toLowerCase().trim();
|
||||||
}.property('newEmail'),
|
}.property('newEmail'),
|
||||||
|
|
||||||
saveButtonText: function() {
|
saveButtonText: function() {
|
||||||
|
|
|
@ -483,9 +483,7 @@ class UsersController < ApplicationController
|
||||||
return render_json_error(user.errors.full_messages) if user.errors[:email].present?
|
return render_json_error(user.errors.full_messages) if user.errors[:email].present?
|
||||||
|
|
||||||
# Raise an error if the email is already in use
|
# Raise an error if the email is already in use
|
||||||
if User.find_by_email(lower_email)
|
return render_json_error(I18n.t('change_email.error')) if User.find_by_email(lower_email)
|
||||||
raise Discourse::InvalidParameters.new(:email)
|
|
||||||
end
|
|
||||||
|
|
||||||
email_token = user.email_tokens.create(email: lower_email)
|
email_token = user.email_tokens.create(email: lower_email)
|
||||||
Jobs.enqueue(
|
Jobs.enqueue(
|
||||||
|
|
|
@ -242,11 +242,13 @@ describe UsersController do
|
||||||
context 'when the new email address is taken' do
|
context 'when the new email address is taken' do
|
||||||
let!(:other_user) { Fabricate(:coding_horror) }
|
let!(:other_user) { Fabricate(:coding_horror) }
|
||||||
it 'raises an error' do
|
it 'raises an error' do
|
||||||
expect { xhr :put, :change_email, username: user.username, email: other_user.email }.to raise_error(Discourse::InvalidParameters)
|
xhr :put, :change_email, username: user.username, email: other_user.email
|
||||||
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an error if there is whitespace too' do
|
it 'raises an error if there is whitespace too' do
|
||||||
expect { xhr :put, :change_email, username: user.username, email: other_user.email + ' ' }.to raise_error(Discourse::InvalidParameters)
|
xhr :put, :change_email, username: user.username, email: other_user.email + ' '
|
||||||
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -254,7 +256,8 @@ describe UsersController do
|
||||||
let!(:other_user) { Fabricate(:user, email: 'case.insensitive@gmail.com')}
|
let!(:other_user) { Fabricate(:user, email: 'case.insensitive@gmail.com')}
|
||||||
|
|
||||||
it 'raises an error' do
|
it 'raises an error' do
|
||||||
expect { xhr :put, :change_email, username: user.username, email: other_user.email.upcase }.to raise_error(Discourse::InvalidParameters)
|
xhr :put, :change_email, username: user.username, email: other_user.email.upcase
|
||||||
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue