Class: Grandstand::SessionsController

Inherits:
MainController
  • Object
show all
Defined in:
app/controllers/grandstand/sessions_controller.rb

Instance Method Summary collapse

Methods inherited from MainController

#expand

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/grandstand/sessions_controller.rb', line 7

def create
   = (session[:login_attempts] || 0).next
  if !params[:email].blank? && user = Grandstand::User.authenticates_with(:email => params[:email])
    if user.authenticates_with?(params[:password])
      saved_return_path = return_path
      reset_session
      session[:user_id] = user.id
      redirect_to saved_return_path || grandstand_root_path
      return
    else
      flash.now[:error] = 'The password you entered is incorrect. Please try again.'
    end
  else
    flash.now[:error] = 'An account with that e-mail could not be found. Please try again.'
  end
  session[:login_attempts] = 
  render :show
end

#destroyObject



26
27
28
29
# File 'app/controllers/grandstand/sessions_controller.rb', line 26

def destroy
  reset_session
  redirect_to grandstand_session_path
end

#resetObject



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

def reset
  if user = Grandstand::User.where(:email => params[:email]).first
    user.reset_password
    flash[:notice] = "A link containing password reset instructions has been sent to #{user.email}"
    redirect_to grandstand_session_path
  else
    flash[:error] = "There is no user account with that e-mail address!"
    redirect_to forgot_grandstand_session_path
  end
end