Sha256: 869a5ade0053684dcbb7e87cb0daf1e5f152f94808f7a96e9aee2dcd7b21e10c

Contents?: true

Size: 926 Bytes

Versions: 4

Compression:

Stored size: 926 Bytes

Contents

module Exposition
  class Admin::SessionsController < Admin::AdminController
    skip_before_action :authorize, only: [:new, :create]

    def new
    end

    def create
      permitted = params.require(:session).permit([:email, :password])
      user = User.find_by(email: permitted[:email].downcase)
      if user && user.authenticate(permitted[:password])
        # Log the user in and redirect to the user's show page.

        user.set_encrypted_remember_token!
        session[:user_id] = user.id
        cookies.permanent.signed[:user_id] = user.id
        cookies.permanent[:remember_token] = user.remember_token
        redirect_to admin_posts_path
      else
        flash.now[:error] = t("sessions.failed_login")
        render 'new'
      end
    end

    def destroy
      session.delete(:user_id)
      cookies.delete(:user_id)
      cookies.delete(:remember_token)
      redirect_to root_url
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
exposition-0.0.5.7.pre.alpha app/controllers/exposition/admin/sessions_controller.rb
exposition-0.0.5.6.pre.alpha app/controllers/exposition/admin/sessions_controller.rb
exposition-0.0.5.5.pre.alpha app/controllers/exposition/admin/sessions_controller.rb
exposition-0.0.5.4.pre.alpha app/controllers/exposition/admin/sessions_controller.rb