Class: Core::Services::Sessions
- Defined in:
- lib/core/services/sessions.rb
Overview
Service concerning sessions (log in and log out)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#create(username, password) ⇒ Core::Models::Authentication::Session
Creates a new session from the given user credentials.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Core::Services::Base
Instance Method Details
#create(username, password) ⇒ 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.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/core/services/sessions.rb', line 18 def create(username, password) account = services.accounts.get_by_username(username) if BCrypt::Password.new(account.password_digest) != password raise Core::Helpers::Errors::Forbidden.new( field: 'password', error: 'wrong' ) end return Core::Models::Authentication::Session.create( account: account, token: SecureRandom.uuid ) end |