Class: Usman::SessionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_default_title

Instance Method Details

#create_sessionObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/usman/sessions_controller.rb', line 14

def create_session
  set_title("Sign In")
  @registration_details = Usman::AuthenticationService.new(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



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/usman/sessions_controller.rb', line 51

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



48
49
# File 'app/controllers/usman/sessions_controller.rb', line 48

def forgot_password_form
end

#reset_password_formObject



63
64
65
# File 'app/controllers/usman/sessions_controller.rb', line 63

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

#reset_password_updateObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/usman/sessions_controller.rb', line 67

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



9
10
11
12
# File 'app/controllers/usman/sessions_controller.rb', line 9

def 
  set_title("Sign In")
   if @current_user && !@current_user.token_expired?
end

#sign_outObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/usman/sessions_controller.rb', line 38

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