Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 99 lines (80 sloc) 2.425 kb
0b7dadf @qrush Revert "Removing namespaces for controllers"
qrush authored
1 class Clearance::PasswordsController < ApplicationController
9e669e4 @qrush Making the clearance controllers unloadable
qrush authored
2 unloadable
087b55b @croaky scope skip_before_filter :authenticate to only actions Clearance defines...
croaky authored
3
78f8f0f @croaky Apply style guidelines
croaky authored
4 skip_before_filter :authorize, :only => [:create, :edit, :new, :update]
5 before_filter :forbid_missing_token, :only => [:edit, :update]
c22d6d6 @qrush Correcting some spelling errors
qrush authored
6 before_filter :forbid_non_existent_user, :only => [:edit, :update]
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
7
8 def create
78f8f0f @croaky Apply style guidelines
croaky authored
9 if user = find_user_for_create
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
10 user.forgot_password!
0fbf771 @joshuaclayton Update clearance and tests to Rails3-style syntax
joshuaclayton authored
11 ::ClearanceMailer.change_password(user).deliver
5e107f6 @croaky [#147] Resetting password no longer redirects to sign in page. It displa...
croaky authored
12 render :template => 'passwords/create'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
13 else
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_failu...
croaky authored
14 flash_failure_after_create
4ecad82 @jferris Namespaced the passwords controller
jferris authored
15 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
16 end
17 end
18
19 def edit
78f8f0f @croaky Apply style guidelines
croaky authored
20 @user = find_user_for_edit
4ecad82 @jferris Namespaced the passwords controller
jferris authored
21 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
22 end
23
78f8f0f @croaky Apply style guidelines
croaky authored
24 def new
25 render :template => 'passwords/new'
26 end
27
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
28 def update
78f8f0f @croaky Apply style guidelines
croaky authored
29 @user = find_user_for_update
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
30
78f8f0f @croaky Apply style guidelines
croaky authored
31 if @user.update_password params[:user][:password]
32 sign_in @user
33 redirect_to url_after_update
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
34 else
04b2363 @croaky Remove dependency on dynamic_form. Replaced with flashes due to limited ...
croaky authored
35 flash_failure_after_update
4ecad82 @jferris Namespaced the passwords controller
jferris authored
36 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
37 end
38 end
39
40 private
41
78f8f0f @croaky Apply style guidelines
croaky authored
42 def find_user_by_id_and_confirmation_token
43 Clearance.configuration.user_model.
44 find_by_id_and_confirmation_token params[:user_id], params[:token].to_s
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
45 end
46
78f8f0f @croaky Apply style guidelines
croaky authored
47 def find_user_for_create
48 Clearance.configuration.user_model.find_by_email params[:password][:email]
49 end
50
51 def find_user_for_edit
52 find_user_by_id_and_confirmation_token
53 end
54
55 def find_user_for_update
56 find_user_by_id_and_confirmation_token
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
57 end
58
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
59 def flash_failure_when_forbidden
d955f09 @croaky Using flash :notice key everywhere now instead of :success and :failure....
croaky authored
60 flash.now[:notice] = translate(:forbidden,
78f8f0f @croaky Apply style guidelines
croaky authored
61 :scope => [:clearance, :controllers, :passwords],
62 :default => 'Please double check the URL or try submitting the form again.')
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
63 end
64
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_failu...
croaky authored
65 def flash_failure_after_create
d955f09 @croaky Using flash :notice key everywhere now instead of :success and :failure....
croaky authored
66 flash.now[:notice] = translate(:unknown_email,
78f8f0f @croaky Apply style guidelines
croaky authored
67 :scope => [:clearance, :controllers, :passwords],
68 :default => 'Unknown email.')
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_failu...
croaky authored
69 end
70
04b2363 @croaky Remove dependency on dynamic_form. Replaced with flashes due to limited ...
croaky authored
71 def flash_failure_after_update
d955f09 @croaky Using flash :notice key everywhere now instead of :success and :failure....
croaky authored
72 flash.now[:notice] = translate(:blank_password,
78f8f0f @croaky Apply style guidelines
croaky authored
73 :scope => [:clearance, :controllers, :passwords],
04b2363 @croaky Remove dependency on dynamic_form. Replaced with flashes due to limited ...
croaky authored
74 :default => "Password can't be blank.")
75 end
76
78f8f0f @croaky Apply style guidelines
croaky authored
77 def forbid_missing_token
78 if params[:token].to_s.blank?
79 flash_failure_when_forbidden
80 render :template => 'passwords/new'
81 end
82 end
83
84 def forbid_non_existent_user
85 unless find_user_by_id_and_confirmation_token
86 flash_failure_when_forbidden
87 render :template => 'passwords/new'
88 end
89 end
90
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
91 def url_after_create
92 sign_in_url
93 end
94
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
95 def url_after_update
f4df580 @croaky remove dependency on root_path, use '/' instead.
croaky authored
96 '/'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
97 end
98 end
Something went wrong with that request. Please try again.