public static function setupUsers($data) { self::dbFixture(\UserAccount::getTableName(), array()); foreach ($data as $key => $userRow) { $userRights = null; if (!isset($userRow['password'])) { $userRow['password'] = self::DefaultPassword; } self::checkUserRow($userRow); if (isset($userRow['rights'])) { $userRights = $userRow['rights']; } $userRow['password'] = Password::hash($userRow['password']); $user = new \UserAccount($userRow); $user->insert(); if (!empty($userRights)) { $user->rights = $userRights; $user->update(); } } }
public function update($group, $permissions) { if (empty($group)) { $this->AddAlert('Группа пользователей не выбрана'); $this->jump('./'); } set_time_limit(0); $page = 0; $groupInfo = DBSimple::get(ACL_TABLE, ['name' => $group]); if (empty($groupInfo)) { throw new \InvalidArgumentException(sprintf('Group "%s" not found, failed to update group permissions', htmlspecialchars($group))); } $permissions = $this->filterPermissionsByGroup($group, $permissions); do { // получаем пользователей $sql = <<<SQL \tselect u.* from %s as u \tinner join %s as r \ton r.entity = concat("%s", u.id) \twhere r.actionId = "%s" \torder by id asc \tlimit %d,%d SQL; $sql = sprintf($sql, \UserAccount::getTableName(), \ACL_GRANT_TABLE, \Faid\DB::escape(\UserAccount::ModelName), $groupInfo['id'], $page * self::Limit, self::Limit); $data = DB::query($sql); // устанавливаем каждому права foreach ($data as $row) { $user = new \UserAccount($row); $tmp = $user->rights->getValue(); $tmp = array_merge($tmp, $permissions); $user->rights = $tmp; $user->update(); } $page++; } while (sizeof($data) != 0); $this->addAlert('Права обновлены'); $this->jump('./'); }
public static function activateEmail($code) { $found = DBSimple::get(self::getTableName(), array('email_confirmation_code' => $code)); if (empty($found)) { throw new NotFoundException('Confirmation code not found '); } $result = new UserAccount($found); $result->email->setValue($result->new_email->getValue()); $result->new_email->setValue(''); $result->email_confirmation_code->setValue(''); $result->update(); return $result; }
public function blockUser(\UserAccount $user) { \CMSLog::addMessage(self::LogName, sprintf('Users with login %s blocked ', $user->login->getValue())); $user->confirmation_code = \UsersRegistration::getConfirmationCode(); $user->update(); }