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.
-
#remote_ip ⇒ Object
readonly
Returns the value of attribute remote_ip.
-
#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 19 |
# File 'app/services/usman/authentication_service.rb', line 6 def initialize(params) @login_handle = params[:login_handle] @password = params[:password] @remote_ip = params[:remote_ip] @error = nil check_if_user_exists if @user authenticate check_if_user_is_approved end @user.start_session(@remote_ip) 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 |
#remote_ip ⇒ Object (readonly)
Returns the value of attribute remote_ip.
4 5 6 |
# File 'app/services/usman/authentication_service.rb', line 4 def remote_ip @remote_ip 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
38 39 40 |
# File 'app/services/usman/authentication_service.rb', line 38 def authenticate set_error(invalid_login_error) unless @user.authenticate(@password) end |
#check_if_user_exists ⇒ Object
29 30 31 32 |
# File 'app/services/usman/authentication_service.rb', line 29 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
34 35 36 |
# File 'app/services/usman/authentication_service.rb', line 34 def check_if_user_is_approved set_error(user_status_error) unless @user.approved? end |
#invalid_login_error ⇒ Object
21 22 23 |
# File 'app/services/usman/authentication_service.rb', line 21 def invalid_login_error "authentication.invalid_login" end |
#set_error(id) ⇒ Object
42 43 44 |
# File 'app/services/usman/authentication_service.rb', line 42 def set_error(id) @error ||= id end |
#user_status_error ⇒ Object
25 26 27 |
# File 'app/services/usman/authentication_service.rb', line 25 def user_status_error "authentication.user_is_#{@user.status.downcase}" end |