Sha256: 8eb520bd9538de3f811a8fce677ce2bc014d9572626b74662522c4e8bce5274a

Contents?: true

Size: 821 Bytes

Versions: 2

Compression:

Stored size: 821 Bytes

Contents

# encoding: utf-8

class SessionsController < ::ApplicationController
  def create
    user = find_user(params[:username], params[:password])
    authenticate!(user) if user

    if logged_in?
      redirect_to success_url
    else
      flash[:notice] = "The provided email address and password combination " \
        "was not valid"
      redirect_to login_url
    end
  end

  def destroy
    flash[:notice] = "You have been logged out"
    deauthenticate!
    redirect_to login_url
  end

  protected

  def find_user(username, password)
    User.authenticate(username, password: password) if username && password
  end

  def success_url
    # TODO: Validate URL
    params[:success_url] || admin_default_url
  end

  def login_url
    # TODO: Validate URL
    params[:login_url] || login_admin_users_url
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pages_core-3.4.3 app/controllers/sessions_controller.rb
pages_core-3.5.1 app/controllers/sessions_controller.rb