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


PHP PhabricatorUser::loadOneWithEmailAddress方法代码示例

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


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

示例1: loadSender

 /**
  * Identifies the sender's user account for a piece of received mail. Note
  * that this method does not validate that the sender is who they say they
  * are, just that they've presented some credential which corresponds to a
  * recognizable user.
  */
 public function loadSender(PhabricatorMetaMTAReceivedMail $mail)
 {
     $raw_from = $mail->getHeader('From');
     $from = self::getRawAddress($raw_from);
     $reasons = array();
     // Try to find a user with this email address.
     $user = PhabricatorUser::loadOneWithEmailAddress($from);
     if ($user) {
         return $user;
     } else {
         $reasons[] = pht('This email was sent from "%s", but that address is not recognized by ' . 'Phabricator and does not correspond to any known user account.', $raw_from);
     }
     // If we missed on "From", try "Reply-To" if we're configured for it.
     $raw_reply_to = $mail->getHeader('Reply-To');
     if (strlen($raw_reply_to)) {
         $reply_to_key = 'metamta.insecure-auth-with-reply-to';
         $allow_reply_to = PhabricatorEnv::getEnvConfig($reply_to_key);
         if ($allow_reply_to) {
             $reply_to = self::getRawAddress($raw_reply_to);
             $user = PhabricatorUser::loadOneWithEmailAddress($reply_to);
             if ($user) {
                 return $user;
             } else {
                 $reasons[] = pht('Phabricator is configured to authenticate users using the ' . '"Reply-To" header, but the reply address ("%s") on this ' . 'message does not correspond to any known user account.', $raw_reply_to);
             }
         } else {
             $reasons[] = pht('(Phabricator is not configured to authenticate users using the ' . '"Reply-To" header, so it was ignored.)');
         }
     }
     // If we don't know who this user is, load or create an external user
     // account for them if we're configured for it.
     $email_key = 'phabricator.allow-email-users';
     $allow_email_users = PhabricatorEnv::getEnvConfig($email_key);
     if ($allow_email_users) {
         $from_obj = new PhutilEmailAddress($from);
         $xuser = id(new PhabricatorExternalAccountQuery())->setViewer($this->getViewer())->withAccountTypes(array('email'))->withAccountDomains(array($from_obj->getDomainName(), 'self'))->withAccountIDs(array($from_obj->getAddress()))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->loadOneOrCreate();
         return $xuser->getPhabricatorUser();
     } else {
         $reasons[] = pht('Phabricator is also not configured to allow unknown external users ' . 'to send mail to the system using just an email address.');
         $reasons[] = pht('To interact with Phabricator, add this address ("%s") to your ' . 'account.', $raw_from);
     }
     if ($this->getApplicationEmail()) {
         $application_email = $this->getApplicationEmail();
         $default_user_phid = $application_email->getConfigValue(PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR);
         if ($default_user_phid) {
             $user = id(new PhabricatorUser())->loadOneWhere('phid = %s', $default_user_phid);
             if ($user) {
                 return $user;
             }
         }
         $reasons[] = pht("Phabricator is misconfigured, the application email " . "'%s' is set to user '%s' but that user does not exist.", $application_email->getAddress(), $default_user_phid);
     }
     $reasons = implode("\n\n", $reasons);
     throw new PhabricatorMetaMTAReceivedMailProcessingException(MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, $reasons);
 }
开发者ID:pugong,项目名称:phabricator,代码行数:61,代码来源:PhabricatorMailReceiver.php

示例2: processLoginRequest

 public function processLoginRequest(PhabricatorAuthLoginController $controller)
 {
     $request = $controller->getRequest();
     $viewer = $request->getUser();
     $require_captcha = false;
     $captcha_valid = false;
     if (AphrontFormRecaptchaControl::isRecaptchaEnabled()) {
         $failed_attempts = PhabricatorUserLog::loadRecentEventsFromThisIP(PhabricatorUserLog::ACTION_LOGIN_FAILURE, 60 * 15);
         if (count($failed_attempts) > 5) {
             $require_captcha = true;
             $captcha_valid = AphrontFormRecaptchaControl::processCaptcha($request);
         }
     }
     $response = null;
     $account = null;
     $log_user = null;
     if ($request->isFormPost()) {
         if (!$require_captcha || $captcha_valid) {
             $username_or_email = $request->getStr('username');
             if (strlen($username_or_email)) {
                 $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username_or_email);
                 if (!$user) {
                     $user = PhabricatorUser::loadOneWithEmailAddress($username_or_email);
                 }
                 if ($user) {
                     $envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
                     if ($user->comparePassword($envelope)) {
                         $account = $this->loadOrCreateAccount($user->getPHID());
                         $log_user = $user;
                         // If the user's password is stored using a less-than-optimal
                         // hash, upgrade them to the strongest available hash.
                         $hash_envelope = new PhutilOpaqueEnvelope($user->getPasswordHash());
                         if (PhabricatorPasswordHasher::canUpgradeHash($hash_envelope)) {
                             $user->setPassword($envelope);
                             $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                             $user->save();
                             unset($unguarded);
                         }
                     }
                 }
             }
         }
     }
     if (!$account) {
         if ($request->isFormPost()) {
             $log = PhabricatorUserLog::initializeNewLog(null, $log_user ? $log_user->getPHID() : null, PhabricatorUserLog::ACTION_LOGIN_FAILURE);
             $log->save();
         }
         $request->clearCookie(PhabricatorCookies::COOKIE_USERNAME);
         $response = $controller->buildProviderPageResponse($this, $this->renderPasswordLoginForm($request, $require_captcha, $captcha_valid));
     }
     return array($account, $response);
 }
开发者ID:hrb518,项目名称:phabricator,代码行数:53,代码来源:PhabricatorPasswordAuthProvider.php

示例3: lookupPublicUser

 private function lookupPublicUser()
 {
     $from = idx($this->headers, 'from');
     $from = $this->getRawEmailAddress($from);
     $user = PhabricatorUser::loadOneWithEmailAddress($from);
     // If Phabricator is configured to allow "Reply-To" authentication, try
     // the "Reply-To" address if we failed to match the "From" address.
     $config_key = 'metamta.insecure-auth-with-reply-to';
     $allow_reply_to = PhabricatorEnv::getEnvConfig($config_key);
     if (!$user && $allow_reply_to) {
         $reply_to = idx($this->headers, 'reply-to');
         $reply_to = $this->getRawEmailAddress($reply_to);
         if ($reply_to) {
             $user = PhabricatorUser::loadOneWithEmailAddress($reply_to);
         }
     }
     return $user;
 }
开发者ID:rudimk,项目名称:phabricator,代码行数:18,代码来源:PhabricatorMetaMTAReceivedMail.php

