shuber-authentication 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/lib/huberry/authentication/model_methods.rb +51 -51
- metadata +2 -2
data/CHANGELOG
CHANGED
|
@@ -25,62 +25,62 @@ module Huberry
|
|
|
25
25
|
|
|
26
26
|
alias_method_chain :reload, :authentication
|
|
27
27
|
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
module ClassMethods
|
|
31
|
-
def authenticate(login, password)
|
|
32
|
-
user = send("find_by_#{self.authentication_options[:login_field]}", login)
|
|
33
|
-
user && user.authenticated?(password) ? user : false
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def digest(str)
|
|
37
|
-
Digest::SHA256.hexdigest(str.to_s)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
module InstanceMethods
|
|
42
|
-
def authenticated?(password)
|
|
43
|
-
send(self.class.authentication_options[:hashed_password_field]) == self.class.digest(password.to_s + send(self.class.authentication_options[:salt_field]).to_s)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def password_changed?
|
|
47
|
-
!!@password_changed
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def reload_with_authentication(*args)
|
|
51
|
-
reload_without_authentication(*args)
|
|
52
|
-
@password_changed = false
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def reset_password(new_password = nil)
|
|
56
|
-
new_password = generate_salt[0..7] if new_password.blank?
|
|
57
|
-
send("#{self.class.authentication_options[:salt_field]}=", nil)
|
|
58
|
-
send("#{self.class.authentication_options[:password_field]}=", new_password)
|
|
59
|
-
send("#{self.class.authentication_options[:password_field]}_confirmation=", new_password)
|
|
60
|
-
@password_changed = true
|
|
61
|
-
end
|
|
62
28
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
29
|
+
module ClassMethods
|
|
30
|
+
def authenticate(login, password)
|
|
31
|
+
user = send("find_by_#{self.authentication_options[:login_field]}", login)
|
|
32
|
+
user && user.authenticated?(password) ? user : false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def digest(str)
|
|
36
|
+
Digest::SHA256.hexdigest(str.to_s)
|
|
37
|
+
end
|
|
66
38
|
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
self.class.digest("--#{Time.now}--#{rand}--")
|
|
39
|
+
|
|
40
|
+
module InstanceMethods
|
|
41
|
+
def authenticated?(password)
|
|
42
|
+
send(self.class.authentication_options[:hashed_password_field]) == self.class.digest(password.to_s + send(self.class.authentication_options[:salt_field]).to_s)
|
|
72
43
|
end
|
|
73
|
-
|
|
74
|
-
def
|
|
75
|
-
|
|
76
|
-
send("#{self.class.authentication_options[:salt_field]}=", generate_salt) if send("#{self.class.authentication_options[:salt_field]}").blank?
|
|
77
|
-
send("#{self.class.authentication_options[:hashed_password_field]}=", self.class.digest(send(self.class.authentication_options[:password_field]).to_s + send(self.class.authentication_options[:salt_field]).to_s))
|
|
78
|
-
end
|
|
44
|
+
|
|
45
|
+
def password_changed?
|
|
46
|
+
!!@password_changed
|
|
79
47
|
end
|
|
80
|
-
|
|
81
|
-
def
|
|
82
|
-
|
|
48
|
+
|
|
49
|
+
def reload_with_authentication(*args)
|
|
50
|
+
reload_without_authentication(*args)
|
|
51
|
+
@password_changed = false
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def reset_password(new_password = nil)
|
|
55
|
+
new_password = generate_salt[0..7] if new_password.blank?
|
|
56
|
+
send("#{self.class.authentication_options[:salt_field]}=", nil)
|
|
57
|
+
send("#{self.class.authentication_options[:password_field]}=", new_password)
|
|
58
|
+
send("#{self.class.authentication_options[:password_field]}_confirmation=", new_password)
|
|
59
|
+
@password_changed = true
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def reset_password!(new_password = nil)
|
|
63
|
+
reset_password(new_password)
|
|
64
|
+
save
|
|
83
65
|
end
|
|
66
|
+
|
|
67
|
+
protected
|
|
68
|
+
|
|
69
|
+
def generate_salt
|
|
70
|
+
self.class.digest("--#{Time.now}--#{rand}--")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def hash_password
|
|
74
|
+
if password_changed? || password_required?
|
|
75
|
+
send("#{self.class.authentication_options[:salt_field]}=", generate_salt) if send("#{self.class.authentication_options[:salt_field]}").blank?
|
|
76
|
+
send("#{self.class.authentication_options[:hashed_password_field]}=", self.class.digest(send(self.class.authentication_options[:password_field]).to_s + send(self.class.authentication_options[:salt_field]).to_s))
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def password_required?
|
|
81
|
+
send(self.class.authentication_options[:hashed_password_field]).blank? || !send(self.class.authentication_options[:password_field]).blank?
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shuber-authentication
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sean Huber
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-01-
|
|
12
|
+
date: 2009-01-24 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|