/** * Saves the form to a new user. * @return boolean */ public function saveToUser() { if ($this->validate()) { $transaction = UserProfile::model()->getDbConnection()->beginTransaction(); try { $profile = new UserProfile(); $profile->user_status_id = 'ACT'; $profile->pseudo = $this->pseudo; $profile->hash = sha1($this->pseudo); $profile->created = date('Y-m-d H:i:s'); if ($profile->save()) { $user = new UserUser(); $user->user_profile_id = $profile->user_profile_id; $user->userProfile = $profile; $user->hash_salt = self::genSalt(); $user->hash_password = self::hash($this->password, $user->hash_salt); $user->email = $this->usermail; $user->hash_email = sha1($this->usermail); $user->registered = date('Y-m-d H:i:s'); $user->last_login = date('Y-m-d H:i:s'); if ($user->save()) { $this->user = $user; $transaction->commit(); return true; } else { $transaction->rollback(); foreach ($user->getErrors() as $errorlist) { foreach ($errorlist as $error) { $this->addError('pseudo', $error); } } return false; } } else { foreach ($profile->getErrors() as $errorlist) { foreach ($errorlist as $error) { $this->addError('pseudo', $error); } } } } catch (CDbException $e) { $this->addError('pseudo', $e->getMessage()); try { $transaction->rollback(); } catch (CDbException $e2) { // nothing to do } return false; } } return false; }