Esempio n. 1
0
File: User.php Progetto: kokx/Firal
 /**
  * Register a user
  *
  * @param array $data
  *
  * @return bool
  */
 public function register(array $data)
 {
     $form = $this->getRegisterForm();
     if (!$form->isValid($data)) {
         return false;
     }
     // create a user object
     $data = $form->getValues();
     // check if the user exists
     if ($this->_mapper->hasUser($data['username'])) {
         $form->getElement('username')->setErrors(array("User with name '{$form->getValue('username')}' already exists."));
         return false;
     }
     $user = new Default_Model_User();
     $user->setUsername($data['username']);
     $user->setPassword($data['password']);
     $user->setEmail($data['email']);
     $user->setRole('user');
     Firal_Plugin::getDefaultDispatcher()->trigger(new Firal_Event($user, 'default.user.register'));
     // insert the new user
     $this->_mapper->insert($user);
     return true;
 }
Esempio n. 2
0
 /**
  * Check if a user exists by its name
  *
  * @param string $name
  *
  * @return bool
  */
 public function hasUser($name)
 {
     return $this->_mapper->hasUser($name);
 }