本文整理汇总了PHP中Pimcore\Model\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createOrUpdateUser
/**
* @param array $config
*/
public function createOrUpdateUser($config = array())
{
$defaultConfig = array("username" => "admin", "password" => md5(microtime()));
$settings = array_replace_recursive($defaultConfig, $config);
if ($user = Model\User::getByName($settings["username"])) {
$user->delete();
}
$user = Model\User::create(array("parentId" => 0, "username" => $settings["username"], "password" => \Pimcore\Tool\Authentication::getPasswordHash($settings["username"], $settings["password"]), "active" => true));
$user->setAdmin(true);
$user->save();
}
示例2: installUser
private function installUser(\Pimcore\Model\User\Role $userRole)
{
$userM = new \Pimcore\Model\User();
$user = $userM->getByName('kunde');
if ($user !== FALSE) {
return $user;
}
$user = \Pimcore\Model\User::create(array('parentId' => 0, 'name' => 'kunde', 'password' => \Pimcore\Tool\Authentication::getPasswordHash('kunde', 'kunde'), 'active' => 1, 'language' => 'de', 'admin' => FALSE, 'roles' => array(0 => $userRole->getId())));
$user->save();
return $user;
}
示例3: lostpasswordAction
public function lostpasswordAction()
{
$username = $this->getParam("username");
if ($username) {
$user = User::getByName($username);
if (!$user instanceof User) {
$this->view->error = "user unknown";
} else {
if ($user->isActive()) {
if ($user->getEmail()) {
$token = Tool\Authentication::generateToken($username, $user->getPassword());
$uri = $this->getRequest()->getScheme() . "://" . $this->getRequest()->getHttpHost();
$loginUrl = $uri . "/admin/login/login/?username=" . $username . "&token=" . $token . "&reset=true";
try {
$mail = Tool::getMail(array($user->getEmail()), "Pimcore lost password service");
$mail->setIgnoreDebugMode(true);
$mail->setBodyText("Login to pimcore and change your password using the following link. This temporary login link will expire in 30 minutes: \r\n\r\n" . $loginUrl);
$mail->send();
$this->view->success = true;
} catch (\Exception $e) {
$this->view->error = "could not send email";
}
} else {
$this->view->error = "user has no email address";
}
} else {
$this->view->error = "user inactive";
}
}
}
}
示例4: setUser
/**
* @param Model\User $user
* @return $this
*/
public function setUser(Model\User $user)
{
$this->user = $user;
\Zend_Registry::set("pimcore_admin_user", $this->user);
$this->setLanguage($this->user->getLanguage());
return $this;
}
示例5: init
public function init()
{
$this->allParam = $this->getAllParams();
// set api key
$this->apiKey = isset($this->apiKey) ? $this->apiKey : \Pimcore\Model\User::getByName($this->userApiBridgeMagento)->getApiKey();
if (!$this->validateApiKey()) {
die;
// no any error info provided
}
// init api
$this->apiModel = new ApiBridgeMagento_Api();
}
示例6: mail
/**
*
*/
public function mail()
{
$conf = 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 = 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");
}
}
示例7: copyContents
/**
* @param $target
* @param $source
* @return mixed
* @throws \Exception
*/
public function copyContents($target, $source)
{
// check if the type is the same
if (get_class($source) != get_class($target)) {
throw new \Exception("Source and target have to be the same type");
}
if (!$source instanceof Asset\Folder) {
$target->setStream($source->getStream());
$target->setCustomSettings($source->getCustomSettings());
}
$target->setUserModification($this->_user->getId());
$target->setProperties($source->getProperties());
$target->save();
return $target;
}
示例8: copyContents
/**
* @param $target
* @param $source
* @return AbstractObject
* @throws \Exception
*/
public function copyContents($target, $source)
{
// check if the type is the same
if (get_class($source) != get_class($target)) {
throw new \Exception("Source and target have to be the same type");
}
//load all in case of lazy loading fields
self::loadAllObjectFields($source);
$new = clone $source;
$new->setChilds($target->getChilds());
$new->setId($target->getId());
$new->setPath($target->getPath());
$new->setKey($target->getKey());
$new->setParentId($target->getParentId());
$new->setScheduledTasks($source->getScheduledTasks());
$new->setProperties($source->getProperties());
$new->setUserModification($this->_user->getId());
$new->save();
$target = AbstractObject::getById($new->getId());
return $target;
}
示例9: getTokenLoginLinkAction
public function getTokenLoginLinkAction()
{
$user = User::getById($this->getParam("id"));
if ($user->isAdmin() && !$this->getUser()->isAdmin()) {
throw new \Exception("Only admin users are allowed to login as an admin user");
}
if ($user) {
$token = Tool\Authentication::generateToken($user->getName(), $user->getPassword());
$r = $this->getRequest();
$link = $r->getScheme() . "://" . $r->getHttpHost() . "/admin/login/login/?username=" . $user->getName() . "&token=" . $token;
$this->_helper->json(["link" => $link]);
}
}
示例10: getInfoDocBlock
/**
* @return string
*/
protected function getInfoDocBlock()
{
$cd = "";
$cd .= "/** ";
$cd .= "\n";
$cd .= "* Generated at: " . date('c') . "\n";
$cd .= "* Inheritance: " . ($this->getAllowInherit() ? "yes" : "no") . "\n";
$cd .= "* Variants: " . ($this->getAllowVariants() ? "yes" : "no") . "\n";
$user = Model\User::getById($this->getUserModification());
if ($user) {
$cd .= "* Changed by: " . $user->getName() . " (" . $user->getId() . ")" . "\n";
}
if (isset($_SERVER["REMOTE_ADDR"])) {
$cd .= "* IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
}
if ($this->getDescription()) {
$description = str_replace(["/**", "*/", "//"], "", $this->getDescription());
$description = str_replace("\n", "\n* ", $description);
$cd .= "* " . $description . "\n";
}
$cd .= "\n\n";
$cd .= "Fields Summary: \n";
$cd = $this->getInfoDocBlockForFields($this, $cd, 1);
$cd .= "*/ ";
return $cd;
}
示例11: setUserId
/**
* @param integer $userId
* @return void
*/
public function setUserId($userId)
{
if ($userId) {
if ($user = Model\User::getById($userId)) {
$this->userId = (int) $userId;
$this->setUser($user);
}
}
return $this;
}
示例12: noteListAction
public function noteListAction()
{
$this->checkPermission("notes_events");
$list = new Element\Note\Listing();
$list->setLimit($this->getParam("limit"));
$list->setOffset($this->getParam("start"));
$sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
if ($sortingSettings['orderKey'] && $sortingSettings['order']) {
$list->setOrderKey($sortingSettings['orderKey']);
$list->setOrder($sortingSettings['order']);
} else {
$list->setOrderKey(["date", "id"]);
$list->setOrder(["DESC", "DESC"]);
}
$conditions = [];
if ($this->getParam("filter")) {
$conditions[] = "(`title` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `description` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `type` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . ")";
}
if ($this->getParam("cid") && $this->getParam("ctype")) {
$conditions[] = "(cid = " . $list->quote($this->getParam("cid")) . " AND ctype = " . $list->quote($this->getParam("ctype")) . ")";
}
if (!empty($conditions)) {
$list->setCondition(implode(" AND ", $conditions));
}
$list->load();
$notes = [];
foreach ($list->getNotes() as $note) {
$cpath = "";
if ($note->getCid() && $note->getCtype()) {
if ($element = Element\Service::getElementById($note->getCtype(), $note->getCid())) {
$cpath = $element->getRealFullPath();
}
}
$e = ["id" => $note->getId(), "type" => $note->getType(), "cid" => $note->getCid(), "ctype" => $note->getCtype(), "cpath" => $cpath, "date" => $note->getDate(), "title" => $note->getTitle(), "description" => $note->getDescription()];
// prepare key-values
$keyValues = [];
if (is_array($note->getData())) {
foreach ($note->getData() as $name => $d) {
$type = $d["type"];
$data = $d["data"];
if ($type == "document" || $type == "object" || $type == "asset") {
if ($d["data"] instanceof Element\ElementInterface) {
$data = ["id" => $d["data"]->getId(), "path" => $d["data"]->getRealFullPath(), "type" => $d["data"]->getType()];
}
} elseif ($type == "date") {
if (is_object($d["data"])) {
$data = $d["data"]->getTimestamp();
}
}
$keyValue = ["type" => $type, "name" => $name, "data" => $data];
$keyValues[] = $keyValue;
}
}
$e["data"] = $keyValues;
// prepare user data
if ($note->getUser()) {
$user = Model\User::getById($note->getUser());
if ($user) {
$e["user"] = ["id" => $user->getId(), "name" => $user->getName()];
} else {
$e["user"] = "";
}
}
$notes[] = $e;
}
$this->_helper->json(["data" => $notes, "success" => true, "total" => $list->getTotalCount()]);
}
示例13: setUserId
/**
* @param integer $userId
* @return void
*/
public function setUserId($userId)
{
if (is_numeric($userId)) {
if ($user = User::getById($userId)) {
$this->userId = (int) $userId;
$this->setUser($user);
}
}
return $this;
}
示例14: initLogger
/**
* @static
*
*/
public static function initLogger()
{
// for forks, etc ...
\Logger::resetLoggers();
// try to load configuration
$conf = Config::getSystemConfig();
if ($conf) {
// redirect php error_log to /website/var/log/php.log
if ($conf->general->custom_php_logfile) {
$phpLog = PIMCORE_LOG_DIRECTORY . "/php.log";
if (!file_exists($phpLog)) {
touch($phpLog);
}
if (is_writable($phpLog)) {
ini_set("error_log", $phpLog);
ini_set("log_errors", "1");
}
}
}
if (!is_file(PIMCORE_LOG_DEBUG)) {
if (is_writable(dirname(PIMCORE_LOG_DEBUG))) {
File::put(PIMCORE_LOG_DEBUG, "AUTOCREATE\n");
}
}
$prios = [];
$availablePrios = \Logger::getAvailablePriorities();
if ($conf && $conf->general->debugloglevel) {
foreach ($availablePrios as $level) {
$prios[] = $level;
if ($level == $conf->general->debugloglevel) {
break;
}
}
\Logger::setPriorities($prios);
} else {
\Logger::setVerbosePriorities();
}
if (is_writable(PIMCORE_LOG_DEBUG)) {
// check for big logfile, empty it if it's bigger than about 200M
if (filesize(PIMCORE_LOG_DEBUG) > 200000000) {
rename(PIMCORE_LOG_DEBUG, PIMCORE_LOG_DEBUG . "-archive-" . date("m-d-Y-H-i"));
// archive log (will be cleaned up by maintenance)
File::put(PIMCORE_LOG_DEBUG, "");
}
// set default core logger (debug.log)
if (!empty($prios)) {
$loggerFile = new \Monolog\Logger('core');
$loggerFile->pushHandler(new \Monolog\Handler\StreamHandler(PIMCORE_LOG_DEBUG));
\Logger::addLogger($loggerFile);
}
$conf = Config::getSystemConfig();
if ($conf) {
//email logger
if (!empty($conf->general->logrecipient)) {
$user = User::getById($conf->general->logrecipient);
if ($user instanceof User && $user->isAdmin()) {
$email = $user->getEmail();
if (!empty($email)) {
$loggerMail = new \Monolog\Logger('email');
$mailHandler = new \Pimcore\Log\Handler\Mail($email);
$loggerMail->pushHandler(new \Monolog\Handler\BufferHandler($mailHandler));
\Logger::addLogger($loggerMail);
}
}
}
}
} else {
// try to use syslog instead
try {
$loggerSyslog = new \Monolog\Logger('core');
$loggerSyslog->pushHandler(new \Monolog\Handler\SyslogHandler("pimcore"));
\Logger::addLogger($loggerSyslog);
} catch (\Exception $e) {
// nothing to do here
}
}
// special request log -> if parameter pimcore_log is set
if (array_key_exists("pimcore_log", $_REQUEST) && self::inDebugMode()) {
if (empty($_REQUEST["pimcore_log"])) {
$requestLogName = date("Y-m-d_H-i-s");
} else {
$requestLogName = $_REQUEST["pimcore_log"];
}
$requestLogFile = dirname(PIMCORE_LOG_DEBUG) . "/request-" . $requestLogName . ".log";
if (!file_exists($requestLogFile)) {
File::put($requestLogFile, "");
}
$loggerRequest = new \Monolog\Logger('request');
$loggerRequest->pushHandler(new \Monolog\Handler\StreamHandler($requestLogFile));
\Logger::addLogger($loggerRequest);
\Logger::setVerbosePriorities();
}
}
示例15: verifyPassword
/**
* @param User $user
* @param $password
* @return bool
*/
public static function verifyPassword($user, $password)
{
$password = self::preparePlainTextPassword($user->getName(), $password);
if ($user->getPassword()) {
// do not allow logins for users without a password
if (password_verify($password, $user->getPassword())) {
if (password_needs_rehash($user->getPassword(), PASSWORD_DEFAULT)) {
$user->setPassword(self::getPasswordHash($user->getName(), $password));
$user->save();
}
return true;
}
}
return false;
}