Пример #1
0
 protected function tearDown()
 {
     Lesson::deleteAll();
     Unit::deleteAll();
     Course::deleteAll();
     User::deleteAll();
 }
Пример #2
0
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if (XUtils::method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } elseif (XUtils::method() == 'POST') {
         $command = trim($_POST['command']);
         $ids = $_POST['id'];
         is_array($ids) && ($ids = implode(',', $ids));
     } else {
         XUtils::message('errorBack', '只支持POST,GET数据');
     }
     empty($ids) && XUtils::message('error', '未选择记录');
     switch ($command) {
         case 'delete':
             parent::_acl('user_delete');
             $cityModel = new User();
             $cityModel->deleteAll('id IN(' . $ids . ')');
             AdminLogger::_create(array('catalog' => 'delete', 'intro' => '删除会员,ID:' . $ids));
             parent::_delete(new User(), $ids, array('index'));
             break;
         default:
             throw new CHttpException(404, '错误的操作类型:' . $command);
             break;
     }
 }
Пример #3
0
 /**
  * Экшен создания учетной записи администратора:
  *
  * @return nothing
  **/
 public function actionCreateuser()
 {
     $model = new InstallForm('createUser');
     if (isset($this->session['InstallForm']['createUser'])) {
         $model->setAttributes($this->session['InstallForm']['createUser']);
         if ($model->validate() && $this->session['InstallForm']['createUserStep'] === true) {
             $this->session['InstallForm'] = array_merge($this->session['InstallForm'], ['createUser' => $model->attributes, 'createUserStep' => false]);
             $this->_markFinished('createuser');
             $this->_setSession();
             $this->redirect(['/install/default/sitesettings']);
         }
     }
     if (($data = Yii::app()->getRequest()->getPost('InstallForm')) !== null) {
         // Сбрасываем сессию текущего пользователя, может поменяться id
         Yii::app()->getUser()->clearStates();
         $model->setAttributes($data);
         if ($model->validate()) {
             $user = new User();
             $user->deleteAll();
             $user->setAttributes(['nick_name' => $model->userName, 'email' => $model->userEmail, 'gender' => User::GENDER_THING, 'access_level' => User::ACCESS_LEVEL_ADMIN, 'status' => User::STATUS_ACTIVE, 'email_confirm' => User::EMAIL_CONFIRM_YES, 'hash' => Yii::app()->userManager->hasher->hashPassword($model->userPassword), 'birth_date' => null]);
             if ($user->save()) {
                 //@TODO заменить на обработку через событие
                 if (Yii::app()->hasModule('rbac')) {
                     Yii::import('application.modules.rbac.models.*');
                     $assign = new AuthAssignment();
                     $assign->itemname = AuthItem::ROLE_ADMIN;
                     $assign->userid = $user->id;
                     $assign->save();
                 }
                 $login = new LoginForm();
                 $login->email = $model->userEmail;
                 $login->password = $model->userPassword;
                 Yii::app()->authenticationManager->login($login, Yii::app()->user, Yii::app()->request);
                 Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('InstallModule.install', 'The administrator has successfully created!'));
                 $this->session['InstallForm'] = array_merge($this->session['InstallForm'], ['createUser' => $model->attributes, 'createUserStep' => true]);
                 $this->_setSession();
                 $this->redirect(['/install/default/createuser']);
             } else {
                 $model->addErrors($user->getErrors());
             }
         }
     }
     $this->render('_view', ['data' => ['model' => $model]]);
 }
Пример #4
0
 /**
  * Экшен создания учетной записи администратора:
  *
  * @return nothing
  **/
 public function actionCreateuser()
 {
     $model = new InstallForm('createUser');
     if (isset($this->session['InstallForm']['createUser'])) {
         $model->setAttributes($this->session['InstallForm']['createUser']);
         if ($model->validate() && $this->session['InstallForm']['createUserStep'] === true) {
             $this->session['InstallForm'] = array_merge($this->session['InstallForm'], array('createUser' => $model->attributes, 'createUserStep' => false));
             $this->_markFinished('createuser');
             $this->_setSession();
             $this->redirect(array('/install/default/sitesettings'));
         }
     }
     if (($data = Yii::app()->getRequest()->getPost('InstallForm')) !== null) {
         // Сбрасываем сессию текущего пользователя, может поменяться id
         Yii::app()->user->clearStates();
         $model->setAttributes($data);
         if ($model->validate()) {
             $user = new User();
             $user->deleteAll();
             $user->setAttributes(array('nick_name' => $model->userName, 'email' => $model->userEmail, 'gender' => 0, 'access_level' => User::ACCESS_LEVEL_ADMIN, 'status' => User::STATUS_ACTIVE, 'email_confirm' => User::EMAIL_CONFIRM_YES, 'hash' => Yii::app()->userManager->hasher->hashPassword($model->userPassword), 'birth_date' => null));
             if ($user->save()) {
                 $login = new LoginForm();
                 $login->email = $model->userEmail;
                 $login->password = $model->userPassword;
                 Yii::app()->authenticationManager->login($login, Yii::app()->user, Yii::app()->request);
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('InstallModule.install', 'The administrator has successfully created!'));
                 $this->session['InstallForm'] = array_merge($this->session['InstallForm'], array('createUser' => $model->attributes, 'createUserStep' => true));
                 $this->_setSession();
                 $this->redirect(array('/install/default/createuser'));
             } else {
                 $model->addErrors($user->getErrors());
             }
         }
     }
     $this->render('_view', array('data' => array('model' => $model)));
 }
Пример #5
0
 public function testAddRename()
 {
     User::deleteAll();
     $this->_conn->addColumn('users', 'girlfriend', 'string');
     User::create(array('girlfriend' => 'bobette'));
     $this->_conn->renameColumn('users', 'girlfriend', 'exgirlfriend');
     $bob = User::find('first');
     $this->assertEquals('bobette', $bob->exgirlfriend);
 }
Пример #6
0
 function testDeleteAll()
 {
     //Arrange
     //We need some categories saved into the database so that we can make sure our deleteAll method removes them all.
     $user = "******";
     $password = "******";
     $id = null;
     $vegie = 0;
     $admin = 1;
     $test_User = new User($user, $password, $vegie, $admin, $id);
     $user2 = "HIST100";
     $password2 = "Abeer";
     $id2 = null;
     $vegie2 = 0;
     $admin2 = 1;
     $test_User2 = new User($user2, $password2, $vegie2, $admin2, $id2);
     $test_User2->save();
     //Act
     //Delete categories.
     User::deleteAll();
     //Assert
     //Now when we call getAll, we should get an empty array because we deleted all categories.
     $result = User::getAll();
     $this->assertEquals([], $result);
 }
 protected function tearDown()
 {
     User::deleteAll();
     Category::deleteAll();
 }
Пример #8
0
 public function testShouldIncludeEmptyHasManyAsEmptyArray()
 {
     User::deleteAll();
     $xml = $this->companies('maintainable')->toXml(array('include' => 'Users', 'indent' => 2));
     $array = Mad_Support_ArrayObject::fromXml($xml);
     $this->assertEquals(array(), $array['company']['users']);
     $this->assertContains('<users type="array"></users>', $xml);
 }
Пример #9
0
 protected function tearDown()
 {
     User::deleteAll();
     Course::deleteAll();
 }
Пример #10
0
 /**
  * @covers EMongoDocument::deleteAll
  */
 function testDeleteAll()
 {
     $c = new User();
     $c->username = '******';
     $this->assertTrue($c->save());
     $c->deleteAll();
     $r = User::model()->findOne();
     $this->assertNull($r);
     for ($i = 0; $i < 9; $i++) {
         $c = new User();
         $c->username = '******';
         $c->mainSkill = 'LoTR';
         $this->assertTrue($c->save());
     }
     $c = new User();
     $c->username = '******';
     $c->mainSkill = 'LoTR';
     $this->assertTrue($c->save());
     $r = User::model()->find(array('mainSkill' => 'LoTR'));
     $this->assertEquals(10, $r->count());
     $c->deleteAll(array('username' => 'ringwraith'));
     $r = User::model()->find(array('mainSkill' => 'LoTR'));
     $this->assertEquals(1, $r->count());
 }
Пример #11
0
 public function testGetIssetBelongsToAssociationAttribute()
 {
     $this->fixtures('users', 'articles');
     $article = Article::find(1);
     $this->assertFalse(empty($article->user));
     // remove all associated objects & recheck
     User::deleteAll();
     $article = Article::find(1);
     $this->assertTrue(empty($article->user));
 }
Пример #12
0
 protected function tearDown()
 {
     User::deleteAll();
     Place::deleteAll();
     Meetup::deleteAll();
 }
Пример #13
0
 function testDeleteAll()
 {
     $c = new User();
     $c->username = '******';
     $this->assertTrue($c->save());
     $c->deleteAll();
     $r = User::model()->findOne();
     $this->assertNull($r);
 }
Пример #14
0
 protected function tearDown()
 {
     User::deleteAll();
     //Project::deleteAll();
 }
Пример #15
0
 function testDeleteAll()
 {
     //Arrange
     $user_name = "Barack Obama";
     $preferred_style = "IPA";
     $region = "Northwest";
     $id = 1;
     $test_user = new User($user_name, $preferred_style, $region, $id);
     $test_user->save();
     $user_name2 = "Miley Cyrus";
     $preferred_style2 = "Stout";
     $region2 = "Southeast";
     $id2 = 2;
     $test_user2 = new User($user_name2, $preferred_style2, $region2, $id2);
     $test_user2->save();
     //Act
     User::deleteAll();
     $result = User::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
Пример #16
0
 function testDeleteAll()
 {
     $user_name = "Wolf";
     $user_buy_quantity = 5;
     $user_phone = '1234567890';
     $user_email = "*****@*****.**";
     $activity_id = 100;
     $id = 1;
     $test_user = new User($user_name, $user_buy_quantity, $user_phone, $user_email, $activity_id, $id);
     $test_user->save();
     $user_name2 = "WolfMan";
     $id2 = 2;
     $test_user2 = new User($user_name2, $user_buy_quantity, $user_phone, $user_email, $activity_id, $id2);
     $test_user2->save();
     User::deleteAll();
     $result = User::GetAll();
     $this->assertEquals([], $result);
 }