Class: Caboose::LoginController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::LoginController
- Defined in:
- app/controllers/caboose/login_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
GET /login.
-
#login ⇒ Object
POST /login.
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
#index ⇒ Object
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 |
#login ⇒ Object
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 |
# File 'app/controllers/caboose/login_controller.rb', line 13 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] 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 login_user(user) resp.redirect = return_url end end end render :json => resp end |