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
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 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
@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
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
|
#register ⇒ Object
42
43
44
|
# File 'app/controllers/goldencobra/sessions_controller.rb', line 42
def register
end
|