Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement