module Admin class PasswordsController < Admin::BaseController def edit end def update unless current_admin_account.authenticate(params[:current_password]) flash.now[:alert] = t("admin.flash.password_current_incorrect") return render :edit, status: :unprocessable_entity end if params[:password] != params[:password_confirmation] flash.now[:alert] = t("admin.flash.password_mismatch") return render :edit, status: :unprocessable_entity end if (code = PasswordComplexity.violation(params[:password])) key = case code when :blank, :too_short then :password_too_short when :too_long then :password_too_long else :password_too_weak end flash.now[:alert] = t("admin.flash.#{key}") return render :edit, status: :unprocessable_entity end if current_admin_account.update(password: params[:password]) redirect_to admin_root_path, notice: t("admin.flash.password_updated") else flash.now[:alert] = current_admin_account.errors.full_messages.to_sentence render :edit, status: :unprocessable_entity end end end end