public function testMakeFormFromGroup() { $user = UserTestHelper::createBasicUser('Billy'); $billId = $user->id; unset($user); $user = User::getById($billId); $this->assertEquals('billy', $user->username); $user = UserTestHelper::createBasicUser('Jimmy'); $jimId = $user->id; unset($user); $user = User::getById($jimId); $this->assertEquals('jimmy', $user->username); $users = User::GetAll(); $allUsers = array(); foreach ($users as $user) { $allUsers[$user->id] = strval($user); } $this->assertEquals(3, count($allUsers)); $a = new Group(); $a->name = 'JJJ'; $this->assertTrue($a->save()); $this->assertEquals(0, $a->users->count()); $this->assertEquals(0, $a->groups->count()); $form = GroupUserMembershipFormUtil::makeFormFromGroup($a); $this->assertEquals(array(), $form->userMembershipData); $this->assertEquals($allUsers, $form->userNonMembershipData); }
/** * @param Report $report * @param array $postData * @param string $wizardFormClassName */ public static function resolveReportByWizardPostData(Report $report, $postData, $wizardFormClassName) { assert('is_array($postData)'); assert('is_string($wizardFormClassName)'); $data = ArrayUtil::getArrayValue($postData, $wizardFormClassName); if (isset($data['description'])) { $report->setDescription($data['description']); } if (isset($data['moduleClassName'])) { $report->setModuleClassName($data['moduleClassName']); } if (isset($data['name'])) { $report->setName($data['name']); } self::resolveFiltersStructure($data, $report); if (null != ArrayUtil::getArrayValue($data, 'ownerId')) { $owner = User::getById((int) $data['ownerId']); $report->setOwner($owner); } else { $report->setOwner(new User()); } if (isset($data['currencyConversionType'])) { $report->setCurrencyConversionType((int) $data['currencyConversionType']); } if (isset($data['spotConversionCurrencyCode'])) { $report->setSpotConversionCurrencyCode($data['spotConversionCurrencyCode']); } self::resolveFilters($data, $report); self::resolveOrderBys($data, $report); self::resolveDisplayAttributes($data, $report); self::resolveDrillDownDisplayAttributes($data, $report); self::resolveGroupBys($data, $report); self::resolveChart($data, $report); }
protected function renderLeaderboardContent() { $content = '<table class="items">'; $content .= '<colgroup>'; $content .= '<col style="width:10%" /><col style="width:80%" /><col style="width:10%" />'; $content .= '</colgroup>'; $content .= '<tbody>'; $content .= '<tr><th>' . Zurmo::t('GamificationModule', 'Rank') . '</th>'; $content .= '<th>' . Zurmo::t('GamificationModule', 'User') . '</th>'; $content .= '<th>' . Zurmo::t('GamificationModule', 'Points') . '</th>'; $content .= '</tr>'; foreach ($this->leaderboardData as $userId => $leaderboardData) { assert('is_string($leaderboardData["rank"])'); assert('is_string($leaderboardData["userLabel"])'); assert('is_int($leaderboardData["points"])'); $userUrl = Yii::app()->createUrl('/users/default/details', array('id' => $userId)); $user = User::getById($userId); $avatarImage = $user->getAvatarImage(24); $content .= '<tr>'; $content .= '<td><span class="ranking">' . $leaderboardData['rank'] . '</span></td>'; $content .= '<td class="user-label">' . ZurmoHtml::link($avatarImage . '<span>' . $leaderboardData['userLabel'] . '</span>', $userUrl) . '</td>'; $content .= '<td><span class="points">' . $leaderboardData['points'] . '</span></td>'; $content .= '</tr>'; } $content .= '</tbody>'; $content .= '</table>'; return $content; }
private function getUserDetail($userId) { $database = gGetDb(); $user = User::getById($userId, $database); if ($user == false) { return BootstrapSkin::displayAlertBox("User not found", "alert-error", "Error", true, false, true); } global $smarty; $activitySummary = $database->prepare(<<<SQL SELECT COALESCE(c.mail_desc, l.log_action) AS action, COUNT(*) AS count FROM acc_log l LEFT JOIN closes c ON l.log_action = c.closes WHERE l.log_user = :username GROUP BY action; SQL ); $activitySummary->execute(array(":username" => $user->getUsername())); $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); $smarty->assign("user", $user); $smarty->assign("activity", $activitySummaryData); $usersCreatedQuery = $database->prepare(<<<SQL SELECT l.log_time time, r.name name, r.id id FROM acc_log l JOIN request r ON r.id = l.log_pend LEFT JOIN emailtemplate e ON concat('Closed ', e.id) = l.log_action WHERE l.log_user = :username AND l.log_action LIKE 'Closed %' AND (e.oncreated = '1' OR l.log_action = 'Closed custom-y') ORDER BY l.log_time; SQL ); $usersCreatedQuery->execute(array(":username" => $user->getUsername())); $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); $smarty->assign("created", $usersCreated); $usersNotCreatedQuery = $database->prepare(<<<SQL SELECT l.log_time time, r.name name, r.id id FROM acc_log l JOIN request r ON r.id = l.log_pend LEFT JOIN emailtemplate e ON concat('Closed ', e.id) = l.log_action WHERE l.log_user = :username AND l.log_action LIKE 'Closed %' AND (e.oncreated = '0' OR l.log_action = 'Closed custom-n' OR l.log_action='Closed 0') ORDER BY l.log_time; SQL ); $usersNotCreatedQuery->execute(array(":username" => $user->getUsername())); $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); $smarty->assign("notcreated", $usersNotCreated); $accountLogQuery = $database->prepare(<<<SQL SELECT * FROM acc_log l WHERE l.log_pend = :userid \t AND log_action IN ('Approved','Suspended','Declined','Promoted','Demoted','Renamed','Prefchange'); SQL ); $accountLogQuery->execute(array(":userid" => $user->getId())); $accountLog = $accountLogQuery->fetchAll(PDO::FETCH_ASSOC); $smarty->assign("accountlog", $accountLog); return $smarty->fetch("statistics/userdetail.tpl"); }
public function testPasswordExpiresPolicyRules() { $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $everyoneGroup->save(); $user = UserTestHelper::createBasicUser('Bobby'); $id = $user->id; unset($user); $user = User::getById($id); $adapter = new UserGroupMembershipToViewAdapter($user); $viewData = $adapter->getViewData(); $compareData = array($everyoneGroup->id => array('displayName' => 'Everyone', 'canRemoveFrom' => false)); $this->assertEquals($compareData, $viewData); $a = new Group(); $a->name = 'AAA'; $this->assertTrue($a->save()); $a->users->add($user); $this->assertTrue($a->save()); $user->forget(); $groupId = $a->id; $a->forget(); unset($a); $user = User::getById($id); $adapter = new UserGroupMembershipToViewAdapter($user); $viewData = $adapter->getViewData(); $compareData = array($everyoneGroup->id => array('displayName' => 'Everyone', 'canRemoveFrom' => false), $groupId => array('displayName' => 'AAA', 'canRemoveFrom' => true)); $this->assertEquals($compareData, $viewData); $user->forget(); unset($user); }
/** * On success populates $GLOBALS['user'] with the authenticated user. * * @return bool */ public static function authenticate() { $authClass = 'Auth_' . ucfirst(AUTH_METHOD); if (!class_exists($authClass)) { SystemEvent::raise(SystemEvent::ERROR, 'Authentication module not found, reverting to default local. [MODULE=' . AUTH_METHOD . '] [PATH="src/core/Auth/' . $authClass . '.php"]', __METHOD__); return false; } $userId = $authClass::authenticate(); if (null === $userId) { // No actual authentication attempt was tried, so no point in logging anything SystemEvent::raise(SystemEvent::DEBUG, "No authentication attempted.", __METHOD__); return null; } elseif (false === $userId) { SystemEvent::raise(SystemEvent::DEBUG, "Failed authentication attempt.", __METHOD__); return false; } $user = User::getById($userId); if (!$user instanceof User) { SystemEvent::raise(SystemEvent::INFO, "Unknown user from user ID. [ID={$userId}]", __METHOD__); return false; } $_SESSION['userId'] = $userId; $GLOBALS['user'] = $user; SystemEvent::raise(SystemEvent::DEBUG, "User authenticated. [USR={$user->getUsername()}]", __METHOD__); return true; }
/** * @param array $data */ public static function resolveValue($data) { $userUrl = Yii::app()->createUrl('/users/default/details', array('id' => $data['userId'])); $user = User::getById($data['userId']); $avatarImage = $user->getAvatarImage(24); $userLabel = ZurmoHtml::tag('span', array(), $data['userLabel']); return ZurmoHtml::link($avatarImage . $userLabel, $userUrl, array('class' => 'user-label')); }
public function load($params = null) { if (empty($params[0])) { return 'no id'; } $user = User::getById($params[0]); unset($user->password); return $user; }
/** * Given a OutboundEmailConfigurationForm, save the configuration global values. */ public static function setConfigurationFromForm(OutboundEmailConfigurationForm $form) { Yii::app()->emailHelper->outboundHost = $form->host; Yii::app()->emailHelper->outboundPort = $form->port; Yii::app()->emailHelper->outboundUsername = $form->username; Yii::app()->emailHelper->outboundPassword = $form->password; Yii::app()->emailHelper->setOutboundSettings(); Yii::app()->emailHelper->setUserToSendNotificationsAs(User::getById((int) $form->userIdOfUserToSendNotificationsAs)); }
public function __construct(array $data = array()) { parent::__construct($data); if (!isset($this->user_id)) { return; } $user = User::getById($this->user_id); $this->user = $user; }
/** * Loads a list of users for the specicifies parameters, returns an array of User elements * * @return array */ public function load() { $usersData = $this->db->fetchAll("SELECT id FROM users" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($usersData as $userData) { $users[] = User::getById($userData["id"]); } $this->model->setUsers($users); return $users; }
protected static function getZurmoControllerUtil() { $getData = GetUtil::getData(); $relatedUserId = ArrayUtil::getArrayValue($getData, 'relatedUserId'); if ($relatedUserId == null) { $relatedUser = null; } else { $relatedUser = User::getById((int) $relatedUserId); } return new SocialItemZurmoControllerUtil($relatedUser); }
/** * test create system user */ public function testCreateSystemUser() { $user = InstallUtil::createSystemUser('testsystemuser', 'test'); $id = $user->id; $user->forget(); unset($user); $user = User::getById($id); $this->assertTrue((bool) $user->isSystemUser); $this->assertTrue((bool) $user->hideFromSelecting); $this->assertTrue((bool) $user->hideFromLeaderboard); }
public static function getSoapClient() { ini_set("soap.wsdl_cache_enabled", "0"); $conf = Zend_Registry::get("pimcore_config_test"); $user = User::getById($conf->user); if (!$user instanceof User) { throw new Exception("invalid user id"); } $client = new Zend_Soap_Client($conf->webservice->wsdl . "&username="******"&apikey=" . $user->getPassword(), array("cache_wsdl" => false, "soap_version" => SOAP_1_2, "classmap" => Webservice_Tool::createClassMappings())); $client->setLocation($conf->webservice->serviceEndpoint . "?username="******"&apikey=" . $user->getPassword()); return $client; }
/** * Checks if data is valid for current data field * * @param mixed $data * @param boolean $omitMandatoryCheck * @throws Exception */ public function checkValidity($data, $omitMandatoryCheck = false) { if (!$omitMandatoryCheck and $this->getMandatory() and empty($data)) { throw new Exception("Empty mandatory field [ " . $this->getName() . " ]"); } if (!empty($data)) { $user = User::getById($data); if (!$user instanceof User) { throw new Exception("invalid user reference"); } } }
public function update() { $user = new User($this->db); if ($this->f3->exists('POST.update')) { $user->edit($this->f3->get('POST.id')); $this->f3->reroute('/success/User Updated'); } else { $user->getById($this->f3->get('PARAMS.id')); $this->f3->set('user', $user); $this->f3->set('page_head', 'Update User'); $this->f3->set('view', 'user/update.htm'); } }
public static function getUserLeaderboardData($type) { assert('is_string($type)'); $sql = static::makeUserLeaderboardSqlQuery($type); $rows = R::getAll($sql); $rank = 1; $leaderboardData = array(); foreach ($rows as $row) { $leaderboardData[$row['userid']] = array('rank' => StringUtil::resolveOrdinalIntegerAsStringContent(intval($rank)), 'userLabel' => strval(User::getById(intval($row['userid']))), 'points' => intval($row['points'])); $rank++; } return $leaderboardData; }
/** * */ public function mail() { $conf = Pimcore_Config::getSystemConfig(); if (!empty($conf->general->logrecipient)) { Logger::debug(get_class($this) . ": detected log recipient:" . $conf->general->logrecipient); $user = User::getById($conf->general->logrecipient); Logger::debug(get_class($this) . ": detected log recipient:" . $user->getEmail()); if ($user instanceof User && $user->isAdmin()) { $email = $user->getEmail(); Logger::debug(get_class($this) . ": user is valid"); if (!empty($email)) { if (is_dir(PIMCORE_LOG_MAIL_TEMP)) { Logger::debug(get_class($this) . ": detected mail log dir"); Logger::debug(get_class($this) . ": opening dir " . PIMCORE_LOG_MAIL_TEMP); if ($handle = opendir(PIMCORE_LOG_MAIL_TEMP)) { Logger::debug(get_class($this) . ": reading dir " . PIMCORE_LOG_MAIL_TEMP); while (false !== ($file = readdir($handle))) { Logger::debug(get_class($this) . ": detected file " . $file); if (is_file(PIMCORE_LOG_MAIL_TEMP . "/" . $file) and is_writable(PIMCORE_LOG_MAIL_TEMP . "/" . $file)) { $now = time(); $threshold = 1 * 60 * 15; $fileModified = filemtime(PIMCORE_LOG_MAIL_TEMP . "/" . $file); Logger::debug(get_class($this) . ": file is writeable and was last modified: " . $fileModified); if ($fileModified !== FALSE and $fileModified < $now - $threshold) { $mail = Pimcore_Tool::getMail(array($email), "pimcore log notification - " . $file); $mail->setIgnoreDebugMode(true); $mail->setBodyText(file_get_contents(PIMCORE_LOG_MAIL_TEMP . "/" . $file)); $mail->send(); @unlink(PIMCORE_LOG_MAIL_TEMP . "/" . $file); Logger::debug(get_class($this) . ": sent mail and deleted temp log file " . $file); } else { if ($fileModified > $now - $threshold) { Logger::debug(get_class($this) . ": leaving temp log file alone because file [ {$file} ] was written to within the last 15 minutes"); } } } } } } } else { Logger::err(get_class($this) . ": Cannot send mail to configured log user [" . $user->getName() . "] because email is empty"); } } else { Logger::err(get_class($this) . ": Cannot send mail to configured log user. User is either null or not an admin"); } } else { Logger::debug(get_class($this) . ": No log recipient configured"); } }
/** * Initialize the session user */ public function init() { if (!$this->getData('user.id')) { $this->setData('user.id', 0); } if (App::conf()->has('db')) { // Get the user from the database $this->user = User::getById($this->getData('user.id')); } else { // The database does not exists yet. Create a 'fake' guest user $this->user = new User(array('id' => User::GUEST_USER_ID, 'username' => 'guest', 'active' => 0)); $this->logged = false; } $this->logged = $this->user->isLogged(); }
/** * @param string $type * @param int $startingRank * @param null|int $offset * @param null|int $count * @return array */ public static function getUserLeaderboardData($type, $startingRank = 1, $offset = null, $count = null) { assert('is_string($type)'); assert('$offset === null || is_integer($offset) && $offset >= 0'); assert('$count === null || is_integer($count) && $count >= 1'); $sql = static::makeUserLeaderboardSqlQuery($type, $offset, $count); $rows = R::getAll($sql); $rank = $startingRank; $leaderboardData = array(); foreach ($rows as $row) { $leaderboardData[$row['userid']] = array('rank' => StringUtil::resolveOrdinalIntegerAsStringContent(intval($rank)), 'userLabel' => strval(User::getById(intval($row['userid']))), 'points' => intval($row['points'])); $rank++; } return $leaderboardData; }
/** * @static * @throws Exception * @return User */ public static function authenticateSession() { // start session if necessary self::initSession(); // get session namespace $adminSession = self::getSession(); $user = $adminSession->user; if ($user instanceof User) { // renew user $user = User::getById($user->getId()); if ($user && $user->isActive()) { return $user; } } return null; }
public function forceLogout($uid) { $user = User::getById($uid, gGetDb()); if ($user->getForceLogout() == "1") { $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time() - 42000, '/'); } session_destroy(); echo "You have been forcibly logged out, probably due to being renamed. Please log back in."; BootstrapSkin::displayAlertBox("You have been forcibly logged out, probably due to being renamed. Please log back in.", "alert-error", "Logged out", true, false); $user->setForceLogout(0); $user->save(); BootstrapSkin::displayInternalFooter(); die; } }
/** * Authenticate the user with the cookie * * @access public * @return bool */ public function authenticate() { $credentials = $this->readCookie(); if ($credentials !== false) { $record = $this->find($credentials['token'], $credentials['sequence']); if ($record) { // Update the sequence $this->writeCookie($record['token'], $this->update($record['token'], $record['sequence']), $record['expiration']); // Create the session $user = new User($this->db, $this->event); $acl = new Acl($this->db, $this->event); $user->updateSession($user->getById($record['user_id'])); $acl->isRememberMe(true); return true; } } return false; }
function editUser() { global $lang; $page_lang = scandir('inc/lang/' . $_SESSION['language']); foreach ($page_lang as $file) { if ($file != '.' && $file != '..') { $parts = explode(".", $file); $page = $parts[0]; if ($page == 'user') { $page_file = $file; } } } include_once 'inc/lang/' . $_SESSION['language'] . '/' . $page_file; if ($_SESSION['access']->users > 1) { $results = array(); $results['formAction'] = "editUser"; if (isset($_POST['saveChanges'])) { // User has posted the user edit form: save the user changes if (!($user = User::getById((int) $_GET['editId']))) { header("Location: index.php?action=listUser&error=userNotFound"); return; } if (!empty($_POST['newPassword'])) { $_POST['password'] = md5($_POST['newPassword']); } unset($_POST['newPassword']); unset($_POST['newPassConfirm']); $user = new User(); $user->storeFormValues($_POST); $user->update(); header("Location: index.php?action=listUser&success=userChangesSaved"); } elseif (isset($_POST['cancel'])) { // User has cancelled their edits: return to the user list header("Location: index.php?action=listUser"); } else { // User has not submitted the user edit form: display the user edit form $results['user'] = User::getById((int) $_GET['userId']); require "inc/layout/editUser.php"; } } else { require "inc/layout/noAccess.php"; } }
/** * Check if user set their primary email address. * @param CFilterChain $filterChain * @return bool * @throws NotFoundException * @throws NotSupportedException */ protected function preFilter($filterChain) { if ($this->userId != null) { $user = User::getById($this->userId); } else { throw new NotSupportedException(); } if (isset($_POST['ajax'])) { return true; } if ($user->primaryEmail->emailAddress != null) { return true; } $messageView = new NoPrimaryEmailAddressForLoggedUserYetView($this->userId); $pageViewClassName = $this->controller->getModule()->getPluralCamelCasedName() . 'PageView'; $view = new $pageViewClassName(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this->controller, $messageView)); echo $view->render(); return false; }
/** * @param $model * @param array $reformedUserAttendees array of User Ids * Remove user attendees that are not provided. Add additional. Do not re-add already added ones. */ protected function resolveUserAttendees(&$model, $reformedUserAttendees = array()) { $usersAlreadyAdded = array(); if ($model->userAttendees->count() > 0) { foreach ($model->userAttendees as $user) { if (!in_array($user->id, $reformedUserAttendees)) { $model->userAttendees->remove($user); } else { $usersAlreadyAdded[] = $user->id; } } } foreach ($reformedUserAttendees as $userId) { if ($userId != null && $userId > 0 && !in_array($userId, $usersAlreadyAdded)) { $user = User::getById($userId); $model->userAttendees->add($user); } } }
public function update() { $user = new User($this->db); if ($this->f3->exists('POST.updateUser')) { // turn empty enter into null for submi_date if (trim($this->f3->get('POST.submit_date')) == '') { $this->f3->set('POST.submit_date', null); } $name = $this->f3->get('POST.username'); $this->f3->set('POST.name', $name); $user->edit($this->f3->get('POST.id')); $this->f3->reroute('/useradmin'); } else { $user->getById($this->f3->get('PARAMS.id')); $this->f3->set('user', $user); $this->f3->set('showMenu', false); $this->f3->set('view', "/user/update.html"); echo Template::instance()->render('layout.htm'); } }
public function update() { $user = new User($this->db); /* * check if POST request has create field * if yes, add user and return home */ if ($this->f3->exists('POST.update')) { $user->edit($this->f3->get('POST.id')); $this->f3->reroute('/'); } else { $user->getById($this->f3->get('PARAMS.id')); $this->f3->set('user', $user); $this->f3->set('page_head', 'Update User'); $this->f3->set('view', 'user/update.html'); } /* * testing */ }
/** * Get feed information if projects for user * @param ProjectAuditEvent $projectAuditEvent * @return string */ public static function getFeedInformationForDashboard(ProjectAuditEvent $projectAuditEvent) { assert('$projectAuditEvent instanceof ProjectAuditEvent'); $project = Project::getById(intval($projectAuditEvent->project->id)); $dateTime = DateTimeUtil::getTimeSinceDisplayContent($projectAuditEvent->dateTime); $data = array('{timeSpanLabel}' => $dateTime); if (ActionSecurityUtil::canCurrentUserPerformAction('Details', $project)) { $projectName = static::resolveProjectName($project); $data['{projectname}'] = $projectName; $user = User::getById($projectAuditEvent->user->id); $data['{username}'] = $user->getFullName(); $unserializedData = unserialize($projectAuditEvent->serializedData); if (is_array($unserializedData)) { $data = array_merge($unserializedData, $data); } } else { return Zurmo::t('ProjectsModule', '<strong>Activity on a restricted project </strong> <small>about {timeSpanLabel}</small>', $data); } return static::getMessageContentByEventAndData($projectAuditEvent->eventName, $data); }
public function testSaveAndLoadGroup() { $u = array(); for ($i = 0; $i < 5; $i++) { $user = new User(); $user->setScenario('createUser'); $user->username = "******"; $user->title->value = 'Mr.'; $user->firstName = "Uuuuuu{$i}"; $user->lastName = "Uuuuuu{$i}son"; $user->setPassword("uuuuu{$i}"); $this->assertTrue($user->save()); // Clear cache of user so the groups properly get accounted for later. // This was needed after we added isActive which calls save twice when a user is // created $id = $user->id; $user->forget(); $u[] = User::getById($id); } $a = new Group(); $a->name = 'AAA'; $this->assertTrue($a->save()); $this->assertEquals(0, $a->users->count()); $this->assertEquals(0, $a->groups->count()); $b = new Group(); $b->name = 'BBB'; $this->assertTrue($b->save()); $this->assertEquals(0, $b->users->count()); $this->assertEquals(0, $b->groups->count()); $a->users->add($u[0]); $a->groups->add($b); $this->assertTrue($a->save()); $this->assertEquals(1, $a->users->count()); $b->forget(); unset($b); $a->forget(); unset($a); }