コード例 #1
0
ファイル: User.php プロジェクト: 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;
 }