Sha256: 8a1af3b81ac823393a5bf59e442e0fc9ef28b1eaed625d11dfc7141e2556a95f

Contents?: true

Size: 1.12 KB

Versions: 23

Compression:

Stored size: 1.12 KB

Contents

module Caboose
  class LoginController < Caboose::ApplicationController
    
    # GET /login
    def index
      @return_url = params[:return_url].nil? ? "/" : params[:return_url];
      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.error = "Already logged in"
      else
        @username = params[:username]
        @password = params[:password]
                           
        if (@username.nil? || @password.nil? || @password.strip.length == 0)
          @resp.error = "Invalid credentials"
        else
          
          @password = Digest::SHA1.hexdigest(Caboose::salt + @password)
          user = User.where(:username => @username, :password => @password).first
          
          if (user.nil?)
            @resp.error = "Invalid credentials"
          else
            login_user(user)
            @resp.redirect = @return_url
          end
        end
      end
      render json: @resp
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
caboose-cms-0.1.101 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.98 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.97 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.96 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.93 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.92 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.91 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.78 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.35 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.34 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.7 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.6 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.5 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.4 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.3 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.2 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.1 app/controllers/caboose/login_controller.rb
caboose-cms-0.1.0 app/controllers/caboose/login_controller.rb
caboose-cms-0.0.7 app/controllers/caboose/login_controller.rb
caboose-cms-0.0.5 app/controllers/caboose/login_controller.rb