mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-18 14:38:32 +00:00
* Add forgot password feature * Make the requested changes Co-authored-by: “Apoorv <“tiwari.apoorv1316@gmail.com”>
26 lines
929 B
Ruby
26 lines
929 B
Ruby
class ForgotPasswordController < ApplicationController
|
|
skip_before_action :authenticate_request
|
|
|
|
def forgot
|
|
user = User.find_by(email: params[:_json])
|
|
if user.present?
|
|
user.send_password_reset
|
|
render json: {message: "We've sent the confirmation code to your email address"}, status: :ok
|
|
else
|
|
render json: {error: 'Email address is not associated with a ToolJet cloud account.'}, status: :not_found
|
|
end
|
|
end
|
|
|
|
def reset
|
|
user = User.find_by(forgot_password_token: params[:token])
|
|
if user.present? && user.forgot_password_token_valid?
|
|
if user.reset_password(params[:password])
|
|
render json: {message: 'Your password has been successfuly reset!'}, status: :ok
|
|
else
|
|
render json: {error: user.errors.full_messages}, status: :unprocessable_entity
|
|
end
|
|
else
|
|
render json: {error: 'Link not valid or expired.'}, status: :not_found
|
|
end
|
|
end
|
|
end
|