Sha256: 0f24e596e02a016b1d136365837abf68e1c6d17b4b7d99d0374a87b9378aa009

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

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

  def create
    login_attempts = (session[:login_attempts] || 0).next
    if !params[:email].blank? && user = 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 || admin_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 admin_session_path
  end

  def reset
    if user = 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 admin_session_path
    else
      flash[:error] = "There is no user account with that e-mail address!"
      redirect_to forgot_admin_session_path
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grandstand-0.2.4 app/controllers/admin/sessions_controller.rb
grandstand-0.2.3 app/controllers/admin/sessions_controller.rb
grandstand-0.2.2 app/controllers/admin/sessions_controller.rb
grandstand-0.2.1 app/controllers/admin/sessions_controller.rb