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


PHP User::setGroup方法代码示例

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


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

示例1: runAddUser

 public function runAddUser(framework\Request $request)
 {
     try {
         if (!framework\Context::getScope()->hasUsersAvailable()) {
             throw new \Exception($this->getI18n()->__('This instance of The Bug Genie cannot add more users'));
         }
         if ($username = trim($request['username'])) {
             if (!entities\User::isUsernameAvailable($username)) {
                 if ($request->getParameter('mode') == 'import') {
                     $user = entities\User::getByUsername($username);
                     $user->addScope(framework\Context::getScope());
                     return $this->renderJSON(array('imported' => true, 'message' => $this->getI18n()->__('The user was successfully added to this scope (pending user confirmation)')));
                 } elseif (framework\Context::getScope()->isDefault()) {
                     throw new \Exception($this->getI18n()->__('This username already exists'));
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('allow_import' => true));
                 }
             }
             $user = new entities\User();
             $user->setUsername($username);
             $user->setRealname($request->getParameter('realname', $username));
             $user->setBuddyname($request->getParameter('buddyname', $username));
             $user->setEmail($request->getParameter('email'));
             $group_id = $request->getParameter('group_id') ? $request->getParameter('group_id') : framework\Settings::get(framework\Settings::SETTING_USER_GROUP);
             $user->setGroup($group_id);
             if ($request->hasParameter('password') && !(empty($request['password']) && empty($request['password_repeat']))) {
                 if (empty($request['password']) || $request['password'] != $request['password_repeat']) {
                     throw new \Exception($this->getI18n()->__('Please enter the same password twice'));
                 }
                 $password = $request['password'];
                 $user->setPassword($password);
             } else {
                 $password = entities\User::createPassword();
                 $user->setPassword($password);
             }
             $user->save();
             foreach ((array) $request['teams'] as $team_id) {
                 $user->addToTeam(entities\Team::getB2DBTable()->selectById((int) $team_id));
             }
             framework\Event::createNew('core', 'config.createuser.save', $user, array('password' => $password))->trigger();
         } else {
             throw new \Exception($this->getI18n()->__('Please enter a username'));
         }
         $this->getResponse()->setTemplate('configuration/findusers');
         $this->too_short = false;
         $this->created_user = true;
         $this->users = array($user);
         $this->total_results = 1;
         $this->title = $this->getI18n()->__('User %username created', array('%username' => $username));
         $this->total_count = entities\User::getUsersCount();
         $this->more_available = framework\Context::getScope()->hasUsersAvailable();
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }
开发者ID:nrensen,项目名称:thebuggenie,代码行数:57,代码来源:Main.php

示例2: loadFixtures

 /**
  * Load user fixtures for a specified scope
  *
  * @param Scope $scope
  * @param Group $admin_group
  * @param Group $user_group
  * @param Group $guest_group
  */
 public static function loadFixtures(Scope $scope, Group $admin_group, Group $user_group, Group $guest_group)
 {
     $adminuser = new User();
     $adminuser->setUsername('administrator');
     $adminuser->setRealname('Administrator');
     $adminuser->setBuddyname('Admin');
     $adminuser->setGroup($admin_group);
     $adminuser->setPassword('admin');
     $adminuser->setActivated();
     $adminuser->setEnabled();
     $adminuser->setAvatar('admin');
     $adminuser->save();
     $guestuser = new User();
     $guestuser->setUsername('guest');
     $guestuser->setRealname('Guest user');
     $guestuser->setBuddyname('Guest user');
     $guestuser->setGroup($guest_group);
     $guestuser->setPassword('password');
     // Settings not active yet
     $guestuser->setActivated();
     $guestuser->setEnabled();
     $guestuser->save();
     framework\Settings::saveSetting('defaultuserid', $guestuser->getID(), 'core', $scope->getID());
     return array($guestuser->getID(), $adminuser->getID());
 }
开发者ID:underblaze,项目名称:thebuggenie-4.1.0,代码行数:33,代码来源:User.php

示例3: runRegister

 /**
  * Registration logic
  *
  * @Route(name="register", url="/do/register")
  * @AnonymousRoute
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runRegister(framework\Request $request)
 {
     framework\Context::loadLibrary('common');
     $i18n = framework\Context::getI18n();
     $fields = array();
     try {
         $username = mb_strtolower(trim($request['fieldusername']));
         $buddyname = $request['buddyname'];
         $email = mb_strtolower(trim($request['email_address']));
         $confirmemail = mb_strtolower(trim($request['email_confirm']));
         $security = $request['verification_no'];
         $realname = $request['realname'];
         $available = tables\Users::getTable()->isUsernameAvailable($username);
         if (!$available) {
             throw new \Exception($i18n->__('This username is in use'));
         }
         if (!empty($buddyname) && !empty($email) && !empty($confirmemail) && !empty($security)) {
             if ($email != $confirmemail) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new \Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new \Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $email_ok = false;
             if (tbg_check_syntax($email, "EMAIL")) {
                 $email_ok = true;
             }
             if ($email_ok && framework\Settings::get('limit_registration') != '') {
                 $allowed_domains = preg_replace('/[[:space:]]*,[[:space:]]*/', '|', framework\Settings::get('limit_registration'));
                 if (preg_match('/@(' . $allowed_domains . ')$/i', $email) == false) {
                     array_push($fields, 'email_address', 'email_confirm');
                     throw new \Exception($i18n->__('Email adresses from this domain can not be used.'));
                 }
             }
             if ($email_ok == false) {
                 array_push($fields, 'email_address', 'email_confirm');
                 throw new \Exception($i18n->__('The email address must be valid, and must be typed twice.'));
             }
             if ($security != $_SESSION['activation_number']) {
                 array_push($fields, 'verification_no');
                 throw new \Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.'));
             }
             $password = entities\User::createPassword();
             $user = new entities\User();
             $user->setUsername($username);
             $user->setRealname($realname);
             $user->setBuddyname($buddyname);
             $user->setGroup(framework\Settings::getDefaultGroup());
             $user->setEnabled();
             $user->setPassword($password);
             $user->setEmail($email);
             $user->setJoined();
             $user->save();
             $_SESSION['activation_number'] = tbg_printRandomNumber();
             if ($user->isActivated()) {
                 framework\Context::setMessage('auto_password', $password);
                 return $this->renderJSON(array('loginmessage' => $i18n->__('After pressing %continue, you need to set your password.', array('%continue' => $i18n->__('Continue'))), 'one_time_password' => $password, 'activated' => true));
             }
             return $this->renderJSON(array('loginmessage' => $i18n->__('The account has now been registered - check your email inbox for the activation email. Please be patient - this email can take up to two hours to arrive.'), 'activated' => false));
         } else {
             array_push($fields, 'email_address', 'email_confirm', 'buddyname', 'verification_no');
             throw new \Exception($i18n->__('You need to fill out all fields correctly.'));
         }
     } catch (\Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $i18n->__($e->getMessage()), 'fields' => $fields));
     }
 }
开发者ID:nrensen,项目名称:thebuggenie,代码行数:78,代码来源:Main.php


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