Class: ResetPasswordsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/dangerzone/templates/controllers/reset_passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#newObject



37
38
# File 'lib/dangerzone/templates/controllers/reset_passwords_controller.rb', line 37

def new
end

#requested_reset_passwordObject



3
4
5
6
7
8
9
10
11
# File 'lib/dangerzone/templates/controllers/reset_passwords_controller.rb', line 3

def requested_reset_password
  @user = User.find_by_email(params[:email].try(:downcase))
  if @user.try(:update_reset_password_credentials)
    DangerzoneMailer.reset_password_email(@user).deliver
    redirect_to :forgot_password, notice: "Reset password email successfully sent."
  else
    redirect_to :forgot_password, notice: "Reset password email failed to send."
  end
end

#reset_password_formObject



13
14
15
16
17
18
# File 'lib/dangerzone/templates/controllers/reset_passwords_controller.rb', line 13

def reset_password_form
  @user = User.find_by_id(params[:id])
  unless @user.try(:in_time?) && @user.token_matches?(params[:reset_password_token])
    redirect_to :forgot_password, notice: "There was a problem, try having the email resent to you."
  end
end

#update_passwordObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dangerzone/templates/controllers/reset_passwords_controller.rb', line 20

def update_password
  @user = User.find_by_id(params[:id])
  if @user.try(:in_time?)
    @user.password = params[:password]
    @user.password_confirmation = params[:password_confirmation]
    if @user.save
      reset_session
      session[:user_id] = @user.id
      redirect_to :root, notice: "Password successfully updated."
    else
      redirect_to reset_password_form_path(@user.id, @user.reset_password_token), notice: "Update password unsuccessful: password confirmation did not match password."
    end
  else
    redirect_to :forgot_password, notice: "Update password unsuccessful."
  end
end