Advertisement
Guest User

Untitled

a guest
Oct 17th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2.  
  3. namespace FrontModule;
  4.  
  5. use Nette\Application\UI,
  6.     Nette\Application\UI\Form as Form;
  7.  
  8. class RegisterPresenter extends BasePresenter {
  9.  
  10.     /** @var Users */
  11.     private $users;
  12.  
  13.     protected function startup() {
  14.         parent::startup();
  15.         $this->users = $this->context->usersRepository;
  16.     }
  17.  
  18.     public function renderRegister() {
  19.  
  20.     }
  21.  
  22.     protected function createComponentRegisterForm() {
  23.         $form = new Form;
  24.         $form->addText('username', 'Username: *')
  25.             ->addRule(Form::FILLED, 'Please enter username.');
  26.         $form->addPassword('password', 'Password: *', 20)
  27.             ->setOption('description', 'Min 6 characters')
  28.             ->addRule(Form::FILLED, 'Please enter password.')
  29.             ->addRule(Form::MIN_LENGTH, 'The Password must be min %d characters long.', 6);
  30.         $form->addPassword('password2', 'Password again: *', 20)
  31.             ->addConditionOn($form['password'], Form::VALID)
  32.             ->addRule(Form::FILLED, 'Password again please.')
  33.             ->addRule(Form::EQUAL, 'Passwords must match.', $form['password']);
  34.         $form->addText('email', 'E-mail: *', 35)
  35.             ->setEmptyValue('@')
  36.             ->addRule(Form::FILLED, 'Please enter your e-mail.')
  37.             ->addCondition(Form::FILLED)
  38.             ->addRule(Form::EMAIL, 'Invalid E-mail address!');
  39.         $form->addSubmit('register', 'Register');
  40.         $form->onSuccess[] = callback($this, 'registerFormSubmitted');
  41.         return $form;          
  42.     }
  43.  
  44.     public function registerFormSubmitted(UI\Form $form) {
  45.         $values = $form->getValues();
  46.         $new_user = $this->users->register($values);
  47.         if ($new_user) {
  48.             $this->flashMessage('You were successfully registered.');
  49.             $this->redirect('Sign:in');
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement