authem 1.0.0.rc3 → 1.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/authem/base_user.rb +31 -21
- data/lib/authem/sorcery_user.rb +8 -8
- data/lib/authem/version.rb +1 -1
- metadata +2 -2
data/lib/authem/base_user.rb
CHANGED
@@ -9,37 +9,47 @@ module Authem::BaseUser
|
|
9
9
|
validates_uniqueness_of :email
|
10
10
|
validates_format_of :email, with: /^\S+@\S+$/
|
11
11
|
validates_presence_of :password, on: :create
|
12
|
-
validates_confirmation_of :password
|
12
|
+
validates_confirmation_of :password
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
module ClassMethods
|
16
|
+
def find_by_email(email)
|
15
17
|
where("LOWER(email) = ?", email.downcase).first
|
16
18
|
end
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def remember_token
|
22
|
+
self[:remember_token] || generate_token(:remember)
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
def session_token
|
26
|
+
self[:session_token] || generate_token(:session)
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
def reset_password(password, confirmation)
|
30
|
+
return false unless password.present?
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
reset_password_token = self.reset_password_token
|
33
|
+
|
34
|
+
self.password = password
|
35
|
+
self.password_confirmation = confirmation
|
36
|
+
self.reset_password_token = nil
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
if save
|
39
|
+
true
|
40
|
+
else
|
41
|
+
self.reset_password_token = reset_password_token
|
42
|
+
false
|
37
43
|
end
|
44
|
+
end
|
38
45
|
|
39
|
-
|
46
|
+
def reset_password_token!
|
47
|
+
generate_token(:reset_password)
|
48
|
+
end
|
40
49
|
|
41
|
-
|
42
|
-
|
43
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
def generate_token(type)
|
53
|
+
Authem::Token.generate.tap { |token| update_column("#{type}_token", token) }
|
44
54
|
end
|
45
55
|
end
|
data/lib/authem/sorcery_user.rb
CHANGED
@@ -6,16 +6,16 @@ module Authem::SorceryUser
|
|
6
6
|
attr_accessor :password, :password_confirmation
|
7
7
|
|
8
8
|
before_save :encrypt_password
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def authenticate(password)
|
12
|
+
self if crypted_password.present? && ::BCrypt::Password.new(crypted_password) == [password, salt].join
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
15
|
+
def encrypt_password
|
16
|
+
if password.present?
|
17
|
+
self.salt = ::BCrypt::Engine.generate_salt
|
18
|
+
self.crypted_password = ::BCrypt::Password.create([password, salt].join)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/authem/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|