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.32 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.31 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.30 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.29 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.28 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.27 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.26 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.25 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.24 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.23 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.22 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.20 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.19 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.17 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.16 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.15 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.14 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.13 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.12 app/controllers/caboose/login_controller.rb
caboose-cms-0.3.11 app/controllers/caboose/login_controller.rb