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


PHP Context::setUser方法代码示例

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


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

示例1: loginCheck

 /**
  * Returns the logged in user, or default user if not logged in
  *
  * @param \thebuggenie\core\framework\Request $request
  * @param \thebuggenie\core\framework\Action  $action
  *
  * @return \thebuggenie\core\entities\User
  */
 public static function loginCheck(framework\Request $request, framework\Action $action)
 {
     try {
         $authentication_method = $action->getAuthenticationMethodForAction(framework\Context::getRouting()->getCurrentRouteAction());
         $user = null;
         $external = false;
         switch ($authentication_method) {
             case framework\Action::AUTHENTICATION_METHOD_ELEVATED:
             case framework\Action::AUTHENTICATION_METHOD_CORE:
                 $username = $request['tbg3_username'];
                 $password = $request['tbg3_password'];
                 if ($authentication_method == framework\Action::AUTHENTICATION_METHOD_ELEVATED) {
                     $elevated_password = $request['tbg3_elevated_password'];
                 }
                 $raw = true;
                 // If no username and password specified, check if we have a session that exists already
                 if ($username === null && $password === null) {
                     if (framework\Context::getRequest()->hasCookie('tbg3_username') && framework\Context::getRequest()->hasCookie('tbg3_password')) {
                         $username = framework\Context::getRequest()->getCookie('tbg3_username');
                         $password = framework\Context::getRequest()->getCookie('tbg3_password');
                         $user = self::getB2DBTable()->getByUsername($username);
                         if ($authentication_method == framework\Action::AUTHENTICATION_METHOD_ELEVATED) {
                             $elevated_password = framework\Context::getRequest()->getCookie('tbg3_elevated_password');
                             if ($user instanceof User && !$user->hasPasswordHash($password)) {
                                 $user = null;
                             } else {
                                 if ($user instanceof User && !$user->hasPasswordHash($elevated_password)) {
                                     framework\Context::setUser($user);
                                     framework\Context::getRouting()->setCurrentRouteName('elevated_login_page');
                                     throw new framework\exceptions\ElevatedLoginException('reenter');
                                 }
                             }
                         } else {
                             if ($user instanceof User && !$user->hasPasswordHash($password)) {
                                 $user = null;
                             }
                         }
                         if (!$user instanceof User) {
                             framework\Context::logout();
                             throw new \Exception('No such login');
                         }
                     }
                 }
                 // If we have authentication details, validate them
                 if (framework\Settings::isUsingExternalAuthenticationBackend() && $username !== null && $password !== null) {
                     $external = true;
                     framework\Logging::log('Authenticating with backend: ' . framework\Settings::getAuthenticationBackend(), 'auth', framework\Logging::LEVEL_INFO);
                     try {
                         $mod = framework\Context::getModule(framework\Settings::getAuthenticationBackend());
                         if ($mod->getType() !== Module::MODULE_AUTH) {
                             framework\Logging::log('Auth module is not the right type', 'auth', framework\Logging::LEVEL_FATAL);
                         }
                         if (framework\Context::getRequest()->hasCookie('tbg3_username') && framework\Context::getRequest()->hasCookie('tbg3_password')) {
                             $user = $mod->verifyLogin($username, $password);
                         } else {
                             $user = $mod->doLogin($username, $password);
                         }
                         if (!$user instanceof User) {
                             // Invalid
                             framework\Context::logout();
                             throw new \Exception('No such login');
                             //framework\Context::getResponse()->headerRedirect(framework\Context::getRouting()->generate('login'));
                         }
                     } catch (\Exception $e) {
                         throw $e;
                     }
                 } elseif (framework\Settings::isUsingExternalAuthenticationBackend()) {
                     $external = true;
                     framework\Logging::log('Authenticating without credentials with backend: ' . framework\Settings::getAuthenticationBackend(), 'auth', framework\Logging::LEVEL_INFO);
                     try {
                         $mod = framework\Context::getModule(framework\Settings::getAuthenticationBackend());
                         if ($mod->getType() !== Module::MODULE_AUTH) {
                             framework\Logging::log('Auth module is not the right type', 'auth', framework\Logging::LEVEL_FATAL);
                         }
                         $user = $mod->doAutoLogin();
                         if ($user == false) {
                             // Invalid
                             framework\Context::logout();
                             throw new \Exception('No such login');
                             //framework\Context::getResponse()->headerRedirect(framework\Context::getRouting()->generate('login'));
                         } else {
                             if ($user == true) {
                                 $user = null;
                             }
                         }
                     } catch (\Exception $e) {
                         throw $e;
                     }
                 } elseif ($username !== null && $password !== null && !$user instanceof User) {
                     $external = false;
                     framework\Logging::log('Using internal authentication', 'auth', framework\Logging::LEVEL_INFO);
                     $user = self::getB2DBTable()->getByUsername($username);
//.........这里部分代码省略.........
开发者ID:underblaze,项目名称:thebuggenie-4.1.0,代码行数:101,代码来源:User.php

示例2: processCommit

 public static function processCommit(\thebuggenie\core\entities\Project $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null, \Closure $callback = null)
 {
     $output = '';
     framework\Context::setCurrentProject($project);
     if ($project->isArchived()) {
         return;
     }
     if (Commits::getTable()->isProjectCommitProcessed($new_rev, $project->getID())) {
         return;
     }
     try {
         framework\Context::getI18n();
     } catch (\Exception $e) {
         framework\Context::reinitializeI18n(null);
     }
     // Is VCS Integration enabled?
     if (framework\Settings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == self::MODE_DISABLED) {
         $output .= '[VCS ' . $project->getKey() . '] This project does not use VCS Integration' . "\n";
         return $output;
     }
     // Parse the commit message, and obtain the issues and transitions for issues.
     $parsed_commit = \thebuggenie\core\entities\Issue::getIssuesFromTextByRegex($commit_msg);
     $issues = $parsed_commit["issues"];
     $transitions = $parsed_commit["transitions"];
     // Build list of affected files
     $file_lines = preg_split('/[\\n\\r]+/', $changed);
     $files = array();
     foreach ($file_lines as $aline) {
         $action = mb_substr($aline, 0, 1);
         if ($action == "A" || $action == "U" || $action == "D" || $action == "M") {
             $theline = trim(mb_substr($aline, 1));
             $files[] = array($action, $theline);
         }
     }
     // Find author of commit, fallback is guest
     /*
      * Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format
      * Joe Bloggs <me@example.com>, instead of a classic username. Therefore a user will be found via 4 queries:
      * a) First we extract the email if there is one, and find a user with that email
      * b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email)
      * c) the username or full name is checked against the friendly name field
      * d) and if we still havent found one, then we check against the username
      * e) and if we STILL havent found one, we use the guest user
      */
     // a)
     $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($author);
     if (!$user instanceof \thebuggenie\core\entities\User && preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
         $email = $matches[0];
         // a2)
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($email);
         if (!$user instanceof \thebuggenie\core\entities\User) {
             // Not found by email
             preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
             $author = $matches[0];
         }
     }
     // b)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByRealname($author);
     }
     // c)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByBuddyname($author);
     }
     // d)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($author);
     }
     // e)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = framework\Settings::getDefaultUser();
     }
     framework\Context::setUser($user);
     framework\Settings::forceSettingsReload();
     framework\Context::cacheAllPermissions();
     $output .= '[VCS ' . $project->getKey() . '] Commit to be logged by user ' . $user->getName() . "\n";
     if ($date == null) {
         $date = NOW;
     }
     // Create the commit data
     $commit = new Commit();
     $commit->setAuthor($user);
     $commit->setDate($date);
     $commit->setLog($commit_msg);
     $commit->setPreviousRevision($old_rev);
     $commit->setRevision($new_rev);
     $commit->setProject($project);
     if ($branch !== null) {
         $data = 'branch:' . $branch;
         $commit->setMiscData($data);
     }
     if ($callback !== null) {
         $commit = $callback($commit);
     }
     $commit->save();
     $output .= '[VCS ' . $project->getKey() . '] Commit logged with revision ' . $commit->getRevision() . "\n";
     // Iterate over affected issues and update them.
     foreach ($issues as $issue) {
         $inst = new IssueLink();
         $inst->setIssue($issue);
//.........这里部分代码省略.........
开发者ID:AzerothShard,项目名称:thebuggenie,代码行数:101,代码来源:Vcs_integration.php

示例3: runDoLogin


//.........这里部分代码省略.........
                     }
                     $user = $this->getUser();
                 } else {
                     $user = entities\User::getByOpenID($openid->identity);
                 }
                 if ($user instanceof entities\User) {
                     $attributes = $openid->getAttributes();
                     $email = array_key_exists('contact/email', $attributes) ? $attributes['contact/email'] : null;
                     if (!$user->getEmail()) {
                         if (array_key_exists('contact/email', $attributes)) {
                             $user->setEmail($attributes['contact/email']);
                         }
                         if (array_key_exists('namePerson/first', $attributes)) {
                             $user->setRealname($attributes['namePerson/first']);
                         }
                         if (array_key_exists('namePerson/friendly', $attributes)) {
                             $user->setBuddyname($attributes['namePerson/friendly']);
                         }
                         if (!$user->getNickname() || $user->isOpenIdLocked()) {
                             $user->setBuddyname($user->getEmail());
                         }
                         if (!$user->getRealname()) {
                             $user->setRealname($user->getBuddyname());
                         }
                         $user->save();
                     }
                     if (!$user->hasOpenIDIdentity($openid->identity)) {
                         tables\OpenIdAccounts::getTable()->addIdentity($openid->identity, $user->getID());
                     }
                     framework\Context::getResponse()->setCookie('tbg3_password', $user->getPassword());
                     framework\Context::getResponse()->setCookie('tbg3_username', $user->getUsername());
                     $user->setOnline();
                     $user->save();
                     if ($this->checkScopeMembership($user)) {
                         return true;
                     }
                     return $this->forward(framework\Context::getRouting()->generate(framework\Settings::get('returnfromlogin')));
                 } else {
                     $this->error = framework\Context::getI18n()->__("Didn't recognize this OpenID. Please log in using your username and password, associate it with your user account in your account settings and try again.");
                 }
             } else {
                 $this->error = framework\Context::getI18n()->__("Could not validate against the OpenID provider");
             }
         } catch (\Exception $e) {
             $this->error = framework\Context::getI18n()->__("Could not validate against the OpenID provider: %message", array('%message' => htmlentities($e->getMessage(), ENT_COMPAT, framework\Context::getI18n()->getCharset())));
         }
     } elseif ($request->getMethod() == framework\Request::POST) {
         try {
             if ($request->hasParameter('tbg3_username') && $request->hasParameter('tbg3_password') && $request['tbg3_username'] != '' && $request['tbg3_password'] != '') {
                 $user = entities\User::loginCheck($request, $this);
                 $user->setOnline();
                 $user->save();
                 framework\Context::setUser($user);
                 if ($this->checkScopeMembership($user)) {
                     return true;
                 }
                 if ($request->hasParameter('return_to')) {
                     $forward_url = $request['return_to'];
                 } else {
                     if (framework\Settings::get('returnfromlogin') == 'referer') {
                         $forward_url = $request->getParameter('tbg3_referer', framework\Context::getRouting()->generate('dashboard'));
                     } else {
                         $forward_url = framework\Context::getRouting()->generate(framework\Settings::get('returnfromlogin'));
                     }
                 }
                 $forward_url = htmlentities($forward_url, ENT_COMPAT, framework\Context::getI18n()->getCharset());
             } else {
                 throw new \Exception('Please enter a username and password');
             }
         } catch (\Exception $e) {
             if ($request->isAjaxCall()) {
                 $this->getResponse()->setHttpStatus(401);
                 framework\Logging::log($e->getMessage(), 'openid', framework\Logging::LEVEL_WARNING_RISK);
                 return $this->renderJSON(array("error" => $i18n->__("Invalid login details")));
             } else {
                 $this->forward403($e->getMessage());
             }
         }
     } else {
         if ($request->isAjaxCall()) {
             $this->getResponse()->setHttpStatus(401);
             return $this->renderJSON(array("error" => $i18n->__('Please enter a username and password')));
         } else {
             $this->forward403($i18n->__('Please enter a username and password'));
         }
     }
     if (!isset($user)) {
         $this->forward403($i18n->__("Invalid login details"));
     }
     if ($this->checkScopeMembership($user)) {
         return true;
     }
     $user->setOnline();
     $user->save();
     if ($request->isAjaxCall()) {
         return $this->renderJSON(array('forward' => $forward_url));
     } else {
         $this->forward($this->getRouting()->generate('account'));
     }
 }
开发者ID:nrensen,项目名称:thebuggenie,代码行数:101,代码来源:Main.php


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