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


PHP PhabricatorUser::describeValidUsername方法代码示例

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


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

示例1: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $admin = $request->getUser();
     $user = id(new PhabricatorPeopleQuery())->setViewer($admin)->withIDs(array($this->id))->executeOne();
     if (!$user) {
         return new Aphront404Response();
     }
     $profile_uri = '/p/' . $user->getUsername() . '/';
     id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession($admin, $request, $profile_uri);
     $errors = array();
     $v_username = $user->getUsername();
     $e_username = true;
     if ($request->isFormPost()) {
         $v_username = $request->getStr('username');
         if (!strlen($v_username)) {
             $e_username = pht('Required');
             $errors[] = pht('New username is required.');
         } else {
             if ($v_username == $user->getUsername()) {
                 $e_username = pht('Invalid');
                 $errors[] = pht('New username must be different from old username.');
             } else {
                 if (!PhabricatorUser::validateUsername($v_username)) {
                     $e_username = pht('Invalid');
                     $errors[] = PhabricatorUser::describeValidUsername();
                 }
             }
         }
         if (!$errors) {
             try {
                 id(new PhabricatorUserEditor())->setActor($admin)->changeUsername($user, $v_username);
                 $new_uri = '/p/' . $v_username . '/';
                 return id(new AphrontRedirectResponse())->setURI($new_uri);
             } catch (AphrontDuplicateKeyQueryException $ex) {
                 $e_username = pht('Not Unique');
                 $errors[] = pht('Another user already has that username.');
             }
         }
     }
     $inst1 = pht('Be careful when renaming users!');
     $inst2 = pht('The old username will no longer be tied to the user, so anything ' . 'which uses it (like old commit messages) will no longer associate ' . 'correctly. (And, if you give a user a username which some other user ' . 'used to have, username lookups will begin returning the wrong user.)');
     $inst3 = pht('It is generally safe to rename newly created users (and test users ' . 'and so on), but less safe to rename established users and unsafe to ' . 'reissue a username.');
     $inst4 = pht('Users who rely on password authentication will need to reset their ' . 'password after their username is changed (their username is part of ' . 'the salt in the password hash).');
     $inst5 = pht('The user will receive an email notifying them that you changed their ' . 'username, with instructions for logging in and resetting their ' . 'password if necessary.');
     $form = id(new AphrontFormView())->setUser($admin)->appendChild(id(new AphrontFormStaticControl())->setLabel(pht('Old Username'))->setValue($user->getUsername()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('New Username'))->setValue($v_username)->setName('username')->setError($e_username));
     if ($errors) {
         $errors = id(new AphrontErrorView())->setErrors($errors);
     }
     return $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle(pht('Change Username'))->appendChild($errors)->appendParagraph($inst1)->appendParagraph($inst2)->appendParagraph($inst3)->appendParagraph($inst4)->appendParagraph($inst5)->appendParagraph(null)->appendChild($form->buildLayoutView())->addSubmitButton(pht('Rename User'))->addCancelButton($profile_uri);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:51,代码来源:PhabricatorPeopleRenameController.php

