ToolJet/app/controllers/forgot_password_controller.rb
Deepti Kakade b10d777f63
Fixes Rubocop issues in tests (#359)
* Updated project set up guide for Mac, added node version and Webpack install steps.

* Worked on PR comment i.e Can we change this line to Install Node.js ( version: v14.9.0 )

* Fixed "Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping."

* Resolved rubocop comments i.e "Style/FrozenStringLiteralComment: Missing frozen string literal comment." in test folder

Co-authored-by: Deepti Kakade <deepti@saeloun.com>
Co-authored-by: Deepti Kakade <“deepti@saeloun.com”>
2021-07-01 12:54:35 +05:30

28 lines
970 B
Ruby

# frozen_string_literal: true
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