Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. namespace Panel;
  3. use Nette\IDebugPanel;
  4.  
  5.  
  6. class UserPanel extends \Nette\Application\Control implements IDebugPanel
  7. {
  8.     /**
  9.      * @return Nette\Application\AppForm
  10.      */
  11.     public function createComponentLogInForm()
  12.     {
  13.         $form = new \Nette\Application\AppForm();
  14.  
  15.         $form->addText('username', 'Username:')
  16.             ->addRule(\Nette\Application\AppForm::FILLED, 'Please provide a username.');
  17.  
  18.         $form->addPassword('password', 'Password:')
  19.             ->addRule(\Nette\Application\AppForm::FILLED, 'Please provide a password.');
  20.  
  21.         $form->addSubmit('send', 'Log in');
  22.  
  23.         $form->onSubmit[] = callback($this, 'onLogInFormSubmitted');
  24.         return $form;
  25.     }
  26.  
  27.  
  28.  
  29.     public function onLogInFormSubmitted($form)
  30.     {
  31.         try {
  32.             $values = $form->getValues();
  33.             \Nette\Environment::getUser()->login($values['username'], $values['password']);
  34.         } catch (AuthenticationException $e) {
  35.             $form->addError($e->getMessage());
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement