Skip to content
Newer
Older
100644 92 lines (76 sloc) 2.49 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
61b4f2f @croaky [#69] Allow Rails apps to before_filter :authenticate the entire app
croaky authored
4 skip_before_filter :authenticate, :only => [:new, :create, :edit, :update]
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
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 new
4ecad82 @jferris Namespaced the passwords controller
jferris authored
9 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
10 end
11
12 def create
38bafd1 @qrush Revert "Revert "Ensuring constants are at root namespace inside Clear…
qrush authored
13 if user = ::User.find_by_email(params[:password][:email])
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
14 user.forgot_password!
0fbf771 @joshuaclayton Update clearance and tests to Rails3-style syntax
joshuaclayton authored
15 ::ClearanceMailer.change_password(user).deliver
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
16 flash_notice_after_create
1b494fa @croaky formatting standards for redirect_tos
croaky authored
17 redirect_to(url_after_create)
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
18 else
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
19 flash_failure_after_create
4ecad82 @jferris Namespaced the passwords controller
jferris authored
20 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
21 end
22 end
23
24 def edit
46f3617 splitting token/token_expires_at into confirmation_token, remember_to…
Daniel Croak authored
25 @user = ::User.find_by_id_and_confirmation_token(
26 params[:user_id], params[:token])
4ecad82 @jferris Namespaced the passwords controller
jferris authored
27 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
28 end
29
30 def update
46f3617 splitting token/token_expires_at into confirmation_token, remember_to…
Daniel Croak authored
31 @user = ::User.find_by_id_and_confirmation_token(
32 params[:user_id], params[:token])
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
33
324437f @croaky moved remember & forget methods off sessions controller and onto lib/…
croaky authored
34 if @user.update_password(params[:user][:password],
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
35 params[:user][:password_confirmation])
4195760 @croaky deprecated sign_user_in. telling developers to use sign_in instead.
croaky authored
36 sign_in(@user)
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
37 flash_success_after_update
1b494fa @croaky formatting standards for redirect_tos
croaky authored
38 redirect_to(url_after_update)
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
39 else
4ecad82 @jferris Namespaced the passwords controller
jferris authored
40 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
41 end
42 end
43
44 private
45
46 def forbid_missing_token
47 if params[:token].blank?
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
48 flash_failure_when_forbidden
49 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
50 end
51 end
52
c22d6d6 @qrush Correcting some spelling errors
qrush authored
53 def forbid_non_existent_user
46f3617 splitting token/token_expires_at into confirmation_token, remember_to…
Daniel Croak authored
54 unless ::User.find_by_id_and_confirmation_token(
55 params[:user_id], params[:token])
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
56 flash_failure_when_forbidden
57 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
58 end
59 end
60
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
61 def flash_failure_when_forbidden
62 flash.now[:failure] = translate(:forbidden,
63 :scope => [:clearance, :controllers, :passwords],
64 :default => "Please double check the URL or try submitting the form again.")
65 end
66
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
67 def flash_notice_after_create
68 flash[:notice] = translate(:deliver_change_password,
69 :scope => [:clearance, :controllers, :passwords],
70 :default => "You will receive an email within the next few minutes. " <<
71 "It contains instructions for changing your password.")
72 end
73
74 def flash_failure_after_create
75 flash.now[:failure] = translate(:unknown_email,
76 :scope => [:clearance, :controllers, :passwords],
77 :default => "Unknown email.")
78 end
79
80 def flash_success_after_update
81 flash[:success] = translate(:signed_in, :default => "Signed in.")
82 end
83
b004f19 @croaky replaced ActionController::Forbidden with a user-friendly flash message.
croaky authored
84 def url_after_create
85 sign_in_url
86 end
87
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
88 def url_after_update
f4df580 @croaky remove dependency on root_path, use '/' instead.
croaky authored
89 '/'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
90 end
91 end
Something went wrong with that request. Please try again.