Created
July 7, 2014 09:04
-
-
Save y00rb/5bf86d1dc992ed3bdd00 to your computer and use it in GitHub Desktop.
SignIn service object
This file contains hidden or 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
class SignIn < PlainModel | |
attr_accessor :email | |
attr_accessor :password | |
validate :validate_user_exists | |
validate :validate_password_correct | |
def user | |
User.find_by_email(email) if email.present? | |
end | |
private | |
def validate_user_exists | |
if user.blank? | |
errors.add(:user_id, 'User not found') | |
end | |
end | |
def validate_password_correct | |
if user && !user.has_password?(password) | |
errors.add(:password, 'Incorrect password') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment