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


PHP Security::setUser方法代码示例

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


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

示例1: loginAction

 protected function loginAction($options = array())
 {
     // Default option value
     // passwordEncrypt = true
     $options["passwordEncrypt"] = isset($options["passwordEncrypt"]) ? $options["passwordEncrypt"] : true;
     // force l'envoi de la clé
     $this->testKey(true);
     if (empty($_REQUEST->login) || empty($_REQUEST->password)) {
         throw new \Core\CException("Login failed");
     }
     $db = \Core\Db::create($this->getParams("database"));
     $userTable = $db->quoteTable($this->getParams("userTable", "table"));
     $idField = $db->quoteField($this->getParams("userTable", "idField"));
     $loginField = $db->quoteField($this->getParams("userTable", "loginField"));
     $passwordField = $db->quoteField($this->getParams("userTable", "passwordField"));
     $passwordFn = $this->getParams("userTable", "passwordFn");
     $nameField = $db->quoteField($this->getParams("userTable", "nameField"));
     $roleTable = $db->quoteTable($this->getParams("roleTable", "table"));
     $roleId = $db->quoteField($this->getParams("roleTable", "idField"));
     $roleField = $db->quoteField($this->getParams("roleTable", "roleField"));
     $linkTable = $db->quoteTable($this->getParams("linkTable", "table"));
     $linkUser = $db->quoteField($this->getParams("linkTable", "userId"));
     $linkRole = $db->quoteField($this->getParams("linkTable", "roleId"));
     //if(! \Core\CString::isValidMd5($_REQUEST->password)) {
     if ($options["passwordEncrypt"] === true && !empty($passwordFn)) {
         $_REQUEST->password = call_user_func($passwordFn, $_REQUEST->password);
     }
     $randId = strtolower(\Core\CString::rand(5));
     $sql = "\n            SELECT\n                {$idField} as userid_{$randId},\n                {$loginField} as userlogin_{$randId},\n                {$nameField} as username_{$randId},\n                u.*\n            FROM\n                {$userTable} u\n            WHERE\n                u.{$loginField} = :user\n                AND u.{$passwordField} = :Login\n        ";
     $res = $db->selectRow($sql, array(":user" => $_REQUEST->login, ":Login" => $_REQUEST->password));
     if (!empty($res)) {
         \Core\Security::setUserId($res["userid_" . $randId]);
         \Core\Security::setUserLogin($res["userlogin_" . $randId]);
         \Core\Security::setUserName($res["username_" . $randId]);
         $resUser = $res;
         unset($resUser["userid_" . $randId]);
         unset($resUser["userlogin_" . $randId]);
         unset($resUser["username_" . $randId]);
         \Core\Security::setUser($resUser);
         // Reccup role
         $sql = "\n                SELECT \n                    r.{$roleField} as role\n                FROM\n                    {$roleTable} r\n               JOIN\n                    {$linkTable} l\n                        ON r.{$roleId} = l.{$linkRole}\n               JOIN\n                    {$userTable} u\n                        ON u.{$idField} = l.{$linkUser}\n               WHERE\n                    u.{$idField} = :userid\n            ";
         $resRole = $db->select($sql, array(":userid" => $res["userid_" . $randId]));
         if (!empty($resRole)) {
             foreach ($resRole as $role) {
                 \Core\Security::AddRole($role["role"]);
             }
         }
         // St cookie for Autologin
         if (isset($_REQUEST->autologin) && $_REQUEST->autologin == "1") {
             $c = array($_REQUEST->login, $_REQUEST->password);
             $c = serialize($c);
             $c = \Core\CString::encrypt($c, $this->cookieName);
             setcookie($this->cookieName, $c, time() + $this->cookieTime, "/");
         }
     } else {
         $this->logout(new \Core\Request());
         throw new \Core\CException("Login failed");
     }
 }
开发者ID:solofo-ralitera,项目名称:oron,代码行数:59,代码来源:Login.php


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