Class: PasswordResetsController

Inherits:
ApplicationController show all
Defined in:
lib/generators/jinda/templates/app/controllers/jinda_org/password_resets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#prepare_meta_tags

Instance Method Details

#createObject



12
13
14
15
16
17
18
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/password_resets_controller.rb', line 12

def create
  # user = User.find_by_email(params[:email])
  user = User.where(email: params[:email]).first

  user&.send_password_reset
  redirect_to root_url, ma_notice: 'Email sent with password reset instructions.'
end

#editObject



6
7
8
9
10
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/password_resets_controller.rb', line 6

def edit
  ## Deprecated syntax in rail 5
  # #@user = User.find_by_password_reset_token!(params[:id])
  @user = User.where(password_reset_token: params[:id]).first
end

#indexObject



4
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/password_resets_controller.rb', line 4

def index; end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/jinda/templates/app/controllers/jinda_org/password_resets_controller.rb', line 20

def update
  # #@user = User.find_by_password_reset_token!(params[:id])
  @user = User.where(password_reset_token: params[:id]).first
  if @user.password_reset_sent_at < 2.hours.ago
    redirect_to new_password_reset_path, alert: "Password &crarr;
    reset has expired."
  elsif @user.update(params[:user])
    redirect_to root_url, notice: 'Password has been reset.'
  else
    render :edit
  end
end