Class: Goldencobra::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/goldencobra/sessions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for, #initialize_article, #s, #set_locale

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Goldencobra::ApplicationController

Instance Method Details

#loginObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/goldencobra/sessions_controller.rb', line 5

def 
  @errors = []
  if params[:usermodel] && params[:usermodel].constantize && params[:usermodel].constantize.present? && params[:usermodel].constantize.attribute_method?(:email)
    @usermodel = params[:usermodel].constantize.find_by_email(params[:loginmodel][:email])
    unless @usermodel && params[:usermodel].constantize.attribute_method?(:username)
      @usermodel = params[:usermodel].constantize.find_by_username(params[:loginmodel][:email])
    end
  end

  if @usermodel.present?
    if ::BCrypt::Password.new(@usermodel.encrypted_password) == "#{params[:loginmodel][:password]}#{Devise.pepper}"
       @usermodel
      @usermodel.failed_attempts = 0
      @usermodel. = @usermodel..to_i + 1
      @usermodel. = Time.now
      @usermodel.save
      @redirect_to = @usermodel.roles.try(:first).try(:redirect_after_login)
    else
      @usermodel.failed_attempts = @usermodel.failed_attempts.to_i + 1
      @usermodel.save
      @errors << "Wrong username or password"
    end
  else
    @errors << "No User found with this email"
  end
end

#logoutObject



33
34
35
36
37
38
39
# File 'app/controllers/goldencobra/sessions_controller.rb', line 33

def logout
  if params[:usermodel] && params[:usermodel].constantize && params[:usermodel].constantize.present? && params[:usermodel].constantize.attribute_method?(:email)
    sign_out
    reset_session
  end
  render :js => "window.location.href = '/';"
end

#registerObject



42
43
44
# File 'app/controllers/goldencobra/sessions_controller.rb', line 42

def register

end