public function runAddUser(TBGRequest $request)
 {
     try {
         if (!TBGContext::getScope()->hasUsersAvailable()) {
             throw new Exception(TBGContext::getI18n()->__('This instance of The Bug Genie cannot add more users'));
         }
         if ($username = $request->getParameter('username')) {
             $user = new TBGUser();
             $user->setUsername($username);
             $user->setRealname($username);
             $user->setBuddyname($username);
             $user->setEnabled();
             $user->setActivated();
             $user->setPassword(TBGUser::hashPassword(TBGUser::createPassword()));
             $user->setJoined();
             $user->save();
         } else {
             throw new Exception(TBGContext::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 = TBGContext::getI18n()->__('User %username% created', array('%username%' => $username));
         $this->total_count = TBGUser::getUsersCount();
         $this->more_available = TBGContext::getScope()->hasUsersAvailable();
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }
 public function hasUsersAvailable()
 {
     return $this->getMaxUsers() ? TBGUser::getUsersCount() < $this->getMaxUsers() : true;
 }
示例#3
0
 public function runAddUser(TBGRequest $request)
 {
     try {
         if (!TBGContext::getScope()->hasUsersAvailable()) {
             throw new Exception($this->getI18n()->__('This instance of The Bug Genie cannot add more users'));
         }
         if ($username = trim($request['username'])) {
             if (!TBGUser::isUsernameAvailable($username)) {
                 if ($request->getParameter('mode') == 'import') {
                     $user = TBGUser::getByUsername($username);
                     $user->addScope(TBGContext::getScope());
                     return $this->renderJSON(array('imported' => true, 'message' => $this->getI18n()->__('The user was successfully added to this scope (pending user confirmation)')));
                 } elseif (TBGContext::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 TBGUser();
             $user->setUsername($username);
             $user->setRealname($request->getParameter('realname', $username));
             $user->setBuddyname($request->getParameter('buddyname', $username));
             $user->setEmail($request->getParameter('email'));
             $user->setGroup(TBGGroupsTable::getTable()->selectById((int) $request->getParameter('group_id', TBGSettings::get(TBGSettings::SETTING_USER_GROUP))));
             $user->setEnabled();
             $user->setActivated();
             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 = TBGUser::createPassword();
                 $user->setPassword($password);
             }
             $user->setJoined();
             $user->save();
             foreach ((array) $request['teams'] as $team_id) {
                 $user->addToTeam(TBGTeamsTable::getTable()->selectById((int) $team_id));
             }
             TBGEvent::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 = TBGUser::getUsersCount();
         $this->more_available = TBGContext::getScope()->hasUsersAvailable();
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }
<?php

$tbg_response->setTitle(__('Configure users, teams and clients'));
$users_text = TBGContext::getScope()->getMaxUsers() ? __('Users (%num/%max)', array('%num' => '<span id="current_user_num_count">' . TBGUser::getUsersCount() . '</span>', '%max' => TBGContext::getScope()->getMaxUsers())) : __('Users');
$teams_text = TBGContext::getScope()->getMaxTeams() ? __('Teams (%num/%max)', array('%num' => '<span id="current_team_num_count">' . TBGTeam::countAll() . '</span>', '%max' => TBGContext::getScope()->getMaxTeams())) : __('Teams');
?>
<table style="table-layout: fixed; width: 100%" cellpadding=0 cellspacing=0 class="configuration_page">
	<tr>
		<?php 
include_component('leftmenu', array('selected_section' => TBGSettings::CONFIGURATION_SECTION_USERS));
?>
		<td valign="top" style="padding-left: 15px;">
			<div style="width: 730px;">
				<h3><?php 
echo __('Configure users, teams and clients');
?>
</h3>
				<div class="tab_menu inset">
					<ul id="usersteamsgroups_menu">
						<li id="tab_users" class="selected"><?php 
echo javascript_link_tag($users_text, array('onclick' => "TBG.Main.Helpers.tabSwitcher('tab_users', 'usersteamsgroups_menu');"));
?>
</li>
						<li id="tab_teams"><?php 
echo javascript_link_tag($teams_text, array('onclick' => "TBG.Main.Helpers.tabSwitcher('tab_teams', 'usersteamsgroups_menu');"));
?>
</li>
						<li id="tab_clients"><?php 
echo javascript_link_tag(__('Clients'), array('onclick' => "TBG.Main.Helpers.tabSwitcher('tab_clients', 'usersteamsgroups_menu');"));
?>
</li>