Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (71 sloc) 2.359 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
4 skip_before_filter :authenticate, :only => [: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 filter_parameter_logging :password, :password_confirmation
8
9 def new
4ecad82 @jferris Namespaced the passwords controller
jferris authored
10 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
11 end
12
13 def create
38bafd1 @qrush Revert "Revert "Ensuring constants are at root namespace inside Clear…
qrush authored
14 if user = ::User.find_by_email(params[:password][:email])
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
15 user.forgot_password!
1d2749c @qrush Adding in scope operator for ClearanceMailer since it causes problems…
qrush authored
16 ::ClearanceMailer.deliver_change_password user
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
17 flash_notice_after_create
1b494fa @croaky formatting standards for redirect_tos
croaky authored
18 redirect_to(url_after_create)
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
19 else
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
20 flash_failure_after_create
4ecad82 @jferris Namespaced the passwords controller
jferris authored
21 render :template => 'passwords/new'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
22 end
23 end
24
25 def edit
46f3617 splitting token/token_expires_at into confirmation_token, remember_to…
Daniel Croak authored
26 @user = ::User.find_by_id_and_confirmation_token(
27 params[:user_id], params[:token])
4ecad82 @jferris Namespaced the passwords controller
jferris authored
28 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
29 end
30
31 def update
46f3617 splitting token/token_expires_at into confirmation_token, remember_to…
Daniel Croak authored
32 @user = ::User.find_by_id_and_confirmation_token(
33 params[:user_id], params[:token])
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
34
324437f @croaky moved remember & forget methods off sessions controller and onto lib/…
croaky authored
35 if @user.update_password(params[:user][:password],
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
36 params[:user][:password_confirmation])
82a8407 @croaky removed unnecessary, untested conditional
croaky authored
37 @user.confirm_email!
4195760 @croaky deprecated sign_user_in. telling developers to use sign_in instead.
croaky authored
38 sign_in(@user)
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
39 flash_success_after_update
1b494fa @croaky formatting standards for redirect_tos
croaky authored
40 redirect_to(url_after_update)
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
41 else
4ecad82 @jferris Namespaced the passwords controller
jferris authored
42 render :template => 'passwords/edit'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
43 end
44 end
45
46 private
47
48 def forbid_missing_token
49 if params[:token].blank?
50 raise ActionController::Forbidden, "missing token"
51 end
52 end
53
c22d6d6 @qrush Correcting some spelling errors
qrush authored
54 def forbid_non_existent_user
46f3617 splitting token/token_expires_at into confirmation_token, remember_to…
Daniel Croak authored
55 unless ::User.find_by_id_and_confirmation_token(
56 params[:user_id], params[:token])
c22d6d6 @qrush Correcting some spelling errors
qrush authored
57 raise ActionController::Forbidden, "non-existent user"
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
58 end
59 end
60
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
61 def flash_notice_after_create
62 flash[:notice] = translate(:deliver_change_password,
63 :scope => [:clearance, :controllers, :passwords],
64 :default => "You will receive an email within the next few minutes. " <<
65 "It contains instructions for changing your password.")
66 end
67
68 def flash_failure_after_create
69 flash.now[:failure] = translate(:unknown_email,
70 :scope => [:clearance, :controllers, :passwords],
71 :default => "Unknown email.")
72 end
73
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
74 def url_after_create
8a3c128 @croaky use convenience paths (sign_up_path, sign_in_path, and sign_out_path)…
croaky authored
75 sign_in_url
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
76 end
77
b6eded5 @croaky [#16] flash_success_after_create, flash_notice_after_create, flash_fa…
croaky authored
78 def flash_success_after_update
79 flash[:success] = translate(:signed_in, :default => "Signed in.")
80 end
81
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
82 def url_after_update
f4df580 @croaky remove dependency on root_path, use '/' instead.
croaky authored
83 '/'
8c9deab @jferris Moved the passwords, sessions, and users controllers into app
jferris authored
84 end
85 end
Something went wrong with that request. Please try again.