Sha256: 34c6beea6579d8d1110cc64a609c1a0ccbfa343bb289bc9e3625d0face6d64fe

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

class SessionsController < ApplicationController
  <% if oauth? %>
  include AuthsHelper
  <% end %>

  # Login
  def new
  end

  def create
    remember = params[:remember_me] == "1"

    if user && user.authenticate(params[:password])
      login(user, remember)
      respond_to do |format|
        format.json { head :no_content }
        format.html { redirect_back_or_default }
      end
    else
      respond_to do |format|
        format.json { render json: { errors: ["Invalid user name or password"], status: "error" }, status: 422 }
        format.html {
          flash.now[:error] = "Invalid user name or password"
          render :new
        }
      end
    end
  end

  # Logout
  def destroy
    logout
    respond_to do |format|
      format.json { head :no_content }
      format.html { redirect_to root_path }
    end
  end

  protected

  def user
    <% if username? %>
    username_or_email = "#{params[:email]}".downcase
    return if username_or_email.blank?
    @user = User.where('LOWER(username) = ? OR email = ?', username_or_email, username_or_email).first
    <% else %>
    email = "#{params[:email]}".downcase
    return if email.blank?
    @user = User.where('email = ?', email).first
    <% end %>
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authkit-0.7.0 lib/generators/authkit/templates/app/controllers/sessions_controller.rb
authkit-0.5.0 lib/generators/authkit/templates/app/controllers/sessions_controller.rb