Class: Goldencobra::SessionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#access_denied, #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



7
8
9
10
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
# File 'app/controllers/goldencobra/sessions_controller.rb', line 7

def 
  @errors = []
  if usermodel
    # search for user/visitor per email address
    @usermodel = usermodel.where(email: params[:loginmodel][:email]).first
    if @usermodel.blank? && usermodel.attribute_method?(:username)
      # if not found, search for visitor per email address
      # only visitor has attribute_method "username"
      @usermodel = usermodel.where(username: params[:loginmodel][:email]).first
    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
      flash[:notice] = I18n.translate("signed_in", scope: ["devise", "sessions"])
      @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



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/goldencobra/sessions_controller.rb', line 39

def logout
  if usermodel
    sign_out usermodel.to_s.downcase.to_sym
    reset_session
    flash[:notice] = I18n.translate("signed_out", scope: ["devise", "sessions"])
  end
  if request.format == "html"
    redirect_to "/"
  else
    render js: "window.location.href = '/';"
  end
end

#registerObject



52
53
# File 'app/controllers/goldencobra/sessions_controller.rb', line 52

def register
end