Class: Caboose::LoginController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/login_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#before_action, #before_before_action, #logged_in?, #logged_in_user, #login_user, #reject_param, #user_is_allowed, #validate_token, #var

Instance Method Details

#indexObject

GET /login



6
7
8
9
10
# File 'app/controllers/caboose/login_controller.rb', line 6

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

#loginObject

POST /login



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/caboose/login_controller.rb', line 13

def 
  Caboose.log("PodioConfig.api_key = #{PodioConfig.api_key}")
  
  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]
    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
        (user)
        resp.redirect = return_url
      end
    end
  end
  render :json => resp
end