tkh_authentication 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/app/controllers/reception_controller.rb +231 -0
  4. data/app/mailers/reception_mailer.rb +19 -0
  5. data/app/models/user.rb +21 -16
  6. data/app/views/reception/_enter_your_password_form.html.erb +19 -0
  7. data/app/views/reception/_enter_your_password_form.js.erb +19 -0
  8. data/app/views/reception/change_your_password.html.erb +17 -0
  9. data/app/views/reception/create_your_password.html.erb +17 -0
  10. data/app/views/reception/email_input.html.erb +23 -0
  11. data/app/views/reception/enter_your_password.html.erb +6 -0
  12. data/app/views/reception/i_forgot_my_password.html.erb +8 -0
  13. data/app/views/reception/parse_email.html.erb +15 -0
  14. data/app/views/reception/parse_email.js.erb +4 -0
  15. data/app/views/reception/request_new_password.html.erb +6 -0
  16. data/app/views/reception_mailer/new_password_request_email.html.erb +17 -0
  17. data/app/views/reception_mailer/new_password_request_email.text.erb +9 -0
  18. data/app/views/reception_mailer/password_creation_verification_email.html.erb +17 -0
  19. data/app/views/reception_mailer/password_creation_verification_email.text.erb +9 -0
  20. data/app/views/reception_mailer/verification_email.html.erb +16 -0
  21. data/app/views/reception_mailer/verification_email.text.erb +7 -0
  22. data/app/views/shared/_login_info_for_navbar.html.erb +2 -2
  23. data/app/views/shared/_other_name_label.html.erb +1 -0
  24. data/app/views/users/_form.html.erb +0 -4
  25. data/config/routes.rb +22 -5
  26. data/lib/generators/tkh_authentication/create_or_update_migrations/create_or_update_migrations_generator.rb +1 -0
  27. data/lib/generators/tkh_authentication/create_or_update_migrations/templates/add_password_creation_token.rb +6 -0
  28. data/lib/tkh_authentication/version.rb +1 -1
  29. metadata +24 -14
  30. data/app/controllers/password_resets_controller.rb +0 -36
  31. data/app/controllers/sessions_controller.rb +0 -41
  32. data/app/mailers/user_mailer.rb +0 -20
  33. data/app/models/newbie.rb +0 -12
  34. data/app/views/password_resets/edit.html.erb +0 -14
  35. data/app/views/password_resets/new.html.erb +0 -14
  36. data/app/views/sessions/_form.html.erb +0 -32
  37. data/app/views/sessions/new.html.erb +0 -6
  38. data/app/views/user_mailer/password_reset.text.erb +0 -1
  39. data/app/views/user_mailer/password_set.text.erb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1be1e35ab59a3e0902cfefd22160a6352e167e01
4
- data.tar.gz: ad0dc779113a26ce1411a2a3fbe9c35e8a92e380
3
+ metadata.gz: b51349fbe53b75922d615973d307d7b3542e1679
4
+ data.tar.gz: b1bcacda9bcd66ff228419359f504cdba7f27a3f
5
5
  SHA512:
6
- metadata.gz: f515e1c29df16e2843f2d6efca7c398a720285f5198675093305171faf8e886ecf1ef25e7e230841cc9cc15c00bfeda3fbacbf9bc4a9f7e529ef13fd7fc73be0
7
- data.tar.gz: f4504eaf664509c0f55f9e3f28df9a59ea83f7e6cedd92af0939c96bfc62ecdb3b4b48ab1a038afe9a8963bc3fa7a1939e8a19bb9050833e49df25cf179c16d1
6
+ metadata.gz: 90594fe0bd1279e009d2d81606ef32c678b2fab5e7dcc42572b6fd7580813ae8abc56b9f927b12fc296ef9d7b2af099e6ff58eb26ac7ccddd4b139cb40587ecd
7
+ data.tar.gz: 5274fdd8aa41e303d3c5549862cda66b22cc639e4b4e278de7ac2cc8d8e0b984f1812ef516ca3ac97a01a5da7e81e51bb3d9562f6db0cfd669c0ec6323f3b03a
@@ -2,6 +2,11 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.9.7
6
+
7
+ * Created a whole new authentication pathway. Please run 'bundle update tkh_authentication' -> 'rake tkh_authentication:update' -> 'rake db:migrate'
8
+
9
+
5
10
  ## 0.9.6
6
11
 
7
12
  * Upgraded Rails and simple_form dependencies.
@@ -0,0 +1,231 @@
1
+ class ReceptionController < ApplicationController
2
+
3
+ # TODO change email address - may be a profile feature in tkh_mailing_list
4
+ # TODO change password - ""
5
+ # TODO localize the whole process
6
+
7
+ before_action :set_target_page, only: [ :email_input, :parse_email, :email_validation, :create_your_password, :enter_your_password, :disconnect ]
8
+
9
+ def email_input
10
+ end
11
+
12
+ def parse_email
13
+ @user = User.find_by(email: params[:user][:email])
14
+ if @user.blank? # first take care of the easy case with a completely new user
15
+ # create new record
16
+ @user = User.new(user_params)
17
+ if @user.save
18
+ send_validation_email
19
+ flash[:notice] = "Your record has been successfully created."
20
+ # show screen to user with notice about email validation
21
+ @status = 'email_validation_email_sent'
22
+ else # problem saving new user record for some reason
23
+ redirect_to email_input_path, alert: "We had problems creating your record. Please try again. Make sure the email address is valid."
24
+ end
25
+ else # the email address was already in the database
26
+ # Returning user pathway goes here
27
+ if @user.email_validated? && @user.has_a_password?
28
+ respond_to do |format|
29
+ format.html { redirect_to enter_your_password_path(auth_token: @user.auth_token) }
30
+ format.js {}
31
+ end
32
+ elsif @user.email_validated? && !@user.has_a_password? # doesn't have a password
33
+ # User needs to securily create a password
34
+ send_password_creation_security_email
35
+ flash[:notice] = "There is 1 last step!"
36
+ # show screen to user with notice about password confirmation email
37
+ @status = 'password_confirmation_email_sent'
38
+ elsif !@user.email_validated?
39
+ send_validation_email
40
+ flash[:notice] = "For your security, we need to verify your email address."
41
+ # show screen to user with notice about email validation
42
+ @status = 'email_validation_email_sent'
43
+ end
44
+ end
45
+ end
46
+
47
+ def email_validation
48
+ @user = User.where(email_validation_token: params[:token]).first
49
+ if @user && @user.email_validation_token_sent_at >= Time.zone.now - 1.hour # still valid token
50
+ @user.email_validated = true
51
+ @user.save
52
+ unless @user.has_a_password?
53
+ set_password_creation_token
54
+ flash[:notice] = "Your email has been validated. There is 1 last step!"
55
+ redirect_to create_your_password_path(password_creation_token: @user.password_creation_token)
56
+ else # the user has a password
57
+ redirect_to enter_your_password_path(auth_token: @user.auth_token)
58
+ end
59
+ elsif @user && @user.email_validation_token_sent_at <= Time.zone.now - 1.hour # expiredd token
60
+ redirect_to email_input_url, alert: "Your verification token was created over an hour ago. Please restart the process."
61
+ else
62
+ redirect_to email_input_url, alert: "We were unable to validate your email. Please try again and make sure you are using a valid email address."
63
+ end
64
+ end
65
+
66
+ def create_your_password
67
+ @user = User.find_by(password_creation_token: params[:password_creation_token])
68
+ if @user.blank?
69
+ redirect_to email_input_url, alert: "We were unable to find the record in the database. Please restart the process and make sure you are using a valid email address."
70
+ end
71
+ end
72
+
73
+ def password_creation
74
+ @user = User.find(params[:id])
75
+ unless @user.blank?
76
+ if !params[:user][:password].blank? && (params[:user][:password] == params[:user][:password_confirmation])
77
+ if @user.password_creation_token_sent_at >= Time.zone.now - 1.hour # still valid token
78
+ if @user.update(user_params)
79
+ login_the_user
80
+ flash[:notice] = "Your new password was created and you have been logged in."
81
+ redirect_to session[:target_page] || root_path
82
+ destroy_target_page
83
+ else # did not update ?!?
84
+ flash[:alert] = "Some problems occurred while trying to create your password"
85
+ render create_your_password
86
+ end
87
+ else # the token has expired
88
+ redirect_to email_input_path, alert: 'Sorry, your password_creation_token has expired. To protect your privacy and ensure your security, we need to ask you to start the process over again. The token, when created, expires after 1 hour!'
89
+ end
90
+ else # password is blank or password and password_confirmation don't match
91
+ redirect_to :back, alert: 'Your password cannot be blank and the password should be identical to the password confirmation. Please try again.'
92
+ end
93
+ else # @user is blank
94
+ redirect_to email_input_path, alert: 'We could not find this user record in our database. Please start the process over.'
95
+ end
96
+ end
97
+
98
+ def enter_your_password
99
+ @user = User.find_by(auth_token: params[:auth_token])
100
+ end
101
+
102
+ def password_checking
103
+ @user = User.find(params[:id])
104
+ if @user
105
+ if @user.email_validated?
106
+ if @user.authenticate(params[:user][:password])
107
+ login_the_user
108
+ redirect_to (session[:target_page] || root_url), notice: t('authentication.login_confirmation')
109
+ destroy_target_page
110
+ else # most likely wrong password
111
+ flash.now.alert = t('authentication.warning.email_or_password_invalid')
112
+ render "enter_your_password"
113
+ end
114
+ else # email not validated
115
+ send_validation_email
116
+ redirect_to root_path, alert: 'Our records show that your email address has not been validated. We need you to do so before letting your log in. Please check your email inbox or spam folder for an validation email.'
117
+ end
118
+ else # we can't find the user in the database
119
+ flash[:alert] = "We were unable to find your email in the database. Please try again and make sure you are using a valid email address."
120
+ redirect_to email_input_url
121
+ end
122
+ end
123
+
124
+ def i_forgot_my_password
125
+ end
126
+
127
+ def request_new_password
128
+ @user = User.find_by(email: params[:user][:email])
129
+ if @user
130
+ send_new_password_request_email
131
+ # show confirmation screen
132
+ else
133
+ redirect_to i_forgot_my_password_path, alert: "We could not find a user with this email address: #{params[:user][:email]}. Please try again."
134
+ end
135
+ end
136
+
137
+ def change_your_password
138
+ @user = User.find_by(password_reset_token: params[:password_reset_token])
139
+ if @user.blank?
140
+ redirect_to email_input_url, alert: "We were unable to find the record in the database. Please restart the process and make sure you are using a valid email address."
141
+ end
142
+ end
143
+
144
+ def password_reset
145
+ @user = User.find(params[:id])
146
+ if @user.present?
147
+ if params[:user][:password].present? && (params[:user][:password] == params[:user][:password_confirmation])
148
+ if @user.password_reset_sent_at >= Time.zone.now - 1.hour # still valid token
149
+ if @user.update(user_params)
150
+ login_the_user
151
+ flash[:notice] = "Your password was changed and you have been logged in."
152
+ redirect_to session[:target_page] || root_path
153
+ destroy_target_page
154
+ else # did not update ?!?
155
+ flash[:alert] = "Some problems occurred while trying to change your password. Please try again."
156
+ render change_your_password
157
+ end
158
+ else # the token has expired
159
+ redirect_to email_input_path, alert: 'Sorry, your password_reset_token has expired. To protect your privacy and ensure your security, we need to ask you to start the process over again. The token, when created, expires after 1 hour!'
160
+ end
161
+ else # password is blank or password and password_confirmation don't match
162
+ redirect_to :back, alert: 'Your password cannot be blank and the password should be identical to the password confirmation. Please try again.'
163
+ end
164
+ else # @user is blank
165
+ redirect_to email_input_path, alert: 'We could not find this user record in our database. Please start the process over.'
166
+ end
167
+ end
168
+
169
+ def disconnect
170
+ cookies.delete(:auth_token)
171
+ redirect_to session[:target_page] || root_url, notice: t('authentication.logout_confirmation')
172
+ destroy_target_page
173
+ end
174
+
175
+ private
176
+
177
+ # Never trust parameters from the scary internet, only allow the white list through.
178
+ def user_params
179
+ params.require(:user).permit :email, :password, :password_confirmation, :first_name, :last_name, :other_name
180
+ end
181
+
182
+ def set_target_page
183
+ session[:target_page] = request.referer unless session[:target_page]
184
+ end
185
+
186
+ def destroy_target_page
187
+ session[:target_page] = nil
188
+ end
189
+
190
+ def send_validation_email
191
+ set_email_validation_token
192
+ ReceptionMailer.verification_email(@user).deliver
193
+ end
194
+
195
+ def set_email_validation_token
196
+ @user.generate_token(:email_validation_token)
197
+ @user.email_validation_token_sent_at = Time.zone.now
198
+ @user.save
199
+ end
200
+
201
+ def send_password_creation_security_email
202
+ set_password_creation_token
203
+ ReceptionMailer.password_creation_verification_email(@user).deliver
204
+ end
205
+
206
+ def set_password_creation_token
207
+ @user.generate_token(:password_creation_token)
208
+ @user.password_creation_token_sent_at = Time.zone.now
209
+ @user.save
210
+ end
211
+
212
+ def send_new_password_request_email
213
+ set_password_reset_token
214
+ ReceptionMailer.new_password_request_email(@user).deliver
215
+ end
216
+
217
+ def set_password_reset_token
218
+ @user.generate_token(:password_reset_token)
219
+ @user.password_reset_sent_at = Time.zone.now
220
+ @user.save
221
+ end
222
+
223
+ def login_the_user
224
+ if params[:user][:remember_me].to_i == 1
225
+ cookies.permanent[:auth_token] = @user.auth_token
226
+ else
227
+ cookies[:auth_token] = @user.auth_token
228
+ end
229
+ end
230
+
231
+ end
@@ -0,0 +1,19 @@
1
+ class ReceptionMailer < ActionMailer::Base
2
+ default from: "#{Setting.first.try(:site_name)} <#{Setting.first.contact_email}>"
3
+
4
+ def verification_email(user)
5
+ @user = user
6
+ mail(to: @user.email, subject: "Email validation for #{Setting.first.try(:site_name)}")
7
+ end
8
+
9
+ def password_creation_verification_email(user)
10
+ @user = user
11
+ mail(to: @user.email, subject: "Password creation confirmation for #{Setting.first.try(:site_name)}")
12
+ end
13
+
14
+ def new_password_request_email(user)
15
+ @user = user
16
+ mail(to: @user.email, subject: "New Password Request for #{Setting.first.try(:site_name)}")
17
+ end
18
+
19
+ end
@@ -1,21 +1,15 @@
1
1
  class User < ActiveRecord::Base
