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


PHP User::getByEmail方法代码示例

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


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

示例1: runDoLogin

 /**
  * Do login (AJAX call)
  *
  * @Route(name="login", url="/do/login")
  * @AnonymousRoute
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runDoLogin(framework\Request $request)
 {
     $i18n = framework\Context::getI18n();
     $options = $request->getParameters();
     $forward_url = framework\Context::getRouting()->generate('home');
     if ($request->hasParameter('persona') && $request['persona'] == 'true') {
         $url = 'https://verifier.login.persona.org/verify';
         $assert = filter_input(INPUT_POST, 'assertion', FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
         //Use the $_POST superglobal array for PHP < 5.2 and write your own filter
         $params = 'assertion=' . urlencode($assert) . '&audience=' . urlencode(framework\Context::getURLhost() . ':80');
         $ch = curl_init();
         $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POST => 2, CURLOPT_POSTFIELDS => $params);
         curl_setopt_array($ch, $options);
         $result = curl_exec($ch);
         curl_close($ch);
         $details = json_decode($result);
         $user = null;
         if ($details->status == 'okay') {
             $user = entities\User::getByEmail($details->email);
             if ($user instanceof entities\User) {
                 framework\Context::getResponse()->setCookie('tbg3_password', $user->getPassword());
                 framework\Context::getResponse()->setCookie('tbg3_username', $user->getUsername());
                 framework\Context::getResponse()->setCookie('tbg3_persona_session', true);
                 $user->setOnline();
                 $user->save();
                 return $this->renderJSON(array('status' => 'login ok', 'redirect' => in_array($request['referer_route'], array('home', 'login'))));
             }
         }
         if (!$user instanceof entities\User) {
             $this->getResponse()->setHttpStatus(401);
             $this->renderJSON(array('message' => $this->getI18n()->__('Invalid login')));
         }
         return;
     }
     if (framework\Settings::isOpenIDavailable()) {
         $openid = new \LightOpenID(framework\Context::getRouting()->generate('login_page', array(), false));
     }
     if (framework\Settings::isOpenIDavailable() && !$openid->mode && $request->isPost() && $request->hasParameter('openid_identifier')) {
         $openid->identity = $request->getRawParameter('openid_identifier');
         $openid->required = array('contact/email');
         $openid->optional = array('namePerson/first', 'namePerson/friendly');
         return $this->forward($openid->authUrl());
     } elseif (framework\Settings::isOpenIDavailable() && $openid->mode == 'cancel') {
         $this->error = framework\Context::getI18n()->__("OpenID authentication cancelled");
     } elseif (framework\Settings::isOpenIDavailable() && $openid->mode) {
         try {
             if ($openid->validate()) {
                 if ($this->getUser()->isAuthenticated() && !$this->getUser()->isGuest()) {
                     if (tables\OpenIdAccounts::getTable()->getUserIDfromIdentity($openid->identity)) {
                         framework\Context::setMessage('openid_used', true);
                         throw new \Exception('OpenID already in use');
                     }
                     $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 {
//.........这里部分代码省略.........
开发者ID:nrensen,项目名称:thebuggenie,代码行数:101,代码来源:Main.php


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