Class: AccountsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/accounts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authorize, #current_account, #redirect, #set_current_account

Instance Method Details

#do_loginObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/accounts_controller.rb', line 14

def 
   = .find_by_email params[:email]
  if  && .authenticate(params[:password])
    session[:account_id] = .id
    

    if respond_to? :
      
    else
      redirect
    end
  else
    redirect_to :back, alert: 'Please check email and password.'
  end
end

#do_set_passwordObject



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

  .password = params[:password]
  .save

  if respond_to? :on_set_password
    on_set_password
  else
    redirect
  end
end

#do_signupObject



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 
   = .new
  .email = params[:email]
  .password = params[:password]
  (.attributes.keys - ['email', 'password_digest']).each do |attr|
    .send "#{attr}=", params[attr.to_sym]
  end

  if .save
    session[:account_id] = .id
    

    if respond_to? :
      
    else
      redirect
    end
  else
    redirect_to :back, alert: "Please check email and password."
  end
end

#loginObject



4
5
6
7
8
9
10
11
# File 'app/controllers/accounts_controller.rb', line 4

def 
  template = 'accounts/login'
  if lookup_context.exists? template
    render template
  else
    render 'accounts/default_login'
  end
end

#logoutObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/accounts_controller.rb', line 31

def logout
  session.delete :account_id
  

  if respond_to? :on_logout
    on_logout
  else
    redirect_to params[:redirect] || root_path
  end
end

#signupObject



43
44
45
46
47
48
49
50
# File 'app/controllers/accounts_controller.rb', line 43

def 
  template = 'accounts/signup'
  if lookup_context.exists? template
    render template
  else
    render 'accounts/default_signup'
  end
end