Class: Core::Services::Sessions
- Includes:
- Singleton
- Defined in:
- lib/core/services/sessions.rb
Overview
Service concerning sessions (log in and log out)
Instance Method Summary collapse
-
#create_from_credentials(username: nil, password: nil, **ignored) ⇒ Core::Models::Authentication::Session
Creates a new session from the given user credentials.
-
#get_by_id(session_id: nil, **ignored) ⇒ Core::Decorators::Session
Gets the session by its unique identifier.
Methods inherited from Base
#bad_request_err, #forbidden_err, #require_parameters, #unknown_err
Instance Method Details
#create_from_credentials(username: nil, password: nil, **ignored) ⇒ Core::Models::Authentication::Session
Creates a new session from the given user credentials. IT will
-
check that the user exists in the database
-
check that the password matches the user encrypted password
If both steps are correctly passed, it will create and return a session object so that the user can have a login token.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/core/services/sessions.rb', line 22 def create_from_credentials(username: nil, password: nil, **ignored) account = Core.svc.accounts.get_by_credentials( username: username, password: password ) session = Core::Models::Authentication::Session.create( account: account, token: SecureRandom.uuid ) Decorators::Session.new(session) end |
#get_by_id(session_id: nil, **ignored) ⇒ Core::Decorators::Session
Gets the session by its unique identifier.
41 42 43 44 45 46 47 |
# File 'lib/core/services/sessions.rb', line 41 def get_by_id(session_id: nil, **ignored) require_parameters session_id: session_id session = Core::Models::Authentication::Session.find_by(token: session_id) raise unknown_err(field: 'session_id') if session.nil? Core::Decorators::Session.new(session) end |