2
2
 
3
- has_secure_password
3
+ has_secure_password(validations: false)
4
4
 
5
5
  # associations connected to tkh_content gem. Any page or comment model will do
6
6
  has_many :pages
7
7
  has_many :comments, :dependent => :destroy, foreign_key: 'author_id'
8
8
 
9
- # not allowed are :admin:boolean, :auth_token:string, password_reset_token:string, password_reset_sent_at:datetime
10
- # attr_accessible :email, :password, :password_confirmation, :first_name, :last_name, :other_name
11
-
12
9
  validates_presence_of :email
13
10
  validates_uniqueness_of :email, :case_sensitive => false
14
- # validates_presence_of :password, on: :create
15
11
 
16
- # TODO - this needs to be somehow integrated in the click flow
17
- # validates_presence_of :first_name
18
- # validates_presence_of :last_name
12
+ attr_accessor :remember_me
19
13
 
20
14
  scope :alphabetically, -> { order('last_name, first_name') }
21
15
  scope :administrators, -> { where('admin = ?', true) }
@@ -28,7 +22,6 @@ class User < ActiveRecord::Base
28
22
  "#{id}-#{name.to_url}"
29
23
  end
30
24
 
31
-
32
25
  def name
33
26
  "#{first_name} #{last_name}".strip
34
27
  end
@@ -37,20 +30,32 @@ class User < ActiveRecord::Base
37
30
  "#{last_name}, #{first_name}".strip
38
31
  end
39
32
 
33
+ def friendly_name
34
+ other_name || first_name
35
+ end
36
+
40
37
  def spiritual_name
41
- @spiritual_name = other_name || first_name
38
+ other_name || name
42
39
  end
43
40
 
44
- def send_password_reset
45
- generate_token(:password_reset_token)
46
- self.password_reset_sent_at = Time.zone.now
47
- save!
48
- UserMailer.password_reset(self).deliver
41
+ def visible_name_present? # used in tkh_authentication to determin whether to show name fields in login form
42
+ name.present? || other_name.present?
43
+ end
44
+
45
+ # def send_password_reset
46
+ # generate_token(:password_reset_token)
47
+ # self.password_reset_sent_at = Time.zone.now
48
+ # save!
49
+ # UserMailer.password_reset(self).deliver
50
+ # end
51
+
52
+ def has_a_password?
53
+ password_digest
49
54
  end
50
55
 
51
56
  def generate_token(column)
52
57
  begin
53
- self[column] = SecureRandom.urlsafe_base64
58
+ self[column] = SecureRandom.urlsafe_base64(40)
54
59
  end while User.exists?(column => self[column])
55
60
  end
56
61
 
@@ -0,0 +1,19 @@
1
+ <%= simple_form_for @user, :url => password_checking_path(@user.id), id: 'enter-you-password-form', method: :post do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <p>Email: <strong><%= @user.email %></strong>. (<small><%= link_to "want to use a different email?", email_input_path %></small>)</p>
5
+ <%= f.input :password, autofocus: true, hint: link_to("forgot your password?", i_forgot_my_password_path) %>
6
+ <br />
7
+ <%= f.input_field :remember_me, as: :boolean, boolean_style: :inline, checked: 'checked' %> &nbsp;remember me
8
+ <br /><br />
9
+
10
+ <% unless @user.visible_name_present? %>
11
+ <p>Please take a few seconds to enter your name.</p>
12
+ <%= f.input :first_name %>
13
+ <%= f.input :last_name %>
14
+ <% # i want certain sites to use a different label for this. They can add a partial in host app. %>
15
+ <%= f.input :other_name, label: render('shared/other_name_label') %><br />
16
+ <% end %>
17
+
18
+ <%= f.submit 'log in!', class: 'btn btn-primary' %>
19
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <%= simple_form_for @user, :url => password_checking_path(@user.id), id: 'enter-you-password-form', method: :post do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <p>Email: <strong><%= @user.email %></strong>. (<small><%= link_to "want to use a different email?", email_input_path %></small>)</p>
5
+ <%= f.input :password, autofocus: true, hint: link_to("forgot your password?", i_forgot_my_password_path) %>
6
+ <br />
7
+ <%= f.input_field :remember_me, as: :boolean, boolean_style: :inline, checked: 'checked' %> &nbsp;remember me
8
+ <br /><br />
9
+
10
+ <% unless @user.visible_name_present? %>
11
+ <p>Please take a few seconds to enter your name.</p>
12
+ <%= f.input :first_name %>
13
+ <%= f.input :last_name %>
14
+ <% # i want certain sites to use a different label for this. They can add a partial in host app. %>
15
+ <%= f.input :other_name, label: render('shared/other_name_label') %><br />
16
+ <% end %>
17
+
18
+ <%= f.submit 'log in!', class: 'btn btn-primary' %>
19
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% content_for :meta_title, 'Change your password' %>
2
+ <% content_for :meta_description, "You need to create a new password so that we can log you in." %>
3
+
4
+ <h1>Change Your Password</h1>
5
+
6
+ <%= simple_form_for @user, :url => password_reset_path(@user.id), method: :post do |f| %>
7
+ <%= f.error_notification %>
8
+
9
+ <p>Email: <strong><%= @user.email %></strong>. (<small><%= link_to "want to use a different email?", email_input_path %></small>)</p>
10
+
11
+ <%= f.input :password, autofocus: true %>
12
+ <%= f.input :password_confirmation %>
13
+ <br />
14
+ <%= f.input_field :remember_me, as: :boolean, boolean_style: :inline %> &nbsp;yes, remember me
15
+ <br /><br />
16
+ <%= f.submit 'change your password and log in!', class: 'btn btn-primary' %>
17
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% content_for :meta_title, 'Create your password' %>
2
+ <% content_for :meta_description, "You need to create a password so that we can log you in." %>
3
+
4
+ <h1>Create Your Password & We'll Log You Right In</h1>
5
+
6
+ <%= simple_form_for @user, :url => password_creation_path(@user.id), method: :post do |f| %>
7
+ <%= f.error_notification %>
8
+
9
+ <p>Email: <strong><%= @user.email %></strong>. (<small><%= link_to "want to use a different email?", email_input_path %></small>)</p>
10
+
11
+ <%= f.input :password, autofocus: true %>
12
+ <%= f.input :password_confirmation %>
13
+ <br />
14
+ <%= f.input_field :remember_me, as: :boolean, boolean_style: :inline, checked: 'checked' %> &nbsp;remember me
15
+ <br /><br />
16
+ <%= f.submit 'Create password and log in!', class: 'btn btn-primary' %>
17
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <% content_for :meta_title, 'Login with your email' %>
2
+ <% content_for :meta_description, "We need your email address to initiate the login or account creation procedure." %>
3
+
4
+ <% unless current_user # most folks coming to this page should not be logged in %>
5
+
6
+ <h1>Login</h1>
7
+
8
+ <%= simple_form_for User.new, url: parse_email_path, html: { id: 'email-input-form' }, remote: true, method: 'post' do |f| %>
9
+ <%= f.error_notification %>
10
+
11
+ <%= f.input :email, autofocus: true, label: 'Please enter your email address' %>
12
+ <br />
13
+ <%= f.button :submit, 'proceed', :class => 'btn btn-primary' %>
14
+ <% end %>
15
+
16
+ <% else # the user is already logged in %>
17
+
18
+ <h1>You are already logged in</h1>
19
+ <p>This is the login page but it appears that you are already logged in with this address: <strong><%= current_user.email %></strong></p>
20
+
21
+ <p><%= link_to 'go to home page', root_path, class: 'btn btn-primary' %><%= link_to 'logout', disconnect_path, class: 'btn btn-default' %></p>
22
+
23
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% content_for :meta_title, 'Enter your password and log in!' %>
2
+ <% content_for :meta_description, "Enter your password to log in." %>
3
+
4
+ <h1>Enter Your Password & We'll Log You Right In</h1>
5
+
6
+ <%= render 'enter_your_password_form' %>
@@ -0,0 +1,8 @@
1
+ <h1>Forgot your password?</h1>
2
+
3
+ <%= simple_form_for User.new, :url => request_new_password_path, method: :post do |f| %>
4
+ <%= f.error_notification %>
5
+
6
+ <%= f.input :email, autofocus: true, hint: "We'll send an email to this address." %>
7
+ <%= f.submit 'let me set a new password!', class: 'btn btn-primary' %>
8
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <% if @status == 'email_validation_email_sent' %>
2
+
3
+ <% content_for :meta_title, 'Email Confirmation' %>
4
+ <% content_for :meta_description, "An email was just sent. Please check your inbox." %>
5
+ <h1>A Validation Email is Coming</h1>
6
+ <p>We've just sent an email to <strong><%= @user.email %></strong>. Please check your inbox or spam folder.</p>
7
+
8
+ <% elsif @status == 'password_confirmation_email_sent' %>
9
+
10
+ <% content_for :meta_title, 'Password creation Email Confirmation' %>
11
+ <% content_for :meta_description, "An email was just sent. Please check your inbox." %>
12
+ <h1>A Password Creation Security Email is Coming</h1>
13
+ <p>For your security we need to check that you truly are the owner of this account. Please check your <strong><%= @user.email %></strong> inbox or spam folder.</p>
14
+
15
+ <% end %>
@@ -0,0 +1,4 @@
1
+ // $('#email-input-form').slideUp(500);
2
+ $('#email-input-form').replaceWith("<%= escape_javascript(render(:partial => 'reception/enter_your_password_form')) %>");
3
+ $(".user_password").effect("highlight", { color: '#8D5530' }, 750);
4
+ $('input#user_password').focus();
@@ -0,0 +1,6 @@
1
+ <% content_for :meta_title, 'New Password Request Email Confirmation' %>
2
+ <% content_for :meta_description, "An email was just sent to enable you to get your new password. Please check your inbox." %>
3
+
4
+ <h1>Your New Password Request Email is Coming</h1>
5
+
6
+ <p>To enable you to reset your password we've just sent an email to <strong><%= @user.email %></strong>. Please check your inbox or spam folder.</p>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
+ </head>
6
+ <body>
7
+ <h1>Hello. You are in the process of creating a new password for your account.</h1>
8
+ <p>
9
+ To protect your privacy, we need you to confirm you are the owner of this specific account.
10
+ </p>
11
+ <p>
12
+ Please visit <%= link_to 'this security link', change_your_password_url(password_reset_token: @user.password_reset_token) %>.
13
+ </p>
14
+ <p>Thank you for visiting our site. We appreciate your presence.</p>
15
+ <p>If you did <strong>not</strong> initiate this procedure, please ignore this email.</p>
16
+ </body>
17
+ </html>
@@ -0,0 +1,9 @@
1
+ Hello. You are in the process of creating a new password for your account.
2
+
3
+ To protect your privacy, we need you to confirm you are the owner of this specific account.
4
+
5
+ Please visit this security link: <%= change_your_password_url(password_reset_token: @user.password_reset_token) %>
6
+
7
+ Thank you for visiting our site. We appreciate your presence.
8
+
9
+ P.S. If you did not initiate this procedure, please ignore this email.
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
+ </head>
6
+ <body>
7
+ <h1>Hello. You are in the process of creating a password for your account.</h1>
8
+ <p>
9
+ To protect your privacy, we need you to confirm you are the owner of this specific account.
10
+ </p>
11
+ <p>
12
+ Please visit <%= link_to 'this security link', create_your_password_url(password_creation_token: @user.password_creation_token) %>.
13
+ </p>
14
+ <p>Thank you for visiting our site. We appreciate your presence.</p>
15
+ <p>If you did <strong>not</strong> initiate this procedure, please ignore this email.</p>
16
+ </body>
17
+ </html>
@@ -0,0 +1,9 @@
1
+ Hello. You are in the process of creating a password for your account.
2
+
3
+ To protect your privacy, we need you to confirm you are the owner of this specific account.
4
+
5
+ Please visit this security link: <%= create_your_password_url(password_creation_token: @user.password_creation_token) %>
6
+
7
+ Thank you for visiting our site. We appreciate your presence.
8
+
9
+ P.S. If you did not initiate this procedure, please ignore this email.
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
+ </head>
6
+ <body>
7
+ <h1>Hello. We need to verify your email address</h1>
8
+ <p>
9
+ To protect your privacy, we need you to confirm you are the owner of the <%= @user.email %> address.
10
+ </p>
11
+ <p>
12
+ Please visit <%= link_to 'this activation link', email_validation_url(token: @user.email_validation_token) %>.
13
+ </p>
14
+ <p>Thank you for visiting our site. We appreciate your presence.</p>
15
+ </body>
16
+ </html>
@@ -0,0 +1,7 @@
1
+ Hello. We need to verify your email address.
2
+
3
+ To protect your privacy, we need you to confirm you are the owner of the <%= @user.email %> address.
4
+
5
+ Please visit this activation link: <%= email_validation_url(token: @user.email_validation_token) %>
6
+
7
+ Thank you for visiting our site. We appreciate your presence.
@@ -1,5 +1,5 @@
1
1
  <% if current_user %>
2
- <ul class="nav navbar-nav navbar-right">
2
+ <ul class="nav navbar-nav navbar-right navbar-login-info">
3
3
  <li class='dropdown'>
4
4
  <a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= current_user.email %> <b class="caret"></b></a>
5
5
  <ul class="dropdown-menu">
@@ -9,6 +9,6 @@
9
9
  </ul>
10
10
  <% else %>
11
11
  <ul class="nav navbar-nav navbar-right">
12
- <%= content_tag :li, link_to(t('authentication.login_now'), login_path) %>
12
+ <%= content_tag :li, link_to(t('authentication.login_now'), email_input_path) %>
13
13
  </ul>
14
14
  <% end %>
@@ -0,0 +1 @@
1
+ nickname or other name
@@ -1,16 +1,12 @@
1
1
  <%= simple_form_for user, :html => { class: 'form-horizontal' } do |f| %>
2
2
  <%= f.error_notification %>
3
3
 
4
- <div class="form-inputs">
5
4
  <%= f.input :email %>
6
5
  <%= f.input :first_name %>
7
6
  <%= f.input :last_name %>
8
7
  <%= f.input :other_name %>
9
8
  <%= f.input :password %>
10
9
  <%= f.input :password_confirmation, required: true %>
11
- </div>
12
10
 
13
- <div class="form-actions">
14
11
  <%= f.button :submit, t('authentication.create_account'), :class => 'btn btn-primary' %>
15
- </div>
16
12
  <% end %>
@@ -1,8 +1,6 @@
1
1
  Rails.application.routes.draw do
2
+
2
3
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
3
- get 'signup', to: 'users#new', as: 'signup'
4
- get 'login', to: 'sessions#new', as: 'login'
5
- get 'logout', to: 'sessions#destroy', as: 'logout'
6
4
 
7
5
  resources :users do
8
6
  member do
@@ -11,7 +9,26 @@ Rails.application.routes.draw do
11
9
  end
12
10
  collection { post :detect_existence }
13
11
  end
14
- resources :sessions
15
- resources :password_resets
12
+
13
+ ##### ACCESS CONTROL
14
+ # legacy routes. Pointing to new pathway.
15
+ get 'signup', to: 'reception#email_input', as: 'signup'
16
+ get 'login', to: 'reception#email_input', as: 'login'
17
+ get 'logout', to: 'reception#disconnect', as: 'logout'
18
+ # New access control pathway
19
+ get '/reception', to: 'reception#email_input', as: 'email_input'
20
+ post '/parse_email', to: 'reception#parse_email'
21
+ get '/email_validation', to: 'reception#email_validation'
22
+ get '/create_your_password', to: 'reception#create_your_password'
23
+ post '/password_creation/:id', to: 'reception#password_creation', as: 'password_creation'
24
+ get '/enter_your_password', to: 'reception#enter_your_password'
25
+ post '/password_checking/:id', to: 'reception#password_checking', as: 'password_checking'
26
+ get '/i_forgot_my_password', to: 'reception#i_forgot_my_password'
27
+ post '/request_new_password', to: 'reception#request_new_password'
28
+ get '/change_your_password', to: 'reception#change_your_password'
29
+ post '/password_reset/:id', to: 'reception#password_reset', as: 'password_reset'
30
+ get '/disconnect', to: 'reception#disconnect'
31
+
16
32
  end
33
+
17
34
  end
@@ -20,6 +20,7 @@ module TkhAuthentication
20
20
  migration_template "create_users.rb", "db/migrate/create_users.rb"
21
21
  migration_template "add_other_name_to_users.rb", "db/migrate/add_other_name_to_users.rb"
22
22
  migration_template "add_email_validation_to_users.rb", "db/migrate/add_email_validation_to_users.rb"
23
+ migration_template "add_password_creation_token.rb", "db/migrate/add_password_creation_token.rb"
23
24
  end
24
25
 
25
26
  end
@@ -0,0 +1,6 @@
1
+ class AddPasswordCreationToken < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :password_creation_token, :string
4
+ add_column :users, :password_creation_token_sent_at, :datetime
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module TkhAuthentication
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swami Atma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-21 00:00:00.000000000 Z
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.0.rc1
47
+ version: 3.1.0.rc2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.0.rc1
54
+ version: 3.1.0.rc2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: stringex
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -92,23 +92,32 @@ files:
92
92
  - MIT-LICENSE
93
93
  - README.md
94
94
  - Rakefile
95
- - app/controllers/password_resets_controller.rb
96
- - app/controllers/sessions_controller.rb
95
+ - app/controllers/reception_controller.rb
97
96
  - app/controllers/users_controller.rb
98
- - app/mailers/user_mailer.rb
99
- - app/models/newbie.rb
97
+ - app/mailers/reception_mailer.rb
100
98
  - app/models/user.rb
101
- - app/views/password_resets/edit.html.erb
102
- - app/views/password_resets/new.html.erb
103
- - app/views/sessions/_form.html.erb
104
- - app/views/sessions/new.html.erb
99
+ - app/views/reception/_enter_your_password_form.html.erb
100
+ - app/views/reception/_enter_your_password_form.js.erb
101
+ - app/views/reception/change_your_password.html.erb
102
+ - app/views/reception/create_your_password.html.erb
103
+ - app/views/reception/email_input.html.erb
104
+ - app/views/reception/enter_your_password.html.erb
105
+ - app/views/reception/i_forgot_my_password.html.erb
106
+ - app/views/reception/parse_email.html.erb
107
+ - app/views/reception/parse_email.js.erb
108
+ - app/views/reception/request_new_password.html.erb
109
+ - app/views/reception_mailer/new_password_request_email.html.erb
110
+ - app/views/reception_mailer/new_password_request_email.text.erb
111
+ - app/views/reception_mailer/password_creation_verification_email.html.erb
112
+ - app/views/reception_mailer/password_creation_verification_email.text.erb
113
+ - app/views/reception_mailer/verification_email.html.erb
114
+ - app/views/reception_mailer/verification_email.text.erb
105
115
  - app/views/shared/_embedded_access_control.html.erb
106
116
  - app/views/shared/_embedded_login_module.html.erb
107
117
  - app/views/shared/_login_info.html.erb
108
118
  - app/views/shared/_login_info_for_navbar.html.erb
109
119
  - app/views/shared/_login_info_for_sidebar.html.erb
110
- - app/views/user_mailer/password_reset.text.erb
111
- - app/views/user_mailer/password_set.text.erb
120
+ - app/views/shared/_other_name_label.html.erb
112
121
  - app/views/users/_detect_user_existence_form.html.erb
113
122
  - app/views/users/_form.html.erb
114
123
  - app/views/users/index.html.erb
@@ -123,6 +132,7 @@ files:
123
132
  - lib/generators/tkh_authentication/create_or_update_migrations/create_or_update_migrations_generator.rb
124
133
  - lib/generators/tkh_authentication/create_or_update_migrations/templates/add_email_validation_to_users.rb
125
134
  - lib/generators/tkh_authentication/create_or_update_migrations/templates/add_other_name_to_users.rb
135
+ - lib/generators/tkh_authentication/create_or_update_migrations/templates/add_password_creation_token.rb
126
136
  - lib/generators/tkh_authentication/create_or_update_migrations/templates/create_users.rb
127
137
  - lib/tasks/tkh_authentication_tasks.rake
128
138
  - lib/tkh_authentication.rb
@@ -1,36 +0,0 @@
1
- class PasswordResetsController < ApplicationController
2
-
3
- def create
4
- user = User.find_by_email(params[:email])
5
- if user
6
- user.send_password_reset
7
- redirect_to root_url, :notice => t('authentication.reset_password_email_sent_confirmation')
8
- else
9
- redirect_to root_url, :alert => t('authentication.warning.no_such_email')
10
- end
11
- end
12
-
13
- def edit
14
- @user = User.find_by_password_reset_token!(params[:id])
15
- end
16
-
17
- def update
18
- @user = User.find_by_password_reset_token!(params[:id])
19
- if @user.password_reset_sent_at < 2.hours.ago
20
- redirect_to new_password_reset_path, :alert => t('authentication.warning.password_reset_expired')
21
- elsif @user.update_attributes(params[:user])
22
- cookies[:auth_token] = @user.auth_token # logging in the user
23
- redirect_to session[:target_page] || safe_root_url, notice: t('authentication.password_reset_confirmation')
24
- destroy_target_page
25
- else
26
- render :edit
27
- end
28
- end
29
-
30
- private
31
-
32
- def destroy_target_page
33
- session[:target_page] = nil
34
- end
35
-
36
- end
@@ -1,41 +0,0 @@
1
- class SessionsController < ApplicationController
2
-
3
- def new
4
- set_target_page
5
- redirect_to root_path if current_user
6
- end
7
-
8
- def create
9
- set_target_page
10
- user = User.find_by_email(params[:email])
11
- if user && user.authenticate(params[:password])
12
- if params[:remember_me]
13
- cookies.permanent[:auth_token] = user.auth_token
14
- else
15
- cookies[:auth_token] = user.auth_token
16
- end
17
- redirect_to (session[:target_page] || safe_root_url), notice: t('authentication.login_confirmation')
18
- destroy_target_page
19
- else
20
- flash.now.alert = t('authentication.warning.email_or_password_invalid')
21
- render "new"
22
- end
23
- end
24
-
25
- def destroy
26
- cookies.delete(:auth_token)
27
- destroy_target_page
28
- redirect_to safe_root_url, notice: t('authentication.logout_confirmation')
29
- end
30
-
31
- private
32
-
33
- def set_target_page
34
- session[:target_page] = request.referer unless session[:target_page] # && !request.referer.nil?
35
- end
36
-
37
- def destroy_target_page
38
- session[:target_page] = nil
39
- end
40
-
41
- end
@@ -1,20 +0,0 @@
1
- class UserMailer < ActionMailer::Base
2
-
3
- default :from => Setting.first.try(:contact_email) ? Setting.first.try(:contact_email) : 'info@tenthousandhours.eu'
4
-
5
- # Subject can be set in your I18n file at config/locales/en.yml
6
- # with the following lookup:
7
- #
8
- # en.user_mailer.password_reset.subject
9
- #
10
- def password_reset(user)
11
- @user = user
12
- mail :to => user.email, :subject => t('authentication.password_reset_email_subject') + ' | ' + Setting.first.try(:site_name)
13
- end
14
-
15
- def password_set(user)
16
- @user = user
17
- mail :to => user.email, :subject => t('authentication.email_validation_subject') + ' | ' + Setting.first.try(:site_name)
18
- end
19
-
20
- end
@@ -1,12 +0,0 @@
1
- class Newbie < User
2
-
3
- def send_password_set
4
- generate_token(:password_reset_token)
5
- self.password_reset_sent_at = Time.zone.now
6
- # necessary to pass has_secure_password validations
7
- self.password, self.password_confirmation = 'temporary', 'temporary'
8
- save!
9
- UserMailer.password_set(self).deliver
10
- end
11
-
12
- end
@@ -1,14 +0,0 @@
1
- <h1>Create a new Password</h1>
2
-
3
- <%= simple_form_for @user, :url => password_reset_path(params[:id]) do |f| %>
4
- <%= f.error_notification %>
5
-
6
- <div class="field">
7
- <%= f.input :password %>
8
- <%= f.input :password_confirmation %>
9
- </div>
10
- <div class="actions"><%= f.submit t('authentication.update_password') %></div>
11
- <% end %>
12
-
13
- <%# partial in tkh_menus gem or has to be added in host app %>
14
- <%= render './shared/menus' %>
@@ -1,14 +0,0 @@
1
- <h1><%= t('authentication.password.request.a_new_one') %></h1>
2
-
3
- <p><%= t('authentication.password.request.explanation') %></p>
4
-
5
- <%= form_tag password_resets_path, :method => :post do %>
6
- <div class="field">
7
- <%= label_tag :email %>
8
- <%= text_field_tag :email, params[:email] %>
9
- </div>
10
- <div class="actions"><%= submit_tag t('authentication.reset_your_password'), class: 'btn btn-primary' %></div>
11
- <% end %>
12
-
13
- <%# partial in tkh_menus gem or has to be added in host app %>
14
- <%= render './shared/menus' %>
@@ -1,32 +0,0 @@
1
- <%= form_tag sessions_path, class: 'simple_form form-horizontal' do %>
2
-
3
- <div class="form-inputs">
4
- <div class="control-group email required">
5
- <%= label_tag :email, t('activerecord.attributes.user.email'), class: "email required control-label" %>
6
- <div class="controls">
7
- <%= text_field_tag :email, params[:email], :html => { class: 'string email required' } %>
8
- <p class="help-block"><%= link_to t('authentication.not_registered'), signup_path %></p>
9
- </div>
10
- </div>
11
-
12
- <div class="control-group password required">
13
- <%= label_tag :password, t('activerecord.attributes.user.password'), class: "password required control-label" %>
14
- <div class="controls">
15
- <%= password_field_tag :password %>
16
- <p class="help-block"><%= link_to t('authentication.forgot_password'), new_password_reset_path %></p>
17
- </div>
18
- </div>
19
-
20
- <div class="control-group boolean optional">
21
- <div class="controls">
22
- <label class="checkbox"><input class="boolean optional" id="remember_me" name="remember_me" type="checkbox" value="1" /><%= t('authentication.remember_me') %></label>
23
- </div>
24
- </div>
25
-
26
- </div>
27
-
28
- <div class="form-actions">
29
- <%= submit_tag t('authentication.login_now'), class: 'btn btn-primary' %>
30
- </div>
31
-
32
- <% end %>
@@ -1,6 +0,0 @@
1
- <h1><%= t('authentication.login_now') %></h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%# partial in tkh_menus gem or has to be added in host app %>
6
- <%= render './shared/menus' %>
@@ -1 +0,0 @@
1
- <%= t 'authentication.reset_instructions', reset_url: edit_password_reset_url(@user.password_reset_token, locale: I18n.locale) %>
@@ -1 +0,0 @@
1
- <%= t 'authentication.email_validation_instructions', reset_url: edit_password_reset_url(@user.password_reset_token, locale: I18n.locale) %>