示例2: processRenameRequest

 private function processRenameRequest(PhabricatorUser $user)
 {
     $request = $this->getRequest();
     $admin = $request->getUser();
     $e_username = true;
     $username = $user->getUsername();
     $errors = array();
     if ($request->isFormPost()) {
         $username = $request->getStr('username');
         if (!strlen($username)) {
             $e_username = 'Required';
             $errors[] = 'New username is required.';
         } else {
             if ($username == $user->getUsername()) {
                 $e_username = 'Invalid';
                 $errors[] = 'New username must be different from old username.';
             } else {
                 if (!PhabricatorUser::validateUsername($username)) {
                     $e_username = 'Invalid';
                     $errors[] = PhabricatorUser::describeValidUsername();
                 }
             }
         }
         if (!$errors) {
             try {
                 id(new PhabricatorUserEditor())->setActor($admin)->changeUsername($user, $username);
                 return id(new AphrontRedirectResponse())->setURI($request->getRequestURI()->alter('saved', true));
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $e_username = 'Not Unique';
                 $errors[] = 'Another user already has that username.';
             }
         }
     }
     if ($errors) {
         $errors = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     } else {
         $errors = null;
     }
     $form = new AphrontFormView();
     $form->setUser($admin)->setAction($request->getRequestURI())->appendChild('<p class="aphront-form-instructions">' . '<strong>Be careful when renaming users!</strong> ' . 'The old username will no longer be tied to the user, so anything ' . 'which uses it (like old commit messages) will no longer associate ' . 'correctly. And if you give a user a username which some other user ' . 'used to have, username lookups will begin returning the wrong ' . 'user.' . '</p>' . '<p class="aphront-form-instructions">' . 'It is generally safe to rename newly created users (and test users ' . 'and so on), but less safe to rename established users and unsafe ' . 'to reissue a username.' . '</p>' . '<p class="aphront-form-instructions">' . 'Users who rely on password auth will need to reset their password ' . 'after their username is changed (their username is part of the ' . 'salt in the password hash). They will receive an email with ' . 'instructions on how to do this.' . '</p>')->appendChild(id(new AphrontFormStaticControl())->setLabel('Old Username')->setValue($user->getUsername()))->appendChild(id(new AphrontFormTextControl())->setLabel('New Username')->setValue($username)->setName('username')->setError($e_username))->appendChild(id(new AphrontFormSubmitControl())->setValue('Change Username'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Change Username');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return array($errors, $panel);
 }
开发者ID:neoxen,项目名称:phabricator,代码行数:46,代码来源:PhabricatorPeopleEditController.php

示例3: processRequest

 public function processRequest()
 {
     $provider = $this->getLDAProvider();
     $ldap_info = $this->getLDAPInfo();
     $request = $this->getRequest();
     $errors = array();
     $e_username = true;
     $e_email = true;
     $e_realname = true;
     $user = new PhabricatorUser();
     $user->setUsername();
     $user->setRealname($provider->retrieveUserRealName());
     $new_email = $provider->retrieveUserEmail();
     if ($new_email) {
         // If the user's LDAP provider account has an email address but the
         // email address domain is not allowed by the Phabricator configuration,
         // we just pretend the provider did not supply an address.
         //
         // For instance, if the user uses LDAP Auth and their email address
         // is "joe@personal.com" but Phabricator is configured to require users
         // use "@company.com" addresses, we show a prompt below and tell the user
         // to provide their "@company.com" address. They can still use the LDAP
         // account to login, they just need to associate their account with an
         // allowed address.
         //
         // If the email address is fine, we just use it and don't prompt the user.
         if (!PhabricatorUserEmail::isAllowedAddress($new_email)) {
             $new_email = null;
         }
     }
     $show_email_input = $new_email === null;
     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[] = PhabricatorUser::describeValidUsername();
             } else {
                 $e_username = null;
             }
         }
         if (!$new_email) {
             $new_email = trim($request->getStr('email'));
             if (!$new_email) {
                 $e_email = 'Required';
                 $errors[] = 'Email is required.';
             } else {
                 $e_email = null;
             }
         }
         if ($new_email) {
             if (!PhabricatorUserEmail::isAllowedAddress($new_email)) {
                 $e_email = 'Invalid';
                 $errors[] = PhabricatorUserEmail::describeAllowedAddresses();
             }
         }
         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) {
             try {
                 // NOTE: We don't verify LDAP email addresses by default because
                 // LDAP providers might associate email addresses with accounts that
                 // haven't actually verified they own them. We could selectively
                 // auto-verify some providers that we trust here, but the stakes for
                 // verifying an email address are high because having a corporate
                 // address at a company is sometimes the key to the castle.
                 $email_obj = id(new PhabricatorUserEmail())->setAddress($new_email)->setIsVerified(0);
                 id(new PhabricatorUserEditor())->setActor($user)->createNewUser($user, $email_obj);
                 $ldap_info->setUserID($user->getID());
                 $ldap_info->save();
                 $session_key = $user->establishSession('web');
                 $request->setCookie('phusr', $user->getUsername());
                 $request->setCookie('phsid', $session_key);
                 $email_obj->sendVerificationEmail($user);
                 return id(new AphrontRedirectResponse())->setURI('/');
             } catch (AphrontQueryDuplicateKeyException $exception) {
                 $same_username = id(new PhabricatorUser())->loadOneWhere('userName = %s', $user->getUserName());
                 $same_email = id(new PhabricatorUserEmail())->loadOneWhere('address = %s', $new_email);
                 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;
                     }
                 }
//.........这里部分代码省略.........
开发者ID:nexeck,项目名称:phabricator,代码行数:101,代码来源:PhabricatorLDAPRegistrationController.php

示例4: processRequest


