Class: JunglePath::Controller::User
- Inherits:
-
Base
- Object
- Base
- JunglePath::Controller::User
show all
- Defined in:
- lib/jungle_path/controller/authentication.rb
Instance Attribute Summary
Attributes inherited from Base
#table_class
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#create_table, #delete, #delete_rows, #drop_table, #reset_table, #select
Constructor Details
#initialize(current_user, current_key, params, db) ⇒ User
Returns a new instance of User.
12
13
14
|
# File 'lib/jungle_path/controller/authentication.rb', line 12
def initialize(current_user, current_key, params, db)
super(current_user, current_key, params, db, JunglePath::Schema::User)
end
|
Class Method Details
.validate_hash_with_password(hash, password) ⇒ Object
68
69
70
|
# File 'lib/jungle_path/controller/authentication.rb', line 68
def self.validate_hash_with_password(hash, password)
JunglePath::Authentication::PasswordHash.validatePassword(password, hash)
end
|
Instance Method Details
#insert(include_secure_columns: false) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/jungle_path/controller/authentication.rb', line 16
def insert(include_secure_columns: false)
params = self.class.add_audit_parameter_values_for_insert(@params, @current_user, @current_key, @table_class)
model = @table_class.new params
password = params[:password]
message = self.class.validate_password_message(password)
if message
self.class.validate_insert(model, message)
raise JunglePath::Exceptions::InvalidPassword, "#{message}", caller
end
model.hash = JunglePath::Authentication::PasswordHash.createHash(password)
self.class.validate_insert(model)
begin
result = @db.insert._model(model)
result = self.class.handle_include_secure_columns_flag(result, include_secure_columns, @table_class)
rescue Sequel::UniqueConstraintViolation => e
user_query = JunglePath::Schema::User.new({user_name: params[:user_name]})
user = @db.select._model_by_any(user_query)
params[:id] = user.id if user
if user
update
user = @db.select._model(user)
else
raise
end
end
end
|
#update ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/jungle_path/controller/authentication.rb', line 49
def update
params = self.class.add_audit_parameter_values_for_update(@params, @current_user, @current_key, @table_class)
model = @table_class.new params
password = params[:password]
if password
message = self.class.validate_password_message(password)
if message
self.class.validate_update(model, message)
raise JunglePath::Exceptions::InvalidPassword, "#{message}", caller
end
model.hash = JunglePath::Authentication::PasswordHash.createHash(password)
end
self.class.validate_update(model)
result = @db.update._model(model)
end
|