コード例 #1
0
ファイル: Main.php プロジェクト: nrensen/thebuggenie
 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()));
     }
 }
コード例 #2
0
ファイル: Main.php プロジェクト: nrensen/thebuggenie
 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'));
 }