//.........这里部分代码省略.........
     $e_password = true;
     $e_captcha = true;
     $skip_captcha = false;
     if ($invite) {
         // If the user is accepting an invite, assume they're trustworthy enough
         // that we don't need to CAPTCHA them.
         $skip_captcha = true;
     }
     $min_len = PhabricatorEnv::getEnvConfig('account.minimum-password-length');
     $min_len = (int) $min_len;
     $from_invite = $request->getStr('invite');
     if ($from_invite && $can_edit_username) {
         $value_username = $request->getStr('username');
         $e_username = null;
     }
     if (($request->isFormPost() || !$can_edit_anything) && !$from_invite) {
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         if ($must_set_password && !$skip_captcha) {
             $e_captcha = pht('Again');
             $captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request);
             if (!$captcha_ok) {
                 $errors[] = pht('Captcha response is incorrect, try again.');
                 $e_captcha = pht('Invalid');
             }
         }
         if ($can_edit_username) {
             $value_username = $request->getStr('username');
             if (!strlen($value_username)) {
                 $e_username = pht('Required');
                 $errors[] = pht('Username is required.');
             } else {
                 if (!PhabricatorUser::validateUsername($value_username)) {
                     $e_username = pht('Invalid');
                     $errors[] = PhabricatorUser::describeValidUsername();
                 } else {
                     $e_username = null;
                 }
             }
         }
         if ($must_set_password) {
             $value_password = $request->getStr('password');
             $value_confirm = $request->getStr('confirm');
             if (!strlen($value_password)) {
                 $e_password = pht('Required');
                 $errors[] = pht('You must choose a password.');
             } else {
                 if ($value_password !== $value_confirm) {
                     $e_password = pht('No Match');
                     $errors[] = pht('Password and confirmation must match.');
                 } else {
                     if (strlen($value_password) < $min_len) {
                         $e_password = pht('Too Short');
                         $errors[] = pht('Password is too short (must be at least %d characters long).', $min_len);
                     } else {
                         if (PhabricatorCommonPasswords::isCommonPassword($value_password)) {
                             $e_password = pht('Very Weak');
                             $errors[] = pht('Password is pathologically weak. This password is one of the ' . 'most common passwords in use, and is extremely easy for ' . 'attackers to guess. You must choose a stronger password.');
                         } else {
                             $e_password = null;
                         }
                     }
                 }
             }
         }
         if ($can_edit_email) {
             $value_email = $request->getStr('email');
开发者ID:hrb518,项目名称:phabricator,代码行数:67,代码来源:PhabricatorAuthRegisterController.php

示例5: changeUsername

 /**
  * @task edit
  */
 public function changeUsername(PhabricatorUser $user, $username)
 {
     $actor = $this->requireActor();
     if (!$user->getID()) {
         throw new Exception("User has not been created yet!");
     }
     if (!PhabricatorUser::validateUsername($username)) {
         $valid = PhabricatorUser::describeValidUsername();
         throw new Exception("Username is invalid! {$valid}");
     }
     $old_username = $user->getUsername();
     $user->openTransaction();
     $user->reload();
     $user->setUsername($username);
     try {
         $user->save();
     } catch (AphrontQueryDuplicateKeyException $ex) {
         $user->setUsername($old_username);
         $user->killTransaction();
         throw $ex;
     }
     $log = PhabricatorUserLog::newLog($this->actor, $user, PhabricatorUserLog::ACTION_CHANGE_USERNAME);
     $log->setOldValue($old_username);
     $log->setNewValue($username);
     $log->save();
     $user->saveTransaction();
     $user->sendUsernameChangeEmail($actor, $old_username);
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:31,代码来源:PhabricatorUserEditor.php

示例6: pht

$is_first_user = !$any_user;
if ($is_first_user) {
    echo pht("WARNING\n\n" . "You're about to create the first account on this install. Normally, " . "you should use the web interface to create the first account, not " . "this script.\n\n" . "If you use the web interface, it will drop you into a nice UI workflow " . "which gives you more help setting up your install. If you create an " . "account with this script instead, you will skip the setup help and you " . "will not be able to access it later.");
    if (!phutil_console_confirm(pht('Skip easy setup and create account?'))) {
        echo pht('Cancelled.') . "\n";
        exit(1);
    }
}
echo pht('Enter a username to create a new account or edit an existing account.');
$username = phutil_console_prompt(pht('Enter a username:'));
if (!strlen($username)) {
    echo pht('Cancelled.') . "\n";
    exit(1);
}
if (!PhabricatorUser::validateUsername($username)) {
    $valid = PhabricatorUser::describeValidUsername();
    echo pht("The username '%s' is invalid. %s", $username, $valid) . "\n";
    exit(1);
}
$user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username);
if (!$user) {
    $original = new PhabricatorUser();
    echo pht("There is no existing user account '%s'.", $username) . "\n";
    $ok = phutil_console_confirm(pht("Do you want to create a new '%s' account?", $username), $default_no = false);
    if (!$ok) {
        echo pht('Cancelled.') . "\n";
        exit(1);
    }
    $user = new PhabricatorUser();
    $user->setUsername($username);
    $is_new = true;
开发者ID:truSense,项目名称:phabricator,代码行数:31,代码来源:account_admin.php

示例7: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $admin = $request->getUser();
     switch ($this->type) {
         case 'standard':
             $is_bot = false;
             break;
         case 'bot':
             $is_bot = true;
             break;
         default:
             return new Aphront404Response();
     }
     $user = new PhabricatorUser();
     $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name');
     $e_username = true;
     $e_realname = $require_real_name ? true : null;
     $e_email = true;
     $errors = array();
     $welcome_checked = true;
     $new_email = null;
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $welcome_checked = $request->getInt('welcome');
         $user->setUsername($request->getStr('username'));
         $new_email = $request->getStr('email');
         if (!strlen($new_email)) {
             $errors[] = pht('Email is required.');
             $e_email = pht('Required');
         } else {
             if (!PhabricatorUserEmail::isAllowedAddress($new_email)) {
                 $e_email = pht('Invalid');
                 $errors[] = PhabricatorUserEmail::describeAllowedAddresses();
             } else {
                 $e_email = null;
             }
         }
         $user->setRealName($request->getStr('realname'));
         if (!strlen($user->getUsername())) {
             $errors[] = pht('Username is required.');
             $e_username = pht('Required');
         } else {
             if (!PhabricatorUser::validateUsername($user->getUsername())) {
                 $errors[] = PhabricatorUser::describeValidUsername();
                 $e_username = pht('Invalid');
             } else {
                 $e_username = null;
             }
         }
         if (!strlen($user->getRealName()) && $require_real_name) {
             $errors[] = pht('Real name is required.');
             $e_realname = pht('Required');
         } else {
             $e_realname = null;
         }
         if (!$errors) {
             try {
                 $email = id(new PhabricatorUserEmail())->setAddress($new_email)->setIsVerified(0);
                 // Automatically approve the user, since an admin is creating them.
                 $user->setIsApproved(1);
                 // If the user is a bot, approve their email too.
                 if ($is_bot) {
                     $email->setIsVerified(1);
                 }
                 id(new PhabricatorUserEditor())->setActor($admin)->createNewUser($user, $email);
                 if ($is_bot) {
                     id(new PhabricatorUserEditor())->setActor($admin)->makeSystemAgentUser($user, true);
                 }
                 if ($welcome_checked && !$is_bot) {
                     $user->sendWelcomeEmail($admin);
                 }
                 $response = id(new AphrontRedirectResponse())->setURI('/p/' . $user->getUsername() . '/');
                 return $response;
             } catch (AphrontDuplicateKeyQueryException $ex) {
                 $errors[] = pht('Username and email must be unique.');
                 $same_username = id(new PhabricatorUser())->loadOneWhere('username = %s', $user->getUsername());
                 $same_email = id(new PhabricatorUserEmail())->loadOneWhere('address = %s', $new_email);
                 if ($same_username) {
                     $e_username = pht('Duplicate');
                 }
                 if ($same_email) {
                     $e_email = pht('Duplicate');
                 }
             }
         }
     }
     $form = id(new AphrontFormView())->setUser($admin);
     if ($is_bot) {
         $form->appendRemarkupInstructions(pht('You are creating a new **bot/script** user account.'));
     } else {
         $form->appendRemarkupInstructions(pht('You are creating a new **standard** user account.'));
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Username'))->setName('username')->setValue($user->getUsername())->setError($e_username))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Real Name'))->setName('realname')->setValue($user->getRealName())->setError($e_realname))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($new_email)->setCaption(PhabricatorUserEmail::describeAllowedAddresses())->setError($e_email));
     if (!$is_bot) {
         $form->appendChild(id(new AphrontFormCheckboxControl())->addCheckbox('welcome', 1, pht('Send "Welcome to Phabricator" email with login instructions.'), $welcome_checked));
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($this->getApplicationURI())->setValue(pht('Create User')));
     if ($is_bot) {
         $form->appendChild(id(new AphrontFormDividerControl()))->appendRemarkupInstructions(pht('**Why do bot/script accounts need an email address?**' . "\n\n" . 'Although bots do not normally receive email from Phabricator, ' . 'they can interact with other systems which require an email ' . 'address. Examples include:' . "\n\n" . "  - If the account takes actions which //send// email, we need " . "    an address to use in the //From// header.\n" . "  - If the account creates commits, Git and Mercurial require " . "    an email address for authorship.\n" . "  - If you send email //to// Phabricator on behalf of the " . "    account, the address can identify the sender.\n" . "  - Some internal authentication functions depend on accounts " . "    having an email address.\n" . "\n\n" . "The address will automatically be verified, so you do not need " . "to be able to receive mail at this address, and can enter some " . "invalid or nonexistent (but correctly formatted) address like " . "`bot@yourcompany.com` if you prefer."));
//.........这里部分代码省略.........
开发者ID:denghp,项目名称:phabricator,代码行数:101,代码来源:PhabricatorPeopleNewController.php


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