* VRFS-311; reject users that try to set their email to the same email as it currently is
This commit is contained in:
parent
2dfdf8463c
commit
5f31daccd1
|
|
@ -52,7 +52,7 @@ module JamRuby
|
||||||
def updating_email(user)
|
def updating_email(user)
|
||||||
@user = user
|
@user = user
|
||||||
sendgrid_unique_args :type => "updating_email"
|
sendgrid_unique_args :type => "updating_email"
|
||||||
mail(:to => user.email, :subject => "Jamkazam Email Change Confirmation") do |format|
|
mail(:to => user.update_email, :subject => "Jamkazam Email Change Confirmation") do |format|
|
||||||
format.text
|
format.text
|
||||||
format.html
|
format.html
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ module ValidationMessages
|
||||||
# user
|
# user
|
||||||
OLD_PASSWORD_DOESNT_MATCH = "Your old password is incorrect."
|
OLD_PASSWORD_DOESNT_MATCH = "Your old password is incorrect."
|
||||||
EMAIL_NOT_FOUND = "Email address not found."
|
EMAIL_NOT_FOUND = "Email address not found."
|
||||||
NOT_YOUR_PASSWORD = "The password you entered is not your current password."
|
NOT_YOUR_PASSWORD = "is not your current password"
|
||||||
EMAIL_ALREADY_TAKEN = "This email is already taken."
|
EMAIL_ALREADY_TAKEN = "is already taken"
|
||||||
|
EMAIL_MATCHES_CURRENT = "is same as your current email"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ module JamRuby
|
||||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
||||||
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
||||||
uniqueness: {case_sensitive: false}
|
uniqueness: {case_sensitive: false}
|
||||||
validates :update_email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
validates :update_email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
||||||
uniqueness: {case_sensitive: false}, :if => :updating_email
|
uniqueness: {case_sensitive: false}, :if => :updating_email
|
||||||
validates_length_of :password, minimum: 6, maximum: 100, :if => :should_validate_password?
|
validates_length_of :password, minimum: 6, maximum: 100, :if => :should_validate_password?
|
||||||
|
|
||||||
|
|
@ -138,7 +138,11 @@ module JamRuby
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_update_email
|
def check_update_email
|
||||||
errors.add(:update_email, ValidationMessages::EMAIL_ALREADY_TAKEN) if updating_email && User.find_by_email(self.update_email) != nil
|
if updating_email && self.update_email == self.email
|
||||||
|
errors.add(:update_email, ValidationMessages::EMAIL_MATCHES_CURRENT)
|
||||||
|
elsif updating_email && User.find_by_email(self.update_email) != nil
|
||||||
|
errors.add(:update_email, ValidationMessages::EMAIL_ALREADY_TAKEN)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def online
|
def online
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,12 @@ describe User do
|
||||||
@user.errors[:password_validation][0].should == ValidationMessages::NOT_YOUR_PASSWORD
|
@user.errors[:password_validation][0].should == ValidationMessages::NOT_YOUR_PASSWORD
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "matches current email" do
|
||||||
|
@user.begin_update_email(@user.email, "foobar", "http://www.jamkazam.com/confirm_email_update?token=")
|
||||||
|
|
||||||
|
@user.errors[:update_email][0].should == ValidationMessages::EMAIL_MATCHES_CURRENT
|
||||||
|
end
|
||||||
|
|
||||||
it "existing email of another user" do
|
it "existing email of another user" do
|
||||||
another_user = FactoryGirl.create(:user)
|
another_user = FactoryGirl.create(:user)
|
||||||
@user.begin_update_email(another_user.email, "foobar", "http://www.jamkazam.com/confirm_email_update?token=")
|
@user.begin_update_email(another_user.email, "foobar", "http://www.jamkazam.com/confirm_email_update?token=")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue