public function register($aid, $name, $gender, $age, $type, $u_name, $u_gender, $u_city, $inviter) { $user = new User(); $user->name = $u_name; $user->gender = $u_gender; $user->city = $u_city; $user->code = $this->createInviteCode(); $user->inviter = $inviter; $user->gold = 500; $reward_items = array(1101 => 3, 1102 => 3, 1103 => 3, 1104 => 3, 1105 => 3, 1106 => 3, 1107 => 3, 1201 => 2, 1202 => 2, 1203 => 2, 1204 => 2, 1205 => 2, 1206 => 2, 1207 => 2, 1301 => 1, 1302 => 1, 1303 => 1, 1304 => 1, 1305 => 1, 2101 => 3, 2102 => 3, 2103 => 3, 2104 => 3); $user->items = serialize($reward_items); $user->save(); if (!isset($aid)) { $animal = new Animal(); $animal->name = $name; $animal->gender = $gender; $animal->age = $age; $animal->type = $type; $animal->from = substr($type, 0, 1); $animal->master_id = $user->usr_id; $animal->save(); $aid = $animal->aid; $circle = new Circle(); $circle->aid = $aid; $circle->usr_id = $user->usr_id; $circle->rank = 0; $circle->save(); } else { $circle = new Circle(); $circle->aid = $aid; $circle->usr_id = $user->usr_id; $circle->save(); } $f = new Follow(); $f->usr_id = $user->usr_id; $f->aid = $aid; $f->create_time = time(); $f->save(); $user->aid = $aid; $user->saveAttributes(array('aid')); $user->initialize(); $user->rewardInviter(); //$this->onRegister = array($user, 'initialize'); //$this->onRegister = array($user, 'rewardInviter'); $this->owner->usr_id = $user->usr_id; $this->owner->saveAttributes(array('usr_id')); $this->onRegister(new CEvent()); return $user; }
/** * @covers EMongoDocument::saveAttributes */ function testSaveAttributes() { $c = new User(); $c->username = '******'; $this->assertTrue($c->save()); $c->job_title = 'wizard'; $r = $c->saveAttributes(array('job_title')); $this->assertNull($r['err']); $r = User::model()->findOne(); $this->assertTrue(isset($r->job_title)); $this->assertEquals('wizard', $r->job_title); $c = new User(); $c->username = '******'; $c->job_title = 'wizard'; $this->setExpectedException('CDbException'); $c->saveAttributes(array('job_title')); }
protected function proccessRequest($model = null) { if (Yii::app()->request->getPost('User') !== null) { if (!$model) { $model = new User('register'); $model->makeForm('register', $this->params['content']->fields, $this->params['content']->fields_req); } $tpldata = array(); $model->attributes = Yii::app()->request->getPost('User'); if ($model->password == '') { $model->password = $model->password_repeat = $tpldata['generatedPassword'] = User::generatePassword(); $model->askfill = true; } if ($model->validate()) { $model->save(false); $cfg = ContentUnit::loadConfig(); $viewFileDir = $cfg['UnitRegister'] . '.register.templates.mail.'; $tpldata['model'] = $model->getAttributes(); $tpldata['settings'] = Yii::app()->settings->model->getAttributes(); $tpldata['page'] = $this->params['content']->getWidgetPageArray(); if ($this->params['content']->notify_admin) { // send 'to_admin_notify' mail Yii::app()->messenger->send('email', Yii::app()->settings->getValue('adminEmail'), '[' . $_SERVER['HTTP_HOST'] . '] ' . Yii::t('UnitRegister.main', 'New user registration'), Yii::app()->controller->renderPartial($viewFileDir . 'to_admin_notify', $tpldata, true)); } if ($this->params['content']->is_emailauth_req) { $model->saveAttributes(array('authcode' => User::hash($model->id . $model->login . time() . rand()))); $tpldata['model'] = $model; // send 'to_user_confirm' mail Yii::app()->messenger->send('email', $model->email, Yii::t('UnitRegister.main', 'Registration confirm'), Yii::app()->controller->renderPartial($viewFileDir . 'to_user_confirm', $tpldata, true)); return true; } else { $model->saveAttributes(array('active' => true)); if ($this->params['content']->notify_user || $tpldata['generatedPassword']) { // send 'to_user_notify' mail Yii::app()->messenger->send('email', $model->email, Yii::t('UnitRegister.main', 'Registration completed'), Yii::app()->controller->renderPartial($viewFileDir . 'to_user_notify', $tpldata, true)); } $loginForm = new LoginForm(); $loginForm->username = $model->email; $loginForm->password = !empty($_POST['User']['password']) ? $_POST['User']['password'] : $tpldata['generatedPassword']; if ($loginForm->login()) { return true; } } } } return false; }
function testSaveAttributes() { $c = new User(); $c->username = '******'; $this->assertTrue($c->save()); $c->job_title = 'programmer'; $r = $c->saveAttributes(array('username')); $this->assertNull($r['err']); $r = User::model()->findOne(); $this->assertFalse(isset($r->job_title)); }
/** * @covers EMongoDocument::saveAttributes */ public function testSaveAttributes() { $c = new User(); $c->username = '******'; $this->assertTrue($c->save()); $c->job_title = 'wizard'; $r = $c->saveAttributes(['job_title']); $this->assertNotNull($r->getModifiedCount()); $r = User::model()->findOne(); $this->assertTrue(isset($r->job_title)); $this->assertEquals('wizard', $r->job_title); $c = new User(); $c->username = '******'; $c->job_title = 'wizard'; $this->setExpectedException('EMongoException'); $c->saveAttributes(['job_title']); }