Class: UserTasks

Inherits:
Volt::Task show all
Defined in:
app/volt/tasks/user_tasks.rb

Instance Method Summary collapse

Methods inherited from Volt::Task

#cookies, #fetch_cookies, inherited, #initialize, known_handlers, method_missing, timeout

Methods included from Volt::LoginAsHelper

#login_as

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']
  password = ['password']

  query = { User. =>  }

  # During login we need access to the user's info even though we aren't the user
  Volt.skip_permissions 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)
    end
  end
end

#logoutObject



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