本文整理汇总了PHP中Pimcore\Model\User::getByName方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getByName方法的具体用法?PHP User::getByName怎么用?PHP User::getByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Model\User
的用法示例。
在下文中一共展示了User::getByName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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";
}
}
}
}
示例3: 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();
}
示例4: authenticateToken
/**
* @param $username
* @param $token
* @param bool $adminRequired
* @return null|User
*/
public static function authenticateToken($username, $token, $adminRequired = false)
{
$user = User::getByName($username);
if (self::isValidUser($user)) {
if ($adminRequired and !$user->isAdmin()) {
return null;
}
$passwordHash = $user->getPassword();
$decrypted = self::tokenDecrypt($passwordHash, $token);
$timestamp = $decrypted[0];
$timeZone = date_default_timezone_get();
date_default_timezone_set("UTC");
if ($timestamp > time() or $timestamp < time() - 60 * 30) {
return null;
}
date_default_timezone_set($timeZone);
return $user;
}
return null;
}
示例5: enableTestMode
/**
* Enables the test mode. X-pimcore-unit-test-request=true header will be sent.
*/
public function enableTestMode()
{
$this->client->setHeaders("X-pimcore-unit-test-request", "true");
if (!$this->getApiKey()) {
$username = "rest";
$password = $username;
$user = User::getByName("{$username}");
if (!$user) {
$apikey = md5(time()) . md5($username);
$user = User::create(array("parentId" => 0, "username" => "rest", "password" => \Pimcore\Tool\Authentication::getPasswordHash($username, $username), "active" => true, "apiKey" => $apikey, "admin" => true));
}
$apikey = $user->getApiKey();
$this->setApiKey($apikey);
}
$this->setTestMode(true);
}