Skip to content

Instantly share code, notes, and snippets.

@y00rb
Created July 7, 2014 09:04
Show Gist options
  • Save y00rb/5bf86d1dc992ed3bdd00 to your computer and use it in GitHub Desktop.
Save y00rb/5bf86d1dc992ed3bdd00 to your computer and use it in GitHub Desktop.
SignIn service object
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