Sha256: d1cab60da9c4c4a2fba19926d4bebf5784de184ee25b5030bc4e9261454fbaa9

Contents?: true

Size: 845 Bytes

Versions: 20

Compression:

Stored size: 845 Bytes

Contents

class Admin::SessionsController < ApplicationController
  def new
    render
  end

  def create
    admin = Admin.find_by email: params[:email]
    auth_failed && return if admin.nil?
    auth_failed && return if not admin.authenticate params[:password]
    cookies.signed[:admin_id] = admin.id
    flash[:notice] = 'Successfully signed in.'
    respond_to do |f|
      f.json{ render json: {success: true} }
      f.html{ redirect_to admin_root_url }
    end
  end

  def destroy
    cookies.signed[:admin_id] = nil
    redirect_to new_admin_session_url, notice: 'Successfully signed out.'
  end

  private

    def auth_failed
      respond_to do |f|
        f.json{ render json: {errors: {base: ['Invalid email or password.']}} }
        f.html{ redirect_to new_admin_session_url, alert: 'Invalid email or password.' }
      end
    end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
loco-rails-3.0.5 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-3.0.4 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-3.0.3 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.5.3 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.5.2 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-3.0.2 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-3.0.1 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.5.1 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.5.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.4.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.3.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-3.0.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.2.2 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.2.1 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.2.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.1.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-2.0.0 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-1.5.2 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-1.5.1 test/dummy/app/controllers/admin/sessions_controller.rb
loco-rails-1.5.0 test/dummy/app/controllers/admin/sessions_controller.rb