Ejemplo n.º 1
0
 /**
  * Create or update user information
  * @param array() $userInfoArr the user related information
  * @return array() create result. return detail information
  */
 public static function editUser($userInfoArr, $pageActionType)
 {
     $resultInfo = array();
     $actionType = BugfreeModel::ACTION_OPEN;
     $oldRecordAttributs = array();
     if (!empty($userInfoArr['id'])) {
         $user = self::loadModel($userInfoArr['id']);
         if (isset($userInfoArr['realname']) && self::isRealnameExisted($userInfoArr['id'], $userInfoArr['realname'])) {
             $userInfoArr['realname'] = $userInfoArr['realname'] . '[' . $userInfoArr['username'] . ']';
         }
         $oldRecordAttributs = $user->attributes;
         $actionType = BugfreeModel::ACTION_EDIT;
         $user->attributes = $userInfoArr;
         if (!empty($userInfoArr['change_password']) && CommonService::$TrueFalseStatus['TRUE'] == $userInfoArr['change_password']) {
             $user->scenario = 'password';
         }
     } else {
         $user = new TestUser();
         $user->attributes = $userInfoArr;
         if (TestUser::$Authmode['ldap'] == $_POST['TestUser']['authmode']) {
             $ldap = new LdapService(Yii::app()->params->ldap['user'], Yii::app()->params->ldap['pass']);
             if (empty($userInfoArr['username'])) {
                 $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                 $resultInfo['detail']['id'] = Yii::t('TestUser', 'username can not be blank');
                 return $resultInfo;
             }
             $ldapUserInfo = $ldap->search($userInfoArr['username']);
             if (empty($ldapUserInfo)) {
                 $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                 $resultInfo['detail']['id'] = Yii::t('TestUser', 'Domain Account not found');
                 return $resultInfo;
             }
             if (self::isRealnameExisted(0, $ldapUserInfo['realname'])) {
                 $ldapUserInfo['realname'] = $ldapUserInfo['realname'] . '[' . $ldapUserInfo['username'] . ']';
             }
             $user->attributes = $ldapUserInfo;
             $user->password = time();
         }
         $user->is_dropped = CommonService::$TrueFalseStatus['FALSE'];
         $user->email_flag = CommonService::$TrueFalseStatus['TRUE'];
         $user->wangwang_flag = CommonService::$TrueFalseStatus['FALSE'];
     }
     if (!self::isUserEditable($user->id, $pageActionType)) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail']['id'] = Yii::t('Common', 'Required URL not found or permission denied.');
         return $resultInfo;
     }
     if ($user->save()) {
         $newRecord = self::loadModel($user->id);
         $addActionResult = AdminActionService::addActionNotes('test_user', $actionType, $newRecord, $oldRecordAttributs);
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         $resultInfo['detail'] = array('id' => $user->id);
         return $resultInfo;
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $user->getErrors();
     }
     return $resultInfo;
 }
Ejemplo n.º 2
0
 /**
  * testDeleteAdminUser method
  *
  * @return void
  */
 public function testDeleteAdminUser()
 {
     $this->User->create(array('username' => 'admin_user', 'name' => 'Admin User', 'role_id' => 1, 'email' => '*****@*****.**', 'password' => 'password', 'website' => 'http://croogo.org', 'activation_key' => md5(uniqid()), 'status' => true));
     $this->User->save();
     $newAdmin = $this->User->read();
     $this->User->create(array('username' => 'another_adm', 'name' => 'Another Admin', 'role_id' => 1, 'email' => '*****@*****.**', 'password' => 'password', 'website' => 'http://croogo.org', 'activation_key' => md5(uniqid()), 'status' => true));
     $this->User->save();
     $anotherAdmin = $this->User->read();
     $this->User->deleteAll(array('NOT' => array('User.id' => array($newAdmin['User']['id'], $anotherAdmin['User']['id']))));
     $this->assertTrue($this->User->delete($newAdmin['User']['id']));
 }
Ejemplo n.º 3
0
 public function testInitMoreData()
 {
     $user = new TestUser();
     $user->name = 'test user';
     $user->save();
     $movie = new TestMovie();
     $movie->name = 'test movie';
     $movie->save();
     $movie = new TestMovie();
     $movie->name = 'test movie 2';
     $movie->save();
     $this->conn->clear();
 }
 function testUpdateIdWithObjectBelongsTo()
 {
     $system = new TestSystem();
     $system->id = 10;
     $system->name = 'test';
     $user = new TestUser();
     $user->name = 'testnavn';
     $user->system = $system;
     $user->save();
     $this->assertEqual(SimpleDbAdapterWrapper::$adapter->lastSQL(1), 'INSERT INTO users (name, meta1, meta2, system_id, id) VALUES(\'testnavn\', \'\', \'\', 10, NULL)');
 }