Created
February 2, 2014 18:40
-
-
Save kreshikhin/8772829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validate :old_password_should_be_valid | |
validate :new_password_should_be_valid | |
validate :password_confirmation_should_be_valid | |
before_save :calculate_digest | |
def old_password_should_be_valid | |
return if self.password.nil? or not self.persisted? | |
if User.digest(self.old_password) != self.password_digest | |
errors.add(:old_password, "Текущий пароль неверен") | |
end | |
end | |
def new_password_should_be_valid | |
return if self.password.nil? | |
if self.password.length < 6 | |
errors.add(:password, "Пароль не должен быть короче 6 символов") | |
end | |
if self.password.length > 64 | |
errors.add(:password, "Пароль не должен быть длинее 64 символов") | |
end | |
end | |
def password_confirmation_should_be_valid | |
return if self.password.nil? or not self.persisted? | |
if self.password != self.password_confirmation | |
errors.add(:password, "Подтерждение не совпадает с новым паролем") | |
end | |
end | |
def calculate_digest | |
return if self.password.nil? | |
self.password_digest = User.digest(self.password) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment