password_resetter 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -57,7 +57,7 @@ The entire form is wrapped with
57
57
 
58
58
  Email input field is tagged with
59
59
  ```ruby
60
- :class => "password-reset-input email"
60
+ :id => "password_reset_email"
61
61
  ```
62
62
 
63
63
  Reset Password button:
@@ -76,11 +76,27 @@ The entire form is wrapped with
76
76
 
77
77
  Password and Password Confirmation fields tagged respectively with:
78
78
  ```ruby
79
- :class => "password-reset-input password"
80
- :class => "password-reset-input password_confirmation"
79
+ :id => "password_reset_password"
80
+ :id => "password_reset_password_confirmation"
81
81
  ```
82
82
 
83
83
  Update Password button:
84
84
  ```ruby
85
- :class => "password-reset-buton update"
85
+ :class => "password-reset-button update"
86
+ ```
87
+
88
+ For example, in `application.css.scss`
89
+
90
+ ```
91
+ #password_reset_email, #password_reset_password, #password_reset_password_confirmation {
92
+ margin-bottom: 15px;
93
+ margin-top: 5px;
94
+ width: 285px;
95
+ }
96
+
97
+ .password-reset-button {
98
+ background: image-url("my_button.png");
99
+ height: 25px;
100
+ width: 100px;
101
+ }
86
102
  ```
@@ -1,19 +1,25 @@
1
1
  class PasswordReset < ActiveRecord::Base
2
-
3
2
  belongs_to :user
4
-
3
+
5
4
  attr_accessible :user, :email, :password, :password_confirmation, :reset_token, :reset_sent_at
6
-
5
+
7
6
  validates_presence_of :email
8
-
7
+
9
8
  def match_email?
10
- guest = User.where(['email = ?', email]).first
9
+ guest = find_guest(email)
11
10
  if guest.present?
12
11
  self.update_attributes(:user => guest)
13
12
  else
14
13
  false
15
14
  end
16
15
  end
16
+
17
+ def find_guest(email_string)
18
+ User.all.each do |user|
19
+ return user if user.email == email_string
20
+ end
21
+ false
22
+ end
17
23
 
18
24
  def send_password_reset
19
25
  generate_token
@@ -21,7 +27,7 @@ class PasswordReset < ActiveRecord::Base
21
27
  save
22
28
  PasswordResetMailer.password_reset(user, self).deliver
23
29
  end
24
-
30
+
25
31
  def update_user_password(password, confirmation)
26
32
  if passwords_valid?(password, confirmation)
27
33
  user.password = password
@@ -31,7 +37,7 @@ class PasswordReset < ActiveRecord::Base
31
37
  false
32
38
  end
33
39
  end
34
-
40
+
35
41
  def expired?
36
42
  reset_sent_at < 2.hours.ago
37
43
  end
@@ -41,7 +47,7 @@ class PasswordReset < ActiveRecord::Base
41
47
  pr.delete if (pr.user_id == user.id) && (pr != self)
42
48
  end
43
49
  end
44
-
50
+
45
51
  private
46
52
  def generate_token
47
53
  begin
@@ -49,7 +55,7 @@ class PasswordReset < ActiveRecord::Base
49
55
  end while PasswordReset.exists?(:reset_token => self.reset_token)
50
56
  self.save
51
57
  end
52
-
58
+
53
59
  def passwords_valid?(password, confirmation)
54
60
  password.present? && confirmation.present? && password == confirmation
55
61
  end
@@ -1,8 +1,8 @@
1
1
  <div class="password-reset-complete-field">
2
2
  <%= simple_form_for @password_reset do |f| %>
3
3
  <div class="field">
4
- <%= f.input :password, :class => "password-reset-input password" %>
5
- <%= f.input :password_confirmation, :class => "password-reset-input password-confirmation" %>
4
+ <%= f.input :password, :label => "New Password" %>
5
+ <%= f.input :password_confirmation, :label => "Password Confirmation" %>
6
6
  </div>
7
7
  <div class="actions"><%= f.submit "Update Password", :class => "password-reset-button update" %></div>
8
8
  <% end %>
@@ -1,10 +1,10 @@
1
1
  <div class="password-reset-request-field">
2
- <div class="password-reset-text reset"> Please enter your email address to reset your password.</div>
2
+ <div class="password-reset-text reset">Forgot Your Password?</div>
3
3
 
4
4
  <%= simple_form_for @password_reset do |f| %>
5
5
  <%= f.full_error :user %>
6
6
  <div class="field">
7
- <%= f.input :email, :label => "Enter your Email Address", :class => "password-reset-input email" %>
7
+ <%= f.input :email, :label => "Enter Your Email Address" %>
8
8
  </div>
9
9
  <div class="actions"><%= submit_tag "Reset Password", :class => "password-reset-button reset" %></div>
10
10
  <% end %>
@@ -0,0 +1,62 @@
1
+ module PasswordResetter
2
+ module Resettable
3
+ belongs_to :user
4
+
5
+ attr_accessible :user, :email, :password, :password_confirmation, :reset_token, :reset_sent_at
6
+
7
+ validates_presence_of :email
8
+
9
+ def match_email?
10
+ guest = find_guest(email)
11
+ if guest.present?
12
+ self.update_attributes(:user => guest)
13
+ else
14
+ false
15
+ end
16
+ end
17
+
18
+ def find_guest(email_string)
19
+ User.where(['email = ?', email_string]).first
20
+ end
21
+
22
+ def send_password_reset
23
+ generate_token
24
+ self.update_attributes(:reset_sent_at => Time.zone.now)
25
+ save
26
+ PasswordResetMailer.password_reset(user, self).deliver
27
+ end
28
+
29
+ def update_user_password(password, confirmation)
30
+ if passwords_valid?(password, confirmation)
31
+ user.password = password
32
+ user.password_confirmation = confirmation
33
+ user.save
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ def expired?
40
+ reset_sent_at < 2.hours.ago
41
+ end
42
+
43
+ def delete_existing
44
+ PasswordReset.all.each do |pr|
45
+ pr.delete if (pr.user_id == user.id) && (pr != self)
46
+ end
47
+ end
48
+
49
+ private
50
+ def generate_token
51
+ begin
52
+ self.reset_token = SecureRandom.urlsafe_base64
53
+ end while PasswordReset.exists?(:reset_token => self.reset_token)
54
+ self.save
55
+ end
56
+
57
+ def passwords_valid?(password, confirmation)
58
+ password.present? && confirmation.present? && password == confirmation
59
+ end
60
+
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module PasswordResetter
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: password_resetter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
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-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -174,6 +174,7 @@ files:
174
174
  - config/routes.rb
175
175
  - db/migrate/20120829163145_create_password_resets.rb
176
176
  - lib/password_resetter/engine.rb
177
+ - lib/password_resetter/resettable.rb
177
178
  - lib/password_resetter/version.rb
178
179
  - lib/password_resetter.rb
179
180
  - lib/tasks/password_resetter_tasks.rake