Class: Goldencobra::SessionsController
Instance Method Summary
collapse
#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
#login ⇒ Object
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 login
@errors = []
if usermodel
@usermodel = usermodel.where(email: params[:loginmodel][:email]).first
if @usermodel.blank? && usermodel.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}"
sign_in @usermodel
@usermodel.failed_attempts = 0
@usermodel.sign_in_count = @usermodel.sign_in_count.to_i + 1
@usermodel.last_sign_in_at = 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
|
#logout ⇒ Object
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
|
#register ⇒ Object
52
53
|
# File 'app/controllers/goldencobra/sessions_controller.rb', line 52
def register
end
|