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


PHP PhabricatorUser::setEmail方法代码示例

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


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

示例1: processRequest

 public function processRequest()
 {
     $provider = $this->getOAuthProvider();
     $oauth_info = $this->getOAuthInfo();
     $request = $this->getRequest();
     $errors = array();
     $e_username = true;
     $e_email = true;
     $e_realname = true;
     $user = new PhabricatorUser();
     $user->setUsername($provider->retrieveUserAccountName());
     $user->setRealName($provider->retrieveUserRealName());
     $user->setEmail($provider->retrieveUserEmail());
     if ($request->isFormPost()) {
         $user->setUsername($request->getStr('username'));
         $username = $user->getUsername();
         if (!strlen($user->getUsername())) {
             $e_username = 'Required';
             $errors[] = 'Username is required.';
         } else {
             if (!PhabricatorUser::validateUsername($username)) {
                 $e_username = 'Invalid';
                 $errors[] = 'Username must consist of only numbers and letters.';
             } else {
                 $e_username = null;
             }
         }
         if ($user->getEmail() === null) {
             $user->setEmail($request->getStr('email'));
             if (!strlen($user->getEmail())) {
                 $e_email = 'Required';
                 $errors[] = 'Email is required.';
             } else {
                 $e_email = null;
             }
         }
         if (!strlen($user->getRealName())) {
             $user->setRealName($request->getStr('realname'));
             if (!strlen($user->getRealName())) {
                 $e_realname = 'Required';
                 $errors[] = 'Real name is required.';
             } else {
                 $e_realname = null;
             }
         }
         if (!$errors) {
             $image = $provider->retrieveUserProfileImage();
             if ($image) {
                 $file = PhabricatorFile::newFromFileData($image, array('name' => $provider->getProviderKey() . '-profile.jpg', 'authorPHID' => $user->getPHID()));
                 $user->setProfileImagePHID($file->getPHID());
             }
             try {
                 $user->save();
                 $oauth_info->setUserID($user->getID());
                 $oauth_info->save();
                 $session_key = $user->establishSession('web');
                 $request->setCookie('phusr', $user->getUsername());
                 $request->setCookie('phsid', $session_key);
                 return id(new AphrontRedirectResponse())->setURI('/');
             } catch (AphrontQueryDuplicateKeyException $exception) {
                 $same_username = id(new PhabricatorUser())->loadOneWhere('userName = %s', $user->getUserName());
                 $same_email = id(new PhabricatorUser())->loadOneWhere('email = %s', $user->getEmail());
                 if ($same_username) {
                     $e_username = 'Duplicate';
                     $errors[] = 'That username or email is not unique.';
                 } else {
                     if ($same_email) {
                         $e_email = 'Duplicate';
                         $errors[] = 'That email is not unique.';
                     } else {
                         throw $exception;
                     }
                 }
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Registration Failed');
         $error_view->setErrors($errors);
     }
     // Strip the URI down to the path, because otherwise we'll trigger
     // external CSRF protection (by having a protocol in the form "action")
     // and generate a form with no CSRF token.
     $action_uri = new PhutilURI($provider->getRedirectURI());
     $action_path = $action_uri->getPath();
     $form = new AphrontFormView();
     $form->addHiddenInput('token', $provider->getAccessToken())->addHiddenInput('expires', $oauth_info->getTokenExpires())->addHiddenInput('state', $this->getOAuthState())->setUser($request->getUser())->setAction($action_path)->appendChild(id(new AphrontFormTextControl())->setLabel('Username')->setName('username')->setValue($user->getUsername())->setError($e_username));
     if ($provider->retrieveUserEmail() === null) {
         $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($request->getStr('email'))->setError($e_email));
     }
     if ($provider->retrieveUserRealName() === null) {
         $form->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setValue($request->getStr('realname'))->setError($e_realname));
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Account'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Create New Account');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
//.........这里部分代码省略.........
开发者ID:ramons03,项目名称:phabricator,代码行数:101,代码来源:PhabricatorOAuthDefaultRegistrationController.php

示例2: nonempty

if (strlen($user_email)) {
    $email_prompt = ' [' . $user_email . ']';
} else {
    $email_prompt = '';
}
do {
    $email = nonempty(phutil_console_prompt("Enter user email address{$email_prompt}:"), $user_email);
    $duplicate = id(new PhabricatorUser())->loadOneWhere('email = %s', $email);
    if ($duplicate && $duplicate->getID() != $user->getID()) {
        $duplicate_username = $duplicate->getUsername();
        echo "ERROR: There is already a user with that email address " . "({$duplicate_username}). Each user must have a unique email " . "address.\n";
    } else {
        break;
    }
} while (true);
$user->setEmail($email);
$changed_pass = false;
// This disables local echo, so the user's password is not shown as they type
// it.
phutil_passthru('stty -echo');
$password = phutil_console_prompt("Enter a password for this user [blank to leave unchanged]:");
phutil_passthru('stty echo');
if (strlen($password)) {
    $changed_pass = $password;
}
$is_admin = $user->getIsAdmin();
$set_admin = phutil_console_confirm('Should this user be an administrator?', $default_no = !$is_admin);
$user->setIsAdmin($set_admin);
echo "\n\nACCOUNT SUMMARY\n\n";
$tpl = "%12s   %-30s   %-30s\n";
printf($tpl, null, 'OLD VALUE', 'NEW VALUE');
开发者ID:netcomtec,项目名称:phabricator,代码行数:31,代码来源:account_admin.php

示例3: processBasicRequest

 private function processBasicRequest(PhabricatorUser $user)
 {
     $request = $this->getRequest();
     $admin = $request->getUser();
     $e_username = true;
     $e_realname = true;
     $e_email = true;
     $errors = array();
     $welcome_checked = true;
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $welcome_checked = $request->getInt('welcome');
         if (!$user->getID()) {
             $user->setUsername($request->getStr('username'));
             $user->setEmail($request->getStr('email'));
             if ($request->getStr('role') == 'agent') {
                 $user->setIsSystemAgent(true);
             }
         }
         $user->setRealName($request->getStr('realname'));
         if (!strlen($user->getUsername())) {
             $errors[] = "Username is required.";
             $e_username = 'Required';
         } else {
             if (!PhabricatorUser::validateUsername($user->getUsername())) {
                 $errors[] = "Username must consist of only numbers and letters.";
                 $e_username = 'Invalid';
             } else {
                 $e_username = null;
             }
         }
         if (!strlen($user->getRealName())) {
             $errors[] = 'Real name is required.';
             $e_realname = 'Required';
         } else {
             $e_realname = null;
         }
         if (!strlen($user->getEmail())) {
             $errors[] = 'Email is required.';
             $e_email = 'Required';
         } else {
             $e_email = null;
         }
         if (!$errors) {
             try {
                 $is_new = !$user->getID();
                 $user->save();
                 if ($is_new) {
                     $log = PhabricatorUserLog::newLog($admin, $user, PhabricatorUserLog::ACTION_CREATE);
                     $log->save();
                     if ($welcome_checked) {
                         $user->sendWelcomeEmail($admin);
                     }
                 }
                 $response = id(new AphrontRedirectResponse())->setURI('/people/edit/' . $user->getID() . '/?saved=true');
                 return $response;
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $errors[] = 'Username and email must be unique.';
                 $same_username = id(new PhabricatorUser())->loadOneWhere('username = %s', $user->getUsername());
                 $same_email = id(new PhabricatorUser())->loadOneWhere('email = %s', $user->getEmail());
                 if ($same_username) {
                     $e_username = 'Duplicate';
                 }
                 if ($same_email) {
                     $e_email = 'Duplicate';
                 }
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($admin);
     if ($user->getID()) {
         $form->setAction('/people/edit/' . $user->getID() . '/');
     } else {
         $form->setAction('/people/edit/');
     }
     if ($user->getID()) {
         $is_immutable = true;
     } else {
         $is_immutable = false;
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Username')->setName('username')->setValue($user->getUsername())->setError($e_username)->setDisabled($is_immutable)->setCaption('Usernames are permanent and can not be changed later!'))->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setValue($user->getRealName())->setError($e_realname))->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setDisabled($is_immutable)->setValue($user->getEmail())->setError($e_email))->appendChild($this->getRoleInstructions());
     if (!$user->getID()) {
         $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Role')->setName('role')->setValue('user')->setOptions(array('user' => 'Normal User', 'agent' => 'System Agent'))->setCaption('You can create a "system agent" account for bots, scripts, ' . 'etc.'))->appendChild(id(new AphrontFormCheckboxControl())->addCheckbox('welcome', 1, 'Send "Welcome to Phabricator" email.', $welcome_checked));
     } else {
         $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Role')->setValue($user->getIsSystemAgent() ? 'System Agent' : 'Normal User'));
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     $panel = new AphrontPanelView();
     if ($user->getID()) {
         $panel->setHeader('Edit User');
     } else {
         $panel->setHeader('Create New User');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
//.........这里部分代码省略.........
开发者ID:ramons03,项目名称:phabricator,代码行数:101,代码来源:PhabricatorPeopleEditController.php

示例4: processBasicRequest

    private function processBasicRequest(PhabricatorUser $user)
    {
        $request = $this->getRequest();
        $admin = $request->getUser();
        $e_username = true;
        $e_realname = true;
        $e_email = true;
        $errors = array();
        $welcome_checked = true;
        $request = $this->getRequest();
        if ($request->isFormPost()) {
            $welcome_checked = $request->getInt('welcome');
            if (!$user->getID()) {
                $user->setUsername($request->getStr('username'));
                $user->setEmail($request->getStr('email'));
                if ($request->getStr('role') == 'agent') {
                    $user->setIsSystemAgent(true);
                }
            }
            $user->setRealName($request->getStr('realname'));
            if (!strlen($user->getUsername())) {
                $errors[] = "Username is required.";
                $e_username = 'Required';
            } else {
                if (!preg_match('/^[a-z0-9]+$/', $user->getUsername())) {
                    $errors[] = "Username must consist of only numbers and letters.";
                    $e_username = 'Invalid';
                } else {
                    $e_username = null;
                }
            }
            if (!strlen($user->getRealName())) {
                $errors[] = 'Real name is required.';
                $e_realname = 'Required';
            } else {
                $e_realname = null;
            }
            if (!strlen($user->getEmail())) {
                $errors[] = 'Email is required.';
                $e_email = 'Required';
            } else {
                $e_email = null;
            }
            if (!$errors) {
                try {
                    $is_new = !$user->getID();
                    $user->save();
                    if ($is_new) {
                        $log = PhabricatorUserLog::newLog($admin, $user, PhabricatorUserLog::ACTION_CREATE);
                        $log->save();
                        if ($welcome_checked) {
                            $admin_username = $admin->getUserName();
                            $admin_realname = $admin->getRealName();
                            $user_username = $user->getUserName();
                            $base_uri = PhabricatorEnv::getProductionURI('/');
                            $uri = $user->getEmailLoginURI();
                            $body = <<<EOBODY
Welcome to Phabricator!

{$admin_username} ({$admin_realname}) has created an account for you.

  Username: {$user_username}

To login to Phabricator, follow this link and set a password:

  {$uri}

After you have set a password, you can login in the future by going here:

  {$base_uri}

Love,
Phabricator

EOBODY;
                            $mail = id(new PhabricatorMetaMTAMail())->addTos(array($user->getPHID()))->setSubject('[Phabricator] Welcome to Phabricator')->setBody($body)->setFrom($admin->getPHID())->saveAndSend();
                        }
                    }
                    $response = id(new AphrontRedirectResponse())->setURI('/people/edit/' . $user->getID() . '/?saved=true');
                    return $response;
                } catch (AphrontQueryDuplicateKeyException $ex) {
                    $errors[] = 'Username and email must be unique.';
                    $same_username = id(new PhabricatorUser())->loadOneWhere('username = %s', $user->getUsername());
                    $same_email = id(new PhabricatorUser())->loadOneWhere('email = %s', $user->getEmail());
                    if ($same_username) {
                        $e_username = 'Duplicate';
                    }
                    if ($same_email) {
                        $e_email = 'Duplicate';
                    }
                }
            }
        }
        $error_view = null;
        if ($errors) {
            $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
        }
        $form = new AphrontFormView();
        $form->setUser($admin);
        if ($user->getID()) {
//.........这里部分代码省略.........
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:101,代码来源:PhabricatorPeopleEditController.php


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