Class: UserTasks
- Inherits:
-
Volt::Task
- Object
- Volt::Task
- UserTasks
- Defined in:
- app/volt/tasks/user_tasks.rb
Instance Method Summary collapse
-
#login(login_info) ⇒ Object
Login a user, takes a login and password.
- #logout ⇒ Object
Methods inherited from Volt::Task
#cookies, #fetch_cookies, inherited, #initialize, known_handlers, method_missing, timeout
Methods included from Volt::LoginAsHelper
Methods included from Volt::CollectionHelpers
#channel, #cookies, #flash, #local_store, #page, #params, #store, #tasks, #url, #url_for, #url_with
Constructor Details
This class inherits a constructor from Volt::Task
Instance Method Details
#login(login_info) ⇒ 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
login_info is a key with login and password (login may be e-mail)
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 6 def login(login_info) login = login_info['login'] password = login_info['password'] query = { User.login_field => login } # During login we need access to the user's info even though we aren't the user Volt. do store._users.where(query).first.then do |user| fail VoltUserError, 'User could not be found' unless user match_pass = BCrypt::Password.new(user._hashed_password) fail 'Password did not match' unless match_pass == password next Volt.user_login_signature(user) end end end |
#logout ⇒ Object
25 26 27 28 |
# File 'app/volt/tasks/user_tasks.rb', line 25 def logout # Remove user_id from user's channel @channel.update_user_id(nil) if @channel end |