HosipLan

Untitled

Apr 26th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.      * @param array $values
  3.      * @final
  4.      * @throws DibiDriverException
  5.      */
  6.     final public function registration($values)
  7.     {
  8.        
  9.         unset($values['passwordAgain']);
  10.         unset($values['agree']);
  11.  
  12.         $values['hash'] = $this->genHash(32,15);
  13.         $values['registered'] = new DateTime;
  14.  
  15.         try {
  16.             return (bool)$this->db->insert(self::usersTable, $values)->execute();
  17.         } catch(DibiDriverException $e) {
  18.         if ($e === \DibiMySqlDriver::ERROR_DUPLICATE_ENTRY) {
  19.                 throw new MyApp\NonUniqueRowException($e->getMessage(), 0, $e);
  20.         } else {
  21.         throw new MyApp\SqlException($e->getMessage(), 0, $e)
  22.             }
  23.         }
  24.     }
  25.  
  26.  
  27. ##########################
  28.  
  29.  
  30.  
  31.     /**
  32.      * @param string $name
  33.      */
  34.     protected function createComponentRegistration($name)
  35.     {
  36.         $form = new UsersRegistrationForm($this,$name);
  37.         $form->onSuccess[] = array($this, 'registrationSubmited');
  38.     }
  39.    
  40.      /**
  41.      * @param Form $form
  42.      */
  43.     public function registrationSubmited($form)
  44.     {  
  45.         if($form['register']->isSubmittedBy()) {
  46.             $values = $form->getValues();
  47.             $values['ip'] = $this->context->httpRequest->getRemoteAddress();
  48.             $values['password'] = $this->context->authenticator->calculateHash($values['password']);
  49.  
  50.         try {
  51.                 $this->db->registration($values);
  52.         $this->flashMessage('Registration successful to your email (' . $values['email'] . ') will be sent an authorization request, please confirm it. In the event of difficulties please contact us.');
  53.                 $this->redirect('this');
  54.  
  55.         } catch (MyApp\NonUniqueRowException $e)  {
  56.                 $form->addError('Such a name or email address already in use by someone else.');
  57.         } catch (MyApp\SqlException $e) {
  58.         $form->addError('What went wrong somewhere. Please try again repeated again after recording this event please contact us and we will solve the subsequent error.');
  59.         }
  60.         }
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment