Class: Usman::AuthenticationService
- Inherits:
-
Object
- Object
- Usman::AuthenticationService
- Defined in:
- app/services/usman/authentication_service.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#login_handle ⇒ Object
readonly
Returns the value of attribute login_handle.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #check_if_user_exists ⇒ Object
- #check_if_user_is_approved ⇒ Object
-
#initialize(params) ⇒ AuthenticationService
constructor
A new instance of AuthenticationService.
- #invalid_login_error ⇒ Object
- #set_error(id) ⇒ Object
- #user_status_error ⇒ Object
Constructor Details
#initialize(params) ⇒ AuthenticationService
Returns a new instance of AuthenticationService.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/services/usman/authentication_service.rb', line 6 def initialize(params) @login_handle = params[:login_handle] @password = params[:password] @error = nil check_if_user_exists if @user authenticate check_if_user_is_approved end @user.start_session unless @error end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
4 5 6 |
# File 'app/services/usman/authentication_service.rb', line 4 def error @error end |
#login_handle ⇒ Object (readonly)
Returns the value of attribute login_handle.
4 5 6 |
# File 'app/services/usman/authentication_service.rb', line 4 def login_handle @login_handle end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'app/services/usman/authentication_service.rb', line 4 def password @password end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'app/services/usman/authentication_service.rb', line 4 def user @user end |
Instance Method Details
#authenticate ⇒ Object
37 38 39 |
# File 'app/services/usman/authentication_service.rb', line 37 def authenticate set_error(invalid_login_error) unless @user.authenticate(@password) end |
#check_if_user_exists ⇒ Object
28 29 30 31 |
# File 'app/services/usman/authentication_service.rb', line 28 def check_if_user_exists @user = User.where("LOWER(email) = LOWER('#{@login_handle}') OR LOWER(username) = LOWER('#{@login_handle}')").first set_error(invalid_login_error) unless @user end |
#check_if_user_is_approved ⇒ Object
33 34 35 |
# File 'app/services/usman/authentication_service.rb', line 33 def check_if_user_is_approved set_error(user_status_error) unless @user.approved? end |
#invalid_login_error ⇒ Object
20 21 22 |
# File 'app/services/usman/authentication_service.rb', line 20 def invalid_login_error "authentication.invalid_login" end |
#set_error(id) ⇒ Object
41 42 43 |
# File 'app/services/usman/authentication_service.rb', line 41 def set_error(id) @error ||= id end |
#user_status_error ⇒ Object
24 25 26 |
# File 'app/services/usman/authentication_service.rb', line 24 def user_status_error "authentication.user_is_#{@user.status.downcase}" end |