sandbox/passwordrecovery

Password recovery Nette extension.

v2.0.1 2023-11-04 15:03 UTC

This package is auto-updated.

Last update: 2024-11-22 18:11:07 UTC


README

Requirements

Sandbox/PasswordRecovery requires PHP 8.1.0 or higher.

  • "nette/application": "^3.1",
  • "nette/bootstrap": "^3.2",
  • "nette/di": "^3.1",
  • "nette/forms": "^3.1",
  • "nette/mail": "^4.0",
  • "nette/robot-loader": "^4.0",
  • "nette/utils": "^4.0",
  • "latte/latte": "^3.0"

Installation

The best way to install Sandbox/PasswordRecovery is using Composer:

$ composer require sandbox/passwordrecovery

Configuration

Then you have to register extension in config.neon.

extensions:
    passwordRecovery: Sandbox\PasswordRecovery\DI\PasswordRecoveryExtension

and configuration section in config.neon:

passwordRecovery:
    passwordRecovery:
    sender: "sandbox@domain.net"
    subject: "Obnova hesla"
    submitButton: "Obnovit heslo"
    validatorMessage: "Prosím vložte validní heslo."
    equalPasswordMessage: "Hesla se musí shodovat."
    emptyPasswordMessage: "Heslo musí obsahovat alespoň %d znaků"
    minimalPasswordLength: 6
    expirationTime: 45 #minute, max 59
    errorMessage: "Odkaz pro obnovu hesla se nepodařilo odeslat. Zkuste to prosím znovu."
    mailer: @mail.mailer
    token: @Sandbox\PasswordRecovery\TokenManagerInterface

Next, you need to register a service that implements an interface UserRepositoryInterface and TokenManagerInterface. Example is sandbox project: https://github.com/ViPErCZ/sandbox

Usage

Sample using in Presenter:

/**
 * @return \Nette\Application\UI\Form
*/
protected function createComponentRecovery() {
	$control = $this->passwordRecovery->createDialog();
	$control->getResetForm()->onSuccess[] = function(Form $form) {
		$this->flashMessage('Odkaz pro obnovu hesla byl odeslán na Váš email ' . $form->getValues()['email'] . ".");
		$this->redrawControl('recoveryForm');
	};

	$control->getResetForm()->onError[] = function() {
		$this->redrawControl('recoveryForm');
	};

	$control->getNewPasswordForm()->onSuccess[] = function() {
		$this->flashMessage('Heslo bylo úspěšně nastaveno. Pokračujte na přihlašovací obrazovku.');
		if ($this->isAjax()) {
           $this->redrawControl('recoveryForm');
        } else {
           $this->redirect('Home:default');
        }
	};

	$control->getNewPasswordForm()->onError[] = function() {
		if ($this->isAjax()) {
           $this->redrawControl('recoveryForm');
        } else {
           $this->redirect('Home:default');
        }
	};

	return $control;
}

and template has default template (using twitter bootstrap class)

{snippet recoveryForm}
	<div n:foreach="$flashes as $flash" class="alert alert-success">{$flash->message}</div>
	{if count($flashes) == 0}
		{control recovery}
	{/if}
{/snippet}

If you want to use your custom template, set the variable templatePath to the path to the latte template.

Extension using Nette\Localization\Translator and all configurated strings are translated.

Homepage https://packagist.org/packages/vipercz/sandbox and repository https://github.com/ViPErCZ/passwordRecovery.