#Password recovery extension for Nette Framework
Requirements
Sandbox/PasswordRecovery requires PHP 8.1.0 or higher., (*1)
- "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:, (*2)
$ composer require sandbox/passwordrecovery
Configuration
Then you have to register extension in config.neon., (*3)
extensions:
passwordRecovery: Sandbox\PasswordRecovery\DI\PasswordRecoveryExtension
and configuration section in config.neon:, (*4)
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, (*5)
Usage
Sample using in Presenter:, (*6)
/**
* @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), (*7)
{snippet recoveryForm}
{$flash->message}
{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., (*8)
Extension using Nette\Localization\Translator and all configurated strings are translated., (*9)
Homepage https://packagist.org/packages/vipercz/sandbox and repository https://github.com/ViPErCZ/passwordRecovery., (*10)