Class: Lines::PasswordResetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lines/password_resets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/lines/password_resets_controller.rb', line 14

def create
  @user = User.find_by(email: params[:password_reset][:email].downcase)
  if @user
    @user.create_reset_digest
    @user.send_password_reset_email
    flash[:info] = "Email sent with password reset instructions"
    redirect_to root_url
  else
    flash.now[:error] = "Email address not found"
    render 'new'
  end
end

#editObject



27
28
# File 'app/controllers/lines/password_resets_controller.rb', line 27

def edit
end

#newObject



11
12
# File 'app/controllers/lines/password_resets_controller.rb', line 11

def new
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/lines/password_resets_controller.rb', line 30

def update
  if password_blank?
    flash.now[:error] = "Password can't be blank"
    render 'edit'
  elsif wrong_password_confirmation?
    flash.now[:error] = "Password confirmation does not match"
    render 'edit'
  elsif @user.update_attributes(user_params)
    # deletr reset_digest and reset_sent_at
    @user.update_attributes(reset_digest: nil, reset_sent_at: nil)        
    flash[:success] = "Password has been reset. You can now log in with your new password."
    redirect_to new_session_path
  else
    render 'edit'
  end
end