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
5 6 7 8 |
# File 'app/controllers/caboose/login_controller.rb', line 5 def index @return_url = params[:return_url].nil? ? "/" : params[:return_url]; redirect_to @return_url if logged_in? end |
#login ⇒ Object
POST /login
11 12 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 |
# File 'app/controllers/caboose/login_controller.rb', line 11 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 |