Created
January 22, 2015 00:30
-
-
Save hayduke19us/bda3ff1ba1adf0866750 to your computer and use it in GitHub Desktop.
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
| module ApiTools | |
| extend ActiveSupport::Concern | |
| class Authenticate < Base | |
| attr_reader :password | |
| def initialize args | |
| super(args) | |
| @password = args.fetch(:password, false) | |
| end | |
| def has_password? | |
| if self.password | |
| return true | |
| else | |
| self.error_response = ErrorSquad.no_password | |
| return false | |
| end | |
| end | |
| def valid_password? | |
| if self.user.valid_password?(self.password) | |
| return true | |
| else | |
| self.error_response = ErrorSquad.wrong_password | |
| return false | |
| end | |
| end | |
| def authentic_user | |
| self.user ? self.valid_password? : false | |
| end | |
| def success? | |
| if self.has_password? and self.authentic_user | |
| self.success_response = SuccessSquad.sign_in | |
| return true | |
| else | |
| return false | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment