Skip to content

Commit 3838ae1

Browse files
committed
[browsermedia#684] Forgot Password should work
There are two forgot password pages, one of public, one for CMS users. * Write Reset password scenario * Implement 'Reset Password' so public users can access it. * Bump version to 4.0.0.beta for testing release. * 'Forgot Password' shows a CMS styled form (even when an error occurs) * Move 'Forgot' to a more prominent place on the sign in.
1 parent f8fa9a0 commit 3838ae1

File tree

11 files changed

+119
-20
lines changed

11 files changed

+119
-20
lines changed

Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
browsercms (4.0.0.alpha)
4+
browsercms (4.0.0.beta)
55
actionpack-page_caching (~> 1.0)
66
ancestry (~> 2.0.0)
77
bootstrap-sass
@@ -52,15 +52,15 @@ GEM
5252
ancestry (2.0.0)
5353
activerecord (>= 3.0.0)
5454
ansi (1.4.3)
55-
arel (4.0.1)
55+
arel (4.0.2)
5656
aruba (0.5.3)
5757
childprocess (>= 0.3.6)
5858
cucumber (>= 1.1.1)
5959
rspec-expectations (>= 2.7.0)
6060
atomic (1.1.14)
6161
bcrypt-ruby (3.1.2)
6262
bluecloth (2.2.0)
63-
bootstrap-sass (3.1.0.0)
63+
bootstrap-sass (3.1.0.2)
6464
sass (~> 3.2)
6565
builder (3.1.4)
6666
capybara (2.1.0)
@@ -71,7 +71,7 @@ GEM
7171
xpath (~> 2.0)
7272
childprocess (0.3.9)
7373
ffi (~> 1.0, >= 1.0.11)
74-
chunky_png (1.2.9)
74+
chunky_png (1.3.0)
7575
ckeditor_rails (4.3.1)
7676
railties (>= 3.0)
7777
climate_control (0.0.3)
@@ -165,7 +165,7 @@ GEM
165165
orm_adapter (0.5.0)
166166
panoramic (0.0.4)
167167
rails (>= 3.0.7)
168-
paperclip (3.5.3)
168+
paperclip (3.5.4)
169169
activemodel (>= 3.0.0)
170170
activesupport (>= 3.0.0)
171171
cocaine (~> 0.5.3)
@@ -220,8 +220,8 @@ GEM
220220
sqlite3 (1.3.7)
221221
sqlite3-ruby (1.3.3)
222222
sqlite3 (>= 1.3.3)
223-
term-ansicolor (1.2.2)
224-
tins (~> 0.8)
223+
term-ansicolor (1.3.0)
224+
tins (~> 1.0)
225225
thin (1.5.1)
226226
daemons (>= 1.0.9)
227227
eventmachine (>= 0.12.6)
@@ -230,7 +230,7 @@ GEM
230230
thread_safe (0.1.3)
231231
atomic
232232
tilt (1.4.1)
233-
tins (0.13.1)
233+
tins (1.0.0)
234234
treetop (1.4.15)
235235
polyglot
236236
polyglot (>= 0.3.1)

app/controllers/cms/passwords_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ def new
88
super
99
end
1010

11+
def create
12+
use_page_title('Forgot Password')
13+
super
14+
end
15+
1116
def edit
1217
use_page_title('Change Password')
1318
super

app/controllers/cms/sites/passwords_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def create
1616
super
1717
end
1818

19+
def edit
20+
use_page_title('Reset Password')
21+
super
22+
end
23+
1924
protected
2025

2126
# @override [Devise::PasswordsController]

app/models/cms/persistent_user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class PersistentUser < ActiveRecord::Base
1111
# Note that Chrome doesn't expire session cookies immediately so test this in other browsers.
1212
# http://stackoverflow.com/questions/16817229/issues-with-devise-rememberable
1313
:rememberable,
14+
:recoverable, # Needs to be here so forgot password link works.
1415
:authentication_keys => [:login]
1516

1617

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%# Overrides devise/passwords/new to add CMS specific styles. %>
2+
<%= render 'cms/application/page_title' %>
3+
4+
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
5+
<%= render layout: 'cms/application/main_with_sidebar' do %>
6+
<%= f.error_notification %>
7+
<%= f.input :email, :required => true, :autofocus => true %>
8+
9+
<%= render "devise/shared/links" %>
10+
<% end %>
11+
<%= render layout: 'cms/application/row' do %>
12+
<%= button_menu :bottom do %>
13+
<%= f.button :submit, "Send me reset password instructions", class: 'right btn-primary' %>
14+
<% end %>
15+
<% end %>
16+
<% end %>
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
<% use_page_title 'Sign in' %>
22
<%= render 'cms/application/page_title' %>
33

4-
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
5-
<%= render layout: 'cms/application/main_with_sidebar' do %>
4+
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
5+
<%= render layout: 'cms/application/main_with_sidebar' do %>
66
<%= f.input :login, :required => false, :autofocus => true %>
77
<%= f.input :password, :required => false %>
88
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
9-
10-
<% end %>
11-
<%= render layout: 'cms/application/row' do %>
12-
<%= button_menu :bottom do %>
13-
<%= f.button :submit, "Sign in", class: 'right btn-primary' %>
14-
<% end %>
15-
<% end %>
16-
<% end %>
17-
<%= render "devise/shared/links" %>
9+
<%= render "devise/shared/links" %>
10+
<% end %>
11+
<%= render layout: 'cms/application/row' do %>
12+
<%= button_menu :bottom do %>
13+
<%= f.button :submit, "Sign in", class: 'right btn-primary' %>
14+
<% end %>
15+
<% end %>
16+
<% end %>

doc/release_notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
* List Portlet [#678] - A convenient way to find content without custom coding.
44
* NameInput [#682] - Improved :name input allows for consistent name fields look/feel. New content will be generated with it.
5+
* [Fixes #684] Forgot Password
6+
7+
* /cms/forgot-password doesn't exist
8+
* Reenable the forgot password link (/forgot-password)
9+
* The edit_password page (pulled from email) doesn't work when followed.
510

611
## [#678] List Portlet
712

features/authentication/user_self_service.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ Feature:
2424
When I login to the public site
2525
Then I should be successful
2626

27+
Scenario: Forgot Password
28+
Given I am not logged in
29+
When I go to the public login page
30+
Then there should be a forgot password link
31+
When I click the forgot password link
32+
And I enter my email address to reset my password
33+
Then I should receive an email with a reset password link.
34+
35+
Scenario: Reset Password
36+
Given I am not logged in
37+
And I have requested to reset my password
38+
When I follow the link in the email
39+
And I enter my new password
40+
Then I should be able to log in with the new password

features/step_definitions/user_steps.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,56 @@
198198

199199
When /^I fill in passwords as "([^"]*)"$/ do |new_pw|
200200
fill_in_password(new_pw)
201+
end
202+
203+
When /^I go to the public login page$/ do
204+
visit "/login"
205+
end
206+
207+
Then /^there should be a forgot password link$/ do
208+
assert page.has_content?("Forgot your password?")
209+
end
210+
211+
When /^I click the forgot password link$/ do
212+
click_on "Forgot your password?"
213+
end
214+
215+
When /^I enter my email address to reset my password$/ do
216+
fill_in "Email", with: Cms::User.first.email
217+
click_on "Send me reset password instructions"
218+
end
219+
220+
Then /^I should receive an email with a reset password link.$/ do
221+
should_be_successful
222+
assert_equal 1, ActionMailer::Base.deliveries.size
223+
assert_equal [Cms::User.first.email], ActionMailer::Base.deliveries.first.to
224+
assert page.has_content?("You will receive an email")
225+
end
226+
227+
Given /^I have requested to reset my password$/ do
228+
visit forgot_password_path
229+
fill_in "Email", with: Cms::User.first.email
230+
click_on "Send me reset password instructions"
231+
end
232+
233+
def cmsadmin
234+
Cms::User.first
235+
end
236+
237+
When /^I follow the link in the email$/ do
238+
visit edit_password_path(reset_password_token: cmsadmin.reset_password_token, id: cmsadmin.id)
239+
should_see_a_page_titled "Reset Password"
240+
end
241+
242+
When /^I enter my new password$/ do
243+
@new_password = "mynewpassword"
244+
fill_in "New password", with: @new_password
245+
fill_in "Confirm your new password", with: @new_password
246+
click_on "Change my password"
247+
should_be_successful
248+
end
249+
250+
Then /^I should be able to log in with the new password$/ do
251+
login_as(Cms::User.first.login, @new_password)
252+
should_be_successful
201253
end

lib/cms/route_extensions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def mount_browsercms
4949
devise_scope :cms_user do
5050
get '/forgot-password' => "cms/sites/passwords#new", :as => 'forgot_password'
5151
post '/forgot-password' => "cms/sites/passwords#create", as: 'cms_user_password'
52+
get '/passwords/:id/edit' => "cms/sites/passwords#edit", as: 'edit_password'
53+
put '/forgot-password' => "cms/sites/passwords#update", as: 'update_password'
5254
end
5355

5456
# Handle 'stock' attachments

0 commit comments

Comments
 (0)