Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (72 sloc) 2.156 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 defi…
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
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
12 end
16bf897 @aripollak Don't expose the existence of a user
aripollak authored
13 render :template => 'passwords/create'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
14 end
15
16 def edit
78f8f0f @croaky Apply style guidelines
croaky authored
17 @user = find_user_for_edit
4ecad82 @jferris Namespaced the passwords controller
jferris authored
18 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
19 end
20
78f8f0f @croaky Apply style guidelines
croaky authored
21 def new
22 render :template => 'passwords/new'
23 end
24
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
25 def update
78f8f0f @croaky Apply style guidelines
croaky authored
26 @user = find_user_for_update
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
27
78f8f0f @croaky Apply style guidelines
croaky authored
28 if @user.update_password params[:user][:password]
29 sign_in @user
30 redirect_to url_after_update
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
31 else
04b2363 @croaky Remove dependency on dynamic_form. Replaced with flashes due to limit…
croaky authored
32 flash_failure_after_update
4ecad82 @jferris Namespaced the passwords controller
jferris authored
33 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
34 end
35 end
36
37 private
38
78f8f0f @croaky Apply style guidelines
croaky authored
39 def find_user_by_id_and_confirmation_token
40 Clearance.configuration.user_model.
41 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
42 end
43
78f8f0f @croaky Apply style guidelines
croaky authored
44 def find_user_for_create
45 Clearance.configuration.user_model.find_by_email params[:password][:email]
46 end
47
48 def find_user_for_edit
49 find_user_by_id_and_confirmation_token
50 end
51
52 def find_user_for_update
53 find_user_by_id_and_confirmation_token
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
54 end
55
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
56 def flash_failure_when_forbidden
d955f09 @croaky Using flash :notice key everywhere now instead of :success and :failu…
croaky authored
57 flash.now[:notice] = translate(:forbidden,
78f8f0f @croaky Apply style guidelines
croaky authored
58 :scope => [:clearance, :controllers, :passwords],
59 :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
60 end
61
04b2363 @croaky Remove dependency on dynamic_form. Replaced with flashes due to limit…
croaky authored
62 def flash_failure_after_update
d955f09 @croaky Using flash :notice key everywhere now instead of :success and :failu…
croaky authored
63 flash.now[:notice] = translate(:blank_password,
78f8f0f @croaky Apply style guidelines
croaky authored
64 :scope => [:clearance, :controllers, :passwords],
04b2363 @croaky Remove dependency on dynamic_form. Replaced with flashes due to limit…
croaky authored
65 :default => "Password can't be blank.")
66 end
67
78f8f0f @croaky Apply style guidelines
croaky authored
68 def forbid_missing_token
69 if params[:token].to_s.blank?
70 flash_failure_when_forbidden
71 render :template => 'passwords/new'
72 end
73 end
74
75 def forbid_non_existent_user
76 unless find_user_by_id_and_confirmation_token
77 flash_failure_when_forbidden
78 render :template => 'passwords/new'
79 end
80 end
81
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
82 def url_after_create
83 sign_in_url
84 end
85
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
86 def url_after_update
f4df580 @croaky remove dependency on root_path, use '/' instead.
croaky authored
87 '/'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
88 end
89 end
Something went wrong with that request. Please try again.