Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class AuthenticationService < ApplicationService
  2. validates :user_present?,
  3. I18n.t("devise.failure.invalid"),
  4. Errors::AuthenticationError
  5.  
  6. validates :check_locked,
  7. I18n.t("devise.failure.locked"),
  8. Errors::AuthenticationError
  9.  
  10. validates :valid_credentials?,
  11. I18n.t("devise.failure.invalid"),
  12. Errors::AuthenticationError
  13.  
  14. def initialize(user, password)
  15. @user = user
  16. @password = password
  17. end
  18.  
  19. def perform
  20. super do
  21. JWTWrapper.encode user_id: @user.id
  22. end
  23. end
  24.  
  25. private
  26.  
  27. def user_present?
  28. @user.present?
  29. end
  30.  
  31. def valid_credentials?
  32. user_present? && valid_for_authentication?
  33. end
  34.  
  35. def valid_for_authentication?
  36. @user.valid_for_authentication? {
  37. @user.valid_password?(@password)
  38. }
  39. end
  40.  
  41. def check_locked
  42. !@user.access_locked?
  43. end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement