forked from External/greenlight
GRN2-180: First stages of refactoring code for v2.4 (#748)
* Email rescues and authenticator concern * Application controller and helper clean up * Moved controller code out of helpers * More helper and email clean up * Cleaned up remaining helpers and create omniauth_options * Controller code clean up * restructured views structure * Restructured role code * Restructured profile and code clean up * Master merge * Added bbb server concern to deal with bbb calls * Bug fixes and changes after changes * rspec * More rubocop fixes
This commit is contained in:
@ -20,45 +20,47 @@ class PasswordResetsController < ApplicationController
|
||||
include Emailer
|
||||
|
||||
before_action :disable_password_reset, unless: -> { Rails.configuration.enable_email_verification }
|
||||
before_action :find_user, only: [:edit, :update]
|
||||
before_action :find_user, only: [:edit, :update]
|
||||
before_action :valid_user, only: [:edit, :update]
|
||||
before_action :check_expiration, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
# POST /password_resets/new
|
||||
def new
|
||||
end
|
||||
|
||||
# POST /password_resets
|
||||
def create
|
||||
@user = User.find_by(email: params[:password_reset][:email].downcase)
|
||||
if @user
|
||||
begin
|
||||
# Check if user exists and throw an error if he doesn't
|
||||
@user = User.find_by!(email: params[:password_reset][:email].downcase)
|
||||
|
||||
@user.create_reset_digest
|
||||
send_password_reset_email(@user)
|
||||
flash[:success] = I18n.t("email_sent", email_type: t("reset_password.subtitle"))
|
||||
redirect_to root_path
|
||||
else
|
||||
flash[:alert] = I18n.t("no_user_email_exists")
|
||||
redirect_to new_password_reset_path
|
||||
rescue
|
||||
# User doesn't exist
|
||||
redirect_to new_password_reset_path, flash: { alert: I18n.t("no_user_email_exists") }
|
||||
end
|
||||
rescue => e
|
||||
logger.error "Support: Error in email delivery: #{e}"
|
||||
redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("delivery_error"))
|
||||
end
|
||||
|
||||
# GET /password_resets/:id/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# PATCH /password_resets/:id
|
||||
def update
|
||||
# Check if password is valid
|
||||
if params[:user][:password].empty?
|
||||
flash.now[:alert] = I18n.t("password_empty_notice")
|
||||
render 'edit'
|
||||
elsif params[:user][:password] != params[:user][:password_confirmation]
|
||||
# Password does not match password confirmation
|
||||
flash.now[:alert] = I18n.t("password_different_notice")
|
||||
render 'edit'
|
||||
elsif @user.update_attributes(user_params)
|
||||
flash[:success] = I18n.t("password_reset_success")
|
||||
redirect_to root_path
|
||||
else
|
||||
render 'edit'
|
||||
# Successfully reset password
|
||||
return redirect_to root_path, flash: { success: I18n.t("password_reset_success") }
|
||||
end
|
||||
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
private
|
||||
@ -84,6 +86,7 @@ class PasswordResetsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# Redirects to 404 if emails are not enabled
|
||||
def disable_password_reset
|
||||
redirect_to '/404'
|
||||
end
|
||||
|
Reference in New Issue
Block a user