Created
October 13, 2017 14:52
-
-
Save renatoalencar/58836191da06a5855e0a1e3a0ed4504f 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
| class AuthenticationService < ApplicationService | |
| validates :user_present?, | |
| I18n.t("devise.failure.invalid"), | |
| Errors::AuthenticationError | |
| validates :check_locked, | |
| I18n.t("devise.failure.locked"), | |
| Errors::AuthenticationError | |
| validates :valid_credentials?, | |
| I18n.t("devise.failure.invalid"), | |
| Errors::AuthenticationError | |
| def initialize(user, password) | |
| @user = user | |
| @password = password | |
| end | |
| def perform | |
| super do | |
| JWTWrapper.encode user_id: @user.id | |
| end | |
| end | |
| private | |
| def user_present? | |
| @user.present? | |
| end | |
| def valid_credentials? | |
| user_present? && valid_for_authentication? | |
| end | |
| def valid_for_authentication? | |
| @user.valid_for_authentication? { | |
| @user.valid_password?(@password) | |
| } | |
| end | |
| def check_locked | |
| !@user.access_locked? | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment