Sha256: 5c38851f494bfc0975fe8752449a65f038f43b71cc28aa014a7e4a81d8ffebda

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

class Grandstand::SessionsController < Grandstand::MainController
  before_filter :require_no_user, :except => [:destroy]
  skip_before_filter :require_user, :except => [:destroy]
  skip_before_filter :set_return_path
  layout 'grandstand_login'

  def create
    login_attempts = (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] = login_attempts
    render :show
  end

  def destroy
    reset_session
    redirect_to grandstand_session_path
  end

  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grandstand-0.2.7 app/controllers/grandstand/sessions_controller.rb
grandstand-0.2.6 app/controllers/grandstand/sessions_controller.rb