Class: AuthenticationController
Constant Summary
collapse
- MSG_INVALID_EMAIL =
"Invalid e-mail address. Let's try it again?"
- MSG_UNKNOWN_BUTTON =
'An unknown error occurred while processing your request. How very odd...'
- MSG_MISMATCHED_PASSWORD =
"Your passwords don't match. Try re-entering your password again, and make sure that both fields contain the same password."
- MSG_UNRECOGNIZED_EMAIL =
"Oh dear, there's no record of this e-mail address in our database. Perhaps you mispelled this page's address?"
- MSG_BAD_TOKEN =
'Invalid reset token. Perhaps you're having this problem because you arrived here by clicking the link on an outdated e-mail?'
- MSG_RESET_SUCCESS =
'Password Successfully Reset. Please use your new password to Login.'
Instance Method Summary
collapse
#controller_id, #define_application_layout_variables, #h_money, #money_for_input
#validate_credentials
Instance Method Details
#index ⇒ Object
16
17
18
|
# File 'app/controllers/authentication_controller.rb', line 16
def index
redirect_to login_url
end
|
#login ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/authentication_controller.rb', line 20
def login
respond_to do |format|
format.html do
define_application_layout_variables
@page_title = 'Sign-in'
if @active_credential
redirect_to @active_credential.default_post_login_url_to
else
render :action => :login
end
end
format.js do
begin
@flash_error = nil
@button_press = 'sign_in_error'
@button_press = params[:commit][0] if /^(login|email)$/.match(params[:commit][0])
case @button_press
when 'login'
@active_credential = Credential.find_using_auth params[:email_address], params[:password]
if @active_credential
session[:credential_id] = @active_credential.id
@redirect_to = session[:uncredentialed_request_uri]
session[:uncredentialed_request_uri] = nil
end
when 'email'
credential = Credential.find_by_email params[:email_address]
if credential
reset_token = credential.generate_reset_token!
credential_name = (credential.user and credential.user.respond_to? :name) ?
credential.user.name :
credential.email_address
mail = Notifier.deliver_reset_password_requested(
credential_name,
credential.email_address,
reset_token,
request_full_host
)
else
raise StandardError, MSG_INVALID_EMAIL
end
else
raise StandardError, MSG_UNKNOWN_BUTTON
end
rescue
@flash_error = $!
ensure
render :action => @button_press
end
end
end
end
|
#logout ⇒ Object
81
82
83
84
|
# File 'app/controllers/authentication_controller.rb', line 81
def logout
session[:credential_id] = nil
redirect_to login_url
end
|
#reset_password_via_token ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'app/controllers/authentication_controller.rb', line 86
def reset_password_via_token
@email_address = params[:email_address][0]
@token = params[:token]
respond_to do |format|
format.html do
define_application_layout_variables
@page_title = 'Reset Password'
render :action => :reset_password_via_token
end
format.js do
begin
raise StandardError, MSG_MISMATCHED_PASSWORD if params[:password_verify] != params[:password]
active_credential = Credential.find_by_email params[:email_address]
raise StandardError, MSG_UNRECOGNIZED_EMAIL unless active_credential
raise StandardError, MSG_BAD_TOKEN unless active_credential.reset_password_by_token!(params[:token], params[:password])
flash[:notice] = MSG_RESET_SUCCESS
rescue
@flash_error = $!
ensure
render :action => :reset_password_via_token
end
end
end
end
|