Class: Goldencobra::SessionsController
Instance Method Summary
collapse
#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
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
|
# File 'app/controllers/goldencobra/sessions_controller.rb', line 8
def login
@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}"
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
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/goldencobra/sessions_controller.rb', line 37
def logout
if params[:usermodel] && params[:usermodel].constantize && params[:usermodel].constantize.present? && params[:usermodel].constantize.attribute_method?(:email)
sign_out
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
51
52
53
|
# File 'app/controllers/goldencobra/sessions_controller.rb', line 51
def register
end
|