Example #1
0
 /**
  * Add a blacklist item. 
  * 
  * @access public
  * @return void
  */
 public function addBlacklist()
 {
     $typeList = $this->lang->guarder->blacklistModes;
     if ($_POST) {
         $item = $this->post->identity;
         $type = 'keywords';
         if (validater::checkIP($item)) {
             $type = 'ip';
         }
         if (validater::checkEmail($item)) {
             $type = 'email';
         }
         if (validater::checkAccount($item)) {
             $user = $this->loadModel('user')->getByAccount($item);
             if (!empty($user)) {
                 $type = 'account';
             }
         }
         $result = $this->guarder->punish($type, $item, $this->post->reason, $this->post->expired);
         if ($result) {
             $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess, 'locate' => inlink('blacklist', "mode={$type}")));
         }
         $this->send(array('result' => 'fail', 'message' => dao::geterror()));
     }
     $this->view->title = $this->lang->guarder->addBlacklist;
     $this->display();
 }
Example #2
0
 /**
  * Batch edit user.
  * 
  * @access public
  * @return void
  */
 public function batchEdit()
 {
     if (empty($_POST['verifyPassword']) or md5($this->post->verifyPassword) != $this->app->user->password) {
         die(js::alert($this->lang->user->error->verifyPassword));
     }
     $oldUsers = $this->dao->select('id, account')->from(TABLE_USER)->where('id')->in(array_keys($this->post->account))->fetchPairs('id', 'account');
     $accountGroup = $this->dao->select('id, account')->from(TABLE_USER)->where('account')->in($this->post->account)->fetchGroup('account', 'id');
     $accounts = array();
     foreach ($this->post->account as $id => $account) {
         $users[$id]['account'] = $account;
         $users[$id]['realname'] = $this->post->realname[$id];
         $users[$id]['commiter'] = $this->post->commiter[$id];
         $users[$id]['email'] = $this->post->email[$id];
         $users[$id]['join'] = $this->post->join[$id];
         $users[$id]['dept'] = $this->post->dept[$id] == 'ditto' ? isset($prev['dept']) ? $prev['dept'] : 0 : $this->post->dept[$id];
         $users[$id]['role'] = $this->post->role[$id] == 'ditto' ? isset($prev['role']) ? $prev['role'] : 0 : $this->post->role[$id];
         if (isset($accountGroup[$account]) and count($accountGroup[$account]) > 1) {
             die(js::error(sprintf($this->lang->user->error->accountDupl, $id)));
         }
         if (in_array($account, $accounts)) {
             die(js::error(sprintf($this->lang->user->error->accountDupl, $id)));
         }
         if (!validater::checkAccount($users[$id]['account'])) {
             die(js::error(sprintf($this->lang->user->error->account, $id)));
         }
         if ($users[$id]['realname'] == '') {
             die(js::error(sprintf($this->lang->user->error->realname, $id)));
         }
         if ($users[$id]['email'] and !validater::checkEmail($users[$id]['email'])) {
             die(js::error(sprintf($this->lang->user->error->mail, $id)));
         }
         if (empty($users[$id]['role'])) {
             die(js::error(sprintf($this->lang->user->error->role, $id)));
         }
         $accounts[$id] = $account;
         $prev['dept'] = $users[$id]['dept'];
         $prev['role'] = $users[$id]['role'];
     }
     foreach ($users as $id => $user) {
         $this->dao->update(TABLE_USER)->data($user)->where('id')->eq((int) $id)->exec();
         if ($user['account'] != $oldUsers[$id]) {
             $oldAccount = $oldUsers[$id];
             $this->dao->update(TABLE_USERGROUP)->set('account')->eq($user['account'])->where('account')->eq($oldAccount)->exec();
             if (strpos($this->app->company->admins, ',' . $oldAccount . ',') !== false) {
                 $admins = str_replace(',' . $oldAccount . ',', ',' . $user['account'] . ',', $this->app->company->admins);
                 $this->dao->update(TABLE_COMPANY)->set('admins')->eq($admins)->where('id')->eq($this->app->company->id)->exec();
             }
             if (!dao::isError() and $this->app->user->account == $oldAccount) {
                 $this->app->user->account = $users['account'];
             }
         }
     }
 }
Example #3
0
 /**
  * Update project member.
  * 
  * @access public
  * @return void
  */
 public function upgradeProjectMember()
 {
     $projects = $this->loadModel('project', 'oa')->getList();
     foreach ($projects as $project) {
         $member = new stdclass();
         $member->type = 'project';
         $member->id = $project->id;
         /* Move master to team table. */
         if (!empty($project->master)) {
             $member->account = $project->master;
             $member->role = 'role';
             $this->dao->replace(TABLE_TEAM)->data($member)->exec();
         }
         /* Move members to team table. */
         if (!empty($project->member)) {
             $members = explode(',', $project->member);
             $member->role = 'member';
             foreach ($members as $account) {
                 if ($account == $project->master) {
                     continue;
                 }
                 if (!validater::checkAccount($account)) {
                     continue;
                 }
                 $member->account = $account;
                 $this->dao->replace(TABLE_TEAM)->data($member)->exec();
             }
         }
         return true;
     }
 }