Class: UserTasks
- Inherits:
-
Volt::TaskHandler
- Object
- Volt::TaskHandler
- UserTasks
- Defined in:
- app/volt/tasks/user_tasks.rb
Instance Method Summary collapse
-
#login(login, password) ⇒ Object
Login a user, takes a login and password.
Methods inherited from Volt::TaskHandler
inherited, #initialize, known_handlers, method_missing, #store
Constructor Details
This class inherits a constructor from Volt::TaskHandler
Instance Method Details
#login(login, password) ⇒ Object
Login a user, takes a login and password. Login can be either a username or an e-mail based on Volt.config.public.auth.use_username
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/volt/tasks/user_tasks.rb', line 4 def login(login, password) query = { User.login_field => login } store._users.find(query).then do |users| user = users.first fail 'User could not be found' unless user match_pass = BCrypt::Password.new(user._hashed_password) fail 'Password did not match' unless match_pass == password fail 'app_secret is not configured' unless Volt.config.app_secret # TODO: returning here should be possible, but causes some issues # Salt the user id with the app_secret so the end user can't # tamper with the cookie signature = BCrypt::Password.create(salty_password(user._id)) # Return user_id:hash on user id next "#{user._id}:#{signature}" end end |