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.
@@ -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, message: 'should match confirmation'
12
+ validates_confirmation_of :password
13
+ end
13
14
 
14
- def self.find_by_email(email)
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
- def remember_token
19
- self[:remember_token] || generate_token(:remember)
20
- end
21
+ def remember_token
22
+ self[:remember_token] || generate_token(:remember)
23
+ end
21
24
 
22
- def session_token
23
- self[:session_token] || generate_token(:session)
24
- end
25
+ def session_token
26
+ self[:session_token] || generate_token(:session)
27
+ end
25
28
 
26
- def reset_password(password, confirmation)
27
- return false unless password.present?
29
+ def reset_password(password, confirmation)
30
+ return false unless password.present?
28
31
 
29
- self.password = password
30
- self.password_confirmation = confirmation
31
- self.reset_password_token = nil
32
- save
33
- end
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
- def reset_password_token!
36
- generate_token(:reset_password)
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
- private
46
+ def reset_password_token!
47
+ generate_token(:reset_password)
48
+ end
40
49
 
41
- def generate_token(type)
42
- Authem::Token.generate.tap { |token| update_column("#{type}_token", token) }
43
- end
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
@@ -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
- def authenticate(password)
11
- self if crypted_password.present? && ::BCrypt::Password.new(crypted_password) == [password, salt].join
12
- end
11
+ def authenticate(password)
12
+ self if crypted_password.present? && ::BCrypt::Password.new(crypted_password) == [password, salt].join
13
+ end
13
14
 
14
- def encrypt_password
15
- if password.present?
16
- self.salt = ::BCrypt::Engine.generate_salt
17
- self.crypted_password = ::BCrypt::Password.create([password, salt].join)
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
@@ -1,3 +1,3 @@
1
1
  module Authem
2
- VERSION = '1.0.0.rc3'
2
+ VERSION = '1.0.0.rc4'
3
3
  end
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.rc3
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: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport