当前位置: 首页>>代码示例>>PHP>>正文


PHP Authentication::authenticatePlaintext方法代码示例

本文整理汇总了PHP中Pimcore\Tool\Authentication::authenticatePlaintext方法的典型用法代码示例。如果您正苦于以下问题:PHP Authentication::authenticatePlaintext方法的具体用法?PHP Authentication::authenticatePlaintext怎么用?PHP Authentication::authenticatePlaintext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pimcore\Tool\Authentication的用法示例。


在下文中一共展示了Authentication::authenticatePlaintext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loginAction

 public function loginAction()
 {
     $user = null;
     try {
         \Pimcore::getEventManager()->trigger("admin.login.login.authenticate", $this, ["username" => $this->getParam("username"), "password" => $this->getParam("password")]);
         $user = $this->getUser();
         if (!$user instanceof User) {
             if ($this->getParam("password")) {
                 $user = Tool\Authentication::authenticatePlaintext($this->getParam("username"), $this->getParam("password"));
                 if (!$user) {
                     throw new \Exception("Invalid username or password");
                 }
             } else {
                 if ($this->getParam("token")) {
                     $user = Tool\Authentication::authenticateToken($this->getParam("username"), $this->getParam("token"));
                     if (!$user) {
                         throw new \Exception("Invalid username or token");
                     }
                     // save the information to session when the user want's to reset the password
                     // this is because otherwise the old password is required => see also PIMCORE-1468
                     if ($this->getParam("reset")) {
                         Tool\Session::useSession(function ($adminSession) {
                             $adminSession->password_reset = true;
                         });
                     }
                 } else {
                     throw new \Exception("Invalid authentication method, must be either password or token");
                 }
             }
         }
     } catch (\Exception $e) {
         //see if module or plugin authenticates user
         \Pimcore::getEventManager()->trigger("admin.login.login.failed", $this, ["username" => $this->getParam("username"), "password" => $this->getParam("password")]);
         $user = $this->getUser();
         if (!$user instanceof User) {
             $this->writeLogFile($this->getParam("username"), $e->getMessage());
             \Logger::info("Login failed: " . $e);
         }
     }
     if ($user instanceof User && $user->getId() && $user->isActive() && $user->getPassword()) {
         Tool\Session::useSession(function ($adminSession) use($user) {
             $adminSession->user = $user;
             Tool\Session::regenerateId();
         });
         if ($this->getParam('deeplink')) {
             $this->redirect('/admin/login/deeplink/?' . $this->getParam('deeplink'));
         } else {
             $this->redirect("/admin/?_dc=" . time());
         }
     } else {
         $this->redirect("/admin/login/?auth_failed=true");
         exit;
     }
 }
开发者ID:elavarasann,项目名称:pimcore,代码行数:54,代码来源:LoginController.php

示例2: updateCurrentUserAction

 public function updateCurrentUserAction()
 {
     $this->protectCSRF();
     $user = $this->getUser();
     if ($user != null) {
         if ($user->getId() == $this->getParam("id")) {
             $values = \Zend_Json::decode($this->getParam("data"));
             unset($values["name"]);
             unset($values["id"]);
             unset($values["admin"]);
             unset($values["permissions"]);
             unset($values["roles"]);
             unset($values["active"]);
             if (!empty($values["new_password"])) {
                 $oldPasswordCheck = false;
                 if (empty($values["old_password"])) {
                     // if the user want to reset the password, the old password isn't required
                     $oldPasswordCheck = Tool\Session::useSession(function ($adminSession) use($oldPasswordCheck) {
                         if ($adminSession->password_reset) {
                             return true;
                         }
                         return false;
                     });
                 } else {
                     // the password has to match
                     $checkUser = Tool\Authentication::authenticatePlaintext($user->getName(), $values["old_password"]);
                     if ($checkUser) {
                         $oldPasswordCheck = true;
                     }
                 }
                 if ($oldPasswordCheck && $values["new_password"] == $values["retype_password"]) {
                     $values["password"] = Tool\Authentication::getPasswordHash($user->getName(), $values["new_password"]);
                 } else {
                     $this->_helper->json(["success" => false, "message" => "password_cannot_be_changed"]);
                 }
             }
             $user->setValues($values);
             $user->save();
             $this->_helper->json(["success" => true]);
         } else {
             \Logger::warn("prevented save current user, because ids do not match. ");
             $this->_helper->json(false);
         }
     } else {
         $this->_helper->json(false);
     }
 }
开发者ID:solverat,项目名称:pimcore,代码行数:47,代码来源:UserController.php


注:本文中的Pimcore\Tool\Authentication::authenticatePlaintext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。