Class: AccountsController
Instance Method Summary
collapse
#authorize, #current_account, #redirect, #set_current_account
Instance Method Details
#do_login ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/accounts_controller.rb', line 14
def do_login
account = Account.find_by_email params[:email]
if account && account.authenticate(params[:password])
session[:account_id] = account.id
set_current_account
if respond_to? :on_login
on_login
else
redirect
end
else
redirect_to :back, alert: 'Please check email and password.'
end
end
|
#do_set_password ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/accounts_controller.rb', line 76
def do_set_password
unless params[:password] == params[:password_confirmation]
return redirect_to :back, alert: 'Passwords do not match.'
end
current_account.password = params[:password]
current_account.save
if respond_to? :on_set_password
on_set_password
else
redirect
end
end
|
#do_signup ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/accounts_controller.rb', line 53
def do_signup
account = Account.new
account.email = params[:email]
account.password = params[:password]
(account.attributes.keys - ['email', 'password_digest']).each do |attr|
account.send "#{attr}=", params[attr.to_sym]
end
if account.save
session[:account_id] = account.id
set_current_account
if respond_to? :on_signup
on_signup
else
redirect
end
else
redirect_to :back, alert: "Please check email and password."
end
end
|
#login ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'app/controllers/accounts_controller.rb', line 4
def login
template = 'accounts/login'
if lookup_context.exists? template
render template
else
render 'accounts/default_login'
end
end
|
#logout ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/accounts_controller.rb', line 31
def logout
session.delete :account_id
set_current_account
if respond_to? :on_logout
on_logout
else
redirect_to params[:redirect] || root_path
end
end
|
#signup ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'app/controllers/accounts_controller.rb', line 43
def signup
template = 'accounts/signup'
if lookup_context.exists? template
render template
else
render 'accounts/default_signup'
end
end
|