Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Panel;
- use Nette\IDebugPanel;
- class UserPanel extends \Nette\Application\Control implements IDebugPanel
- {
- /**
- * @return Nette\Application\AppForm
- */
- public function createComponentLogInForm()
- {
- $form = new \Nette\Application\AppForm();
- $form->addText('username', 'Username:')
- ->addRule(\Nette\Application\AppForm::FILLED, 'Please provide a username.');
- $form->addPassword('password', 'Password:')
- ->addRule(\Nette\Application\AppForm::FILLED, 'Please provide a password.');
- $form->addSubmit('send', 'Log in');
- $form->onSubmit[] = callback($this, 'onLogInFormSubmitted');
- return $form;
- }
- public function onLogInFormSubmitted($form)
- {
- try {
- $values = $form->getValues();
- \Nette\Environment::getUser()->login($values['username'], $values['password']);
- } catch (AuthenticationException $e) {
- $form->addError($e->getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement