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


PHP User::createPassword方法代码示例

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


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

示例1: runUpdateUser

 public function runUpdateUser(framework\Request $request)
 {
     try {
         $user = entities\User::getB2DBTable()->selectByID($request['user_id']);
         if ($user instanceof entities\User) {
             if (!$user->isConfirmedMemberOfScope(framework\Context::getScope())) {
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => $this->getI18n()->__('This user is not a confirmed member of this scope')));
             }
             if (!empty($request['username'])) {
                 $testuser = entities\User::getByUsername($request['username']);
                 if (!$testuser instanceof entities\User || $testuser->getID() == $user->getID()) {
                     $user->setUsername($request['username']);
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => $this->getI18n()->__('This username is already taken')));
                 }
             }
             $password_changed = false;
             if ($request['password_action'] == 'change' && $request['new_password_1'] && $request['new_password_2']) {
                 if ($request['new_password_1'] == $request['new_password_2']) {
                     $user->setPassword($request['new_password_1']);
                     $password_changed = true;
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => $this->getI18n()->__('Please enter the new password twice')));
                 }
             } elseif ($request['password_action'] == 'random') {
                 $random_password = entities\User::createPassword();
                 $user->setPassword($random_password);
                 $password_changed = true;
             }
             if (isset($request['realname'])) {
                 $user->setRealname($request['realname']);
             }
             $return_options = array();
             try {
                 if ($group = entities\Group::getB2DBTable()->selectById($request['group'])) {
                     if ($user->getGroupID() != $group->getID()) {
                         $groups = array($user->getGroupID(), $group->getID());
                         $return_options['update_groups'] = array('ids' => array(), 'membercounts' => array());
                     }
                     $user->setGroup($group);
                 }
             } catch (\Exception $e) {
                 throw new \Exception($this->getI18n()->__('Invalid user group'));
             }
             $existing_teams = array_keys($user->getTeams());
             $new_teams = array();
             $new_clients = array();
             $user->clearTeams();
             try {
                 foreach ($request->getParameter('teams', array()) as $team_id => $team) {
                     if ($team = entities\Team::getB2DBTable()->selectById($team_id)) {
                         $new_teams[] = $team_id;
                         $user->addToTeam($team);
                     }
                 }
             } catch (\Exception $e) {
                 throw new \Exception($this->getI18n()->__('One or more teams were invalid'));
             }
             try {
                 $user->clearClients();
                 foreach ($request->getParameter('clients', array()) as $client_id => $client) {
                     if ($client = entities\Client::getB2DBTable()->selectById($client_id)) {
                         $new_clients[] = $client_id;
                         $user->addToClient($client);
                     }
                 }
             } catch (\Exception $e) {
                 throw new \Exception($this->getI18n()->__('One or more clients were invalid'));
             }
             if (isset($request['nickname'])) {
                 $user->setBuddyname($request['nickname']);
             }
             if (isset($request['email'])) {
                 $user->setEmail($request['email']);
             }
             if (isset($request['homepage'])) {
                 $user->setHomepage($request['homepage']);
             }
             if (framework\Context::getScope()->isDefault()) {
                 $user->setActivated((bool) $request['activated']);
                 $user->setEnabled((bool) $request['enabled']);
             }
             $user->save();
             if (isset($groups)) {
                 foreach ($groups as $group_id) {
                     if (!$group_id) {
                         continue;
                     }
                     $return_options['update_groups']['ids'][] = $group_id;
                     $return_options['update_groups']['membercounts'][$group_id] = entities\Group::getB2DBTable()->selectById($group_id)->getNumberOfMembers();
                 }
             }
             if ($new_teams != $existing_teams) {
                 $new_team_ids = array_diff($new_teams, $existing_teams);
                 $existing_team_ids = array_diff($existing_teams, $new_teams);
                 $teams_to_update = array_merge($new_team_ids, $existing_team_ids);
                 $return_options['update_teams'] = array('ids' => array(), 'membercounts' => array());
//.........这里部分代码省略.........
开发者ID:nrensen,项目名称:thebuggenie,代码行数:101,代码来源:Main.php

示例2: listen_registerUser

 public function listen_registerUser(framework\Event $event)
 {
     if ($this->isActivationNeeded() && $this->isOutgoingNotificationsEnabled()) {
         $user = $event->getSubject();
         $password = User::createPassword(8);
         $user->setPassword($password);
         $user->setActivated(false);
         $user->save();
         if ($user->getEmail()) {
             //                The following line is included for the i18n parser to pick up the translatable string:
             //                __('User account registered with The Bug Genie');
             $subject = 'User account registered with The Bug Genie';
             $link_to_activate = $this->generateURL('activate', array('user' => str_replace('.', '%2E', $user->getUsername()), 'key' => $user->getActivationKey()));
             $parameters = compact('user', 'password', 'link_to_activate');
             $messages = $this->getTranslatedMessages('registeruser', $parameters, array($user), $subject);
             foreach ($messages as $message) {
                 $this->sendMail($message);
             }
         }
         $event->setProcessed();
     }
 }
开发者ID:RTechSoft,项目名称:thebuggenie,代码行数:22,代码来源:Mailing.php

示例3: runAccountPickUsername

 public function runAccountPickUsername(framework\Request $request)
 {
     if (entities\User::isUsernameAvailable($request['selected_username'])) {
         $user = $this->getUser();
         $user->setUsername($request['selected_username']);
         $user->setOpenIdLocked(false);
         $user->setPassword(entities\User::createPassword());
         $user->save();
         $this->getResponse()->setCookie('tbg3_username', $user->getUsername());
         $this->getResponse()->setCookie('tbg3_password', $user->getPassword());
         framework\Context::setMessage('username_chosen', true);
         $this->forward($this->getRouting()->generate('account'));
     }
     framework\Context::setMessage('error', $this->getI18n()->__('Could not pick the username "%username"', array('%username' => $request['selected_username'])));
     $this->forward($this->getRouting()->generate('account'));
 }
开发者ID:nrensen,项目名称:thebuggenie,代码行数:16,代码来源:Main.php


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