Class: Usman::SessionsController

Inherits:
Kuppayam::BaseController
  • Object
show all
Includes:
AuthenticationHelper
Defined in:
app/controllers/usman/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_sessionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/usman/sessions_controller.rb', line 19

def create_session
  set_title("Sign In")
  registration_params = { login_handle: params[:login_handle], password: params[:password], remote_ip: request.remote_ip}
  @registration_details = Usman::AuthenticationService.new(registration_params)

  if @registration_details.error
    
    text = "#{I18n.t("#{@registration_details.error}.heading")}: #{I18n.t("#{@registration_details.error}.message")}"
    set_flash_message(text, :error, false) if defined?(flash) && flash

    
    return
  else
    @user = @registration_details.user
    session[:id] = @user.id
    @current_user = @user
    
    text = "#{I18n.t("authentication.logged_in.heading")}: #{I18n.t("authentication.logged_in.message")}"
    set_flash_message(text, :success, false) if defined?(flash) && flash

    
    return
  end
end

#forgot_passwordObject



57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/usman/sessions_controller.rb', line 57

def forgot_password
  @user = User.find_by_email(params[:email])
  if @user.present?
    @user.generate_reset_password_token
    @user.save
    UsersMailer.forgot_password(@user).deliver
  else
  end
  flash[:notice] = "A password reset link will be send to your email if the records matches."
  redirect_to root_path
end

#forgot_password_formObject



54
55
# File 'app/controllers/usman/sessions_controller.rb', line 54

def forgot_password_form
end

#reset_password_formObject



69
70
71
# File 'app/controllers/usman/sessions_controller.rb', line 69

def reset_password_form
  @user = User.find(params[:id])
end

#reset_password_updateObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/usman/sessions_controller.rb', line 73

def reset_password_update
  @user = User.find(params[:id])
  if @user.reset_password_token == user_params[:reset_password_token] && @user.update(user_params)
    @user.reset_password_token = nil
    @user.save
    flash[:success] = "Password updated successfully"
    redirect_to root_path
  else
    flash[:error] = "Unable to update password please try again later"
    render "reset_password_form"
  end
end

#sign_inObject



14
15
16
17
# File 'app/controllers/usman/sessions_controller.rb', line 14

def 
  set_title("Sign In")
   if @current_user
end

#sign_outObject



44
45
46
47
48
49
50
51
52
# File 'app/controllers/usman/sessions_controller.rb', line 44

def sign_out
  text = "#{I18n.t("authentication.logged_out.heading")}: #{I18n.t("authentication.logged_out.message")}"
  set_flash_message(text, :success, false) if defined?(flash) && flash

  @current_user.end_session
  session.delete(:id)
  restore_last_user
  redirect_after_unsuccessful_authentication
end