/**
  * Validates that a user with this email address is not already registered
  * into the db.
  * 
  * @param unknown $attribute
  * @param unknown $params
  */
 public function validateEmailNotExistant($attribute, $params)
 {
     $ehash = sha1($this->usermail);
     $other = UserUser::model()->findByAttributes(array('hash_email' => $ehash));
     if ($other !== null) {
         $this->addError($attribute, Yii::t('user.form', 'The chosen email address already exists. Please choose another one.'));
     }
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  * @see CUserIdentity::authenticate()
  */
 public function authenticate()
 {
     $dbconn = Yii::app()->getModule('user')->getDatabaseConnection();
     if ($dbconn === null) {
         return false;
     }
     $users = UserUser::model()->findAllByAttributes(array('hash_email' => sha1($this->username)));
     if ($users === array()) {
         $criteria = new CDbCriteria();
         $criteria->with = array('userProfile' => array('alias' => 'p'));
         $criteria->compare('p.pseudo', $this->username);
         $users = UserUser::model()->findAll($criteria);
     }
     if (count($users) === 0) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     }
     foreach ($users as $user) {
         /* @var $user UserUser */
         $hash = UserRegistrationForm::hash($this->password, $user->hash_salt);
         if (!strcmp($hash, $user->hash_password)) {
             $this->errorCode = self::ERROR_NONE;
             $this->user = $user;
         }
     }
     if ($this->errorCode === self::ERROR_NONE) {
         $profile = $this->user->userProfile;
         $this->id = $this->user->hash_email;
         if ($profile !== null) {
             $this->username = $profile->getName();
         } else {
             $this->username = $this->user->email;
         }
         /* @var $session CHttpSession */
         $session = Yii::app()->session;
         $session->regenerateID();
         $this->setState('ring_value.current', IPluggableAccessRole::RING_AUTHENTICATED);
     }
     return !$this->errorCode;
 }