1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/controllers/password_resets_controller.rb
Zach Gollwitzer f2739b79fb
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions
Improve password reset flow, normalize translations
2024-11-05 17:15:29 -05:00

44 lines
1,006 B
Ruby

class PasswordResetsController < ApplicationController
skip_authentication
layout "auth"
before_action :set_user_by_token, only: %i[edit update]
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 new_password_reset_path(step: "pending")
end
def edit
@user = User.new
end
def update
if @user.update(password_params)
redirect_to new_session_path, notice: t(".success")
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: t("password_resets.update.invalid_token") unless @user.present?
end
def password_params
params.require(:user).permit(:password, :password_confirmation)
end
end