Class: User

Inherits:
Volt::Model show all
Defined in:
app/volt/models/user.rb

Instance Attribute Summary

Attributes inherited from Volt::Model

#attributes, #options, #parent, #path, #persistor

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Volt::Model

#!, #<<, #==, #_id, #_id=, #assign_attribute, #buffer, #expand!, #initialize, #inspect, #method_missing, #new_array_model, #new_model, nosave, #promise_for_errors, #read_attribute, #read_new_model, #return_undefined_method, #save!

Methods included from Volt::ModelState

#change_state_to, #loaded?, #state

Methods included from Volt::Validations

#clear_server_errors, #errors, included, #mark_all_fields!, #mark_field!, #marked_errors, #marked_fields, #server_errors

Methods included from Volt::ModelHashBehaviour

#clear, #delete, #each_with_object, #empty?, #false?, #keys, #nil?, #size, #to_h, #true?

Methods included from Volt::ModelHelpers

#class_at_path, #deep_unwrap, #event_added, #event_removed

Methods included from Volt::ModelWrapper

#wrap_value, #wrap_values

Constructor Details

This class inherits a constructor from Volt::Model

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Volt::Model

Class Method Details

.login(username, password) ⇒ Object

Login the user, return a promise for success



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/volt/models/user.rb', line 22

def self.(username, password)
  puts "Login now"
  UserTasks.(username, password).then do |result|
    puts "Got: #{result.inspect}"

    # Assign the user_id cookie for the user
    $page.cookies._user_id = result

    # Pass nil back
    nil
  end
end

.logoutObject



35
36
37
# File 'app/volt/models/user.rb', line 35

def self.logout
  $page.cookies.delete(:user_id)
end

Instance Method Details

#password=(val) ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/volt/models/user.rb', line 12

def password=(val)
  if Volt.server?
    # on the server, we bcrypt the password and store the result
    self._hashed_password = BCrypt::Password.create(val)
  else
    self._password = val
  end
end