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



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

#loginObject

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 
  
  @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
        (user)
        @resp.redirect = @return_url
      end
    end
  end
  render json: @resp
end