Sha256: ce88d3f8fb41f8d4651876032bb67adb697035eef1fbf52572ce6dcf14f20864

Contents?: true

Size: 1.32 KB

Versions: 39

Compression:

Stored size: 1.32 KB

Contents

module Caboose
  class LoginController < Caboose::ApplicationController
    layout 'caboose/modal'
    
    # GET /login
    def index
      @return_url = params[:return_url].nil? ? "/" : params[:return_url]
      @modal = params[:modal].nil? ? false : params[:modal]
      redirect_to @return_url if logged_in?
    end
    
    # POST /login
    def login
      resp = StdClass.new('error' => '', 'redirect' => '')
      return_url = params[:return_url].nil? ? "/" : params[:return_url]
      
      if (logged_in?)
        resp.redirect = return_url
      else
        username = params[:username].downcase
        password = params[:password]
                           
        if (username.nil? || password.nil? || password.strip.length == 0)
          resp.error = "Invalid credentials"
        else
          
          bouncer_class = Caboose::authenticator_class.constantize
          bouncer = bouncer_class.new
          user = bouncer.authenticate(username, password)
          
          if (user.nil? || user == false)
            resp.error = "Invalid credentials"
          else
            remember = params[:remember] && (params[:remember] == 1 || params[:remember] == "1")
            login_user(user, remember)
            resp.redirect = return_url
          end
        end
      end
      render :json => resp
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
caboose-cms-0.3.9 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.8 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.7 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.6 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.5 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.4 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.3 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.2 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.1 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.104 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.103 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.102 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.100 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.99 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.98 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.97 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.96 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.95 app/controllers/caboose/login_controller.rb
caboose-cms-0.2.94 app/controllers/caboose/login_controller.rb