public function createUser(RegistrationForm $form) { $transaction = Yii::app()->db->beginTransaction(); try { $user = new User('registration'); $profile = new Profile('registration'); $data = $form->getAttributes(); // Устанавливаем атрибуты пользователя $user->setAttributes(array('email' => $data['email'])); // Генерируем для пользователя новый пароль $password = $this->hasher->generateRandomPassword(); $user->hash = $this->hasher->hashPassword($password); // Устанавливаем роль пользователя $user->role = User::USER_ROLE; $profile->setAttributes(array('name' => $data['name'], 'gender' => $data['gender'], 'birth_date' => $data['date'], 'birth_time' => $form->getTime(), 'city_id' => $data['city_id'])); $profile->subscriber = Profile::SUBSCRIBER_YES; if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) { $profile->user_id = $user->id; if (!$profile->save()) { throw new CException(Yii::t('UserModule.user', 'Error creating profile!')); } $event = new CEvent($this, array('user' => $user, 'password' => $password, 'token' => $token, 'programId' => $data['programId'], 'subscriptionType' => $data['subscriptionType'])); $this->onSuccessRegistration($event); Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', array('{nick_name}' => $user->email)), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->commit(); return $user; } throw new CException(Yii::t('UserModule.user', 'Error creating account!')); } catch (Exception $e) { Yii::log(Yii::t('UserModule.user', 'Error {error} account creating!', array('{error}' => $e->__toString())), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->rollback(); return false; } }