/** * Registers new user, collects username and email if needed * * @param CActiveRecord $user current user model * @param object $userProfile social network's user profile object * @access protected */ protected function processUser($user, $userProfile) { if ($this->useYiiUser) { $profile = new Profile(); // enabling register mode // old versions of yii $profile->regMode = true; // new version, when regMode is static property $prop = new ReflectionProperty('Profile', 'regMode'); if ($prop->isStatic()) { Profile::$regMode = true; } } if ($user->isNewRecord) { $this->populateModel($user, $userProfile); } // trying to fill email and username fields // NOTE: we display `username` field in our form only if it is required by the model if (!$user->isAttributeRequired($this->usernameAttribute)) { $this->usernameAttribute = false; } $form = new HUserInfoForm($user, $this->_emailAttribute, $this->usernameAttribute); if (!$form->validateUser()) { $this->controller->render(self::ALIAS . '.views.form', array('form' => $form)); Yii::app()->end(); } // updating attributes in $user model (if needed) $user = $form->validUserModel; // the model won't be new, if user provided email and password of existing account if ($user->isNewRecord) { if (!$user->save()) { throw new Exception("Error, while saving {$this->model} model:\n\n" . var_export($user->errors, true)); } // trying to send activation email $this->sendActivationMail($user); if ($this->useYiiUser) { $profile->user_id = $user->primaryKey; if ($profile->hasAttribute('firstname')) { // we have new version of yii-user of about 06.2013 $profile->firstname = $userProfile->firstName; $profile->lastname = $userProfile->lastName; } else { $profile->first_name = $userProfile->firstName; $profile->last_name = $userProfile->lastName; } if (!$profile->save()) { throw new Exception("Error, while saving " . get_class($profile) . "\tmodel:\n\n" . var_export($user->errors, true)); } } } return $user; }
/** * Uses HUserInfoForm to check if we have all data, that we need from new user * displays the form to get the required, but not specified user data * * @param CActiveRecord $user user model * @return CActiveRecord user model with correct data */ protected function checkUserData($user) { // trying to fill email and username fields // NOTE: we display `username` field in our form only if it is required by the model if ($this->usernameAttribute && !$user->isAttributeRequired($this->usernameAttribute)) { $this->usernameAttribute = false; } $form = new HUserInfoForm($user, $this->_emailAttribute, $this->usernameAttribute); if (!$form->validateUser()) { // We need to request some info from user $this->controller->render('hoauth.views.form', array('form' => $form)); Yii::app()->end(); } // updating attributes in $user model (if needed) $user = $form->validUserModel; return $user; }