1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/controllers/password_resets_controller.rb
Rob Zolkos 1cc9550c80 Lint files to rubocop omakase standards
root ➜ /workspace (fix-rubocop-issues) $ rubocop
Inspecting 54 files
......................................................

54 files inspected, no offenses detected
2024-02-02 16:07:29 +00:00

39 lines
943 B
Ruby

class PasswordResetsController < ApplicationController
layout "auth"
def new
end
def create
if (user = User.find_by(email: params[:email]))
PasswordMailer.with(
user: user,
token: user.generate_token_for(:password_reset)
).password_reset.deliver_later
end
redirect_to root_path, notice: "If an account with that email exists, we have sent a link to reset your password."
end
def edit
end
def update
if @user.update(password_params)
redirect_to new_session_path, notice: "Your password has been reset."
else
render :edit, status: :unprocessable_entity
end
end
private
def set_user_by_token
@user = User.find_by_token_for(password_reset: params[:token])
redirect_to new_password_reset_path, alert: "Invalid token." unless @user.present?
end
def password_params
params.require(:user).permit(:password, :password_confirmation)
end
end