示例4: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     if ($request->getUser()->getPHID()) {
         // Kick the user out if they're already logged in.
         return id(new AphrontRedirectResponse())->setURI('/');
     }
     if ($request->isConduit()) {
         // A common source of errors in Conduit client configuration is getting
         // the request path wrong. The client will end up here, so make some
         // effort to give them a comprehensible error message.
         $request_path = $this->getRequest()->getPath();
         $conduit_path = '/api/<method>';
         $example_path = '/api/conduit.ping';
         $message = "ERROR: You are making a Conduit API request to '{$request_path}', " . "but the correct HTTP request path to use in order to access a " . "Conduit method is '{$conduit_path}' (for example, " . "'{$example_path}'). Check your configuration.";
         return id(new AphrontPlainTextResponse())->setContent($message);
     }
     $error_view = null;
     if ($request->getCookie('phusr') && $request->getCookie('phsid')) {
         // The session cookie is invalid, so clear it.
         $request->clearCookie('phusr');
         $request->clearCookie('phsid');
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Invalid Session');
         $error_view->setErrors(array("Your login session is invalid. Try logging in again. If that " . "doesn't work, clear your browser cookies."));
     }
     $next_uri_path = $this->getRequest()->getPath();
     if ($next_uri_path == '/login/') {
         $next_uri = '/';
     } else {
         $next_uri = $this->getRequest()->getRequestURI();
     }
     if (!$request->isFormPost()) {
         $request->setCookie('next_uri', $next_uri);
     }
     $password_auth = PhabricatorEnv::getEnvConfig('auth.password-auth-enabled');
     $username_or_email = $request->getCookie('phusr');
     $forms = array();
     $errors = array();
     if ($password_auth) {
         $require_captcha = false;
         $e_captcha = true;
         if ($request->isFormPost()) {
             if (AphrontFormRecaptchaControl::isRecaptchaEnabled()) {
                 $failed_attempts = PhabricatorUserLog::loadRecentEventsFromThisIP(PhabricatorUserLog::ACTION_LOGIN_FAILURE, 60 * 15);
                 if (count($failed_attempts) > 5) {
                     $require_captcha = true;
                     if (!AphrontFormRecaptchaControl::processCaptcha($request)) {
                         if (AphrontFormRecaptchaControl::hasCaptchaResponse($request)) {
                             $e_captcha = 'Invalid';
                             $errors[] = 'CAPTCHA was not entered correctly.';
                         } else {
                             $e_captcha = 'Required';
                             $errors[] = 'Too many login failures recently. You must ' . 'submit a CAPTCHA with your login request.';
                         }
                     }
                 }
             }
             $username_or_email = $request->getStr('username_or_email');
             $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username_or_email);
             if (!$user) {
                 $user = PhabricatorUser::loadOneWithEmailAddress($username_or_email);
             }
             if (!$errors) {
                 // Perform username/password tests only if we didn't get rate limited
                 // by the CAPTCHA.
                 $envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
                 if (!$user || !$user->comparePassword($envelope)) {
                     $errors[] = 'Bad username/password.';
                 }
             }
             if (!$errors) {
                 $session_key = $user->establishSession('web');
                 $request->setCookie('phusr', $user->getUsername());
                 $request->setCookie('phsid', $session_key);
                 $uri = new PhutilURI('/login/validate/');
                 $uri->setQueryParams(array('phusr' => $user->getUsername()));
                 return id(new AphrontRedirectResponse())->setURI((string) $uri);
             } else {
                 $log = PhabricatorUserLog::newLog(null, $user, PhabricatorUserLog::ACTION_LOGIN_FAILURE);
                 $log->save();
                 $request->clearCookie('phusr');
                 $request->clearCookie('phsid');
             }
         }
         if ($errors) {
             $error_view = new AphrontErrorView();
             $error_view->setTitle('Login Failed');
             $error_view->setErrors($errors);
         }
         $form = new AphrontFormView();
         $form->setUser($request->getUser())->setAction('/login/')->appendChild(id(new AphrontFormTextControl())->setLabel('Username/Email')->setName('username_or_email')->setValue($username_or_email))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Password')->setName('password')->setCaption('<a href="/login/email/">' . 'Forgot your password? / Email Login</a>'));
         if ($require_captcha) {
             $form->appendChild(id(new AphrontFormRecaptchaControl())->setError($e_captcha));
         }
         $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Login'));
         //    $panel->setCreateButton('Register New Account', '/login/register/');
         $forms['Phabricator Login'] = $form;
     }
     $ldap_provider = new PhabricatorLDAPProvider();
//.........这里部分代码省略.........
开发者ID:neoxen,项目名称:phabricator,代码行数:101,代码来源:PhabricatorLoginController.php

示例5: findUserByEmailAddress

 private function findUserByEmailAddress($email_address)
 {
     $by_email = PhabricatorUser::loadOneWithEmailAddress($email_address);
     if ($by_email) {
         return $by_email->getPHID();
     }
     return null;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:8,代码来源:DiffusionResolveUserQuery.php


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