Class: UserTasks

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

Instance Method Summary collapse

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/volt/tasks/user_tasks.rb', line 5

def (, password)
  query = {User. => }

  return store._users.find(query).then do |users|
    user = users.first

    if user
      match_pass = BCrypt::Password.new(user._hashed_password)
      if match_pass == password
        raise "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("#{Volt.config.app_secret}::#{user._id}")

        # Return user_id:hash on user id
        next "#{user._id}:#{signature}"
      else
        raise "Password did not match"
      end
    else
      raise "User could not be found"
    end
  end
end