Class: Marty::User
- Inherits:
-
Base
show all
- Defined in:
- app/models/marty/user.rb
Constant Summary
collapse
- MARTY_IMPORT_UNIQUENESS =
[:login]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
get_final_attrs, get_struct_attrs, make_hash, make_openstruct, mcfly_pt
joins, old_joins
Class Method Details
.authenticate_with?(login, password) ⇒ Boolean
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/marty/user.rb', line 76
def self.authenticate_with?(login, password)
cf = Rails.configuration.marty
auth_source = cf.auth_source.to_s
if auth_source == 'local'
ok = password == cf.local_password
elsif auth_source == 'ldap'
ok = ldap_login(login, password)
else
raise "bad auth_source: #{auth_source.inspect}"
end
find_by_login(login) if ok
end
|
.current ⇒ Object
96
97
98
|
# File 'app/models/marty/user.rb', line 96
def self.current
Mcfly.whodunnit
end
|
.current=(user) ⇒ Object
92
93
94
|
# File 'app/models/marty/user.rb', line 92
def self.current=(user)
Mcfly.whodunnit = user
end
|
.has_role(role) ⇒ Object
100
101
102
103
|
# File 'app/models/marty/user.rb', line 100
def self.has_role(role)
mr = Mcfly.whodunnit.user_roles rescue []
mr.any? { |ur| ur.role == role }
end
|
.ldap_login(login, password) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/models/marty/user.rb', line 59
def self.ldap_login(login, password)
cf = Rails.configuration.marty.ldap
ldap = Net::LDAP.new(host: cf.host,
port: cf.port,
base: cf.base_dn,
encryption: cf.encryption,
auth: {
method: :simple,
username: cf.domain + '\\' + login,
password: password,
})
ldap.bind
end
|
.try_to_autologin(key) ⇒ Object
Returns the user who matches the given autologin key
or nil
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/models/marty/user.rb', line 30
def self.try_to_autologin(key)
tokens = Marty::Token.find_all_by_action_and_value('autologin', key.to_s)
if tokens.size == 1
token = tokens.first
autologin = Rails.configuration.marty.autologin || 0
if (token.created_on > autologin.to_i.day.ago) &&
token.user && token.user.active?
token.user
end
end
end
|
.try_to_login(login, password) ⇒ Object
Returns the user that matches provided login and password, or nil
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/models/marty/user.rb', line 45
def self.try_to_login(login, password)
login = login.to_s
password = password.to_s
return nil if password.empty?
user = find_by_login(login)
return nil if !user || !user.active?
authenticate_with?(login, password) || nil
end
|
Instance Method Details
#name ⇒ Object
17
18
19
|
# File 'app/models/marty/user.rb', line 17
def name
"#{firstname} #{lastname}"
end
|
#roles ⇒ Object
25
26
27
|
# File 'app/models/marty/user.rb', line 25
def roles
user_roles.map(&:role)
end
|
#to_s ⇒ Object
21
22
23
|
# File 'app/models/marty/user.rb', line 21
def to_s
name
end
|