public function do_execute()
 {
     $this->cliEcho('Saving remote server: ');
     $this->cliEcho($this->getProvidedArgument('server_url'), 'white', 'bold');
     $this->cliEcho("\n");
     file_put_contents(THEBUGGENIE_PATH . '.remote_server', $this->getProvidedArgument('server_url'));
     if ($this->hasProvidedArgument('username')) {
         $this->cliEcho('Saving remote username: '******'username'), 'white', 'bold');
         $this->cliEcho("\n");
         file_put_contents(THEBUGGENIE_PATH . '.remote_username', $this->getProvidedArgument('username'));
         $this->cliEcho("\n");
         $this->cliEcho('To avoid being asked for a password, please enter the password for the remote user ');
         $this->cliEcho($this->getProvidedArgument('username'), 'white', 'bold');
         $this->cliEcho(" (a hash of the password will be stored).\nIf you don't want to store this, simply press enter:\n");
         $this->cliEcho("Enter the password for the {$this->getProvidedArgument('username')} user: "******"Please enter the remote security key: ", 'white', 'bold');
         $salt = $this->_getCliInput();
         if ($password != '' && $salt != '') {
             file_put_contents(THEBUGGENIE_PATH . '.remote_password_hash', TBGUser::hashPassword($password, $salt));
             $this->cliEcho("Authentication details saved.\n", 'white', 'bold');
         } else {
             $this->cliEcho("\n");
             $this->cliEcho("Please provide both password and security key.\n");
             $this->cliEcho("If you haven't received the security key, please contact the remote server administrator.\n\n");
             $this->cliEcho("Password hash not saved.\n", 'white', 'bold');
         }
     }
 }
Esempio n. 2
0
 /**
  * Reset user password
  * 
  * @param TBGRequest $request
  */
 public function runResetPassword(TBGRequest $request)
 {
     $this->user = TBGUser::getByUsername(str_replace('%2E', '.', $request->getParameter('user')));
     $this->username = $request->getParameter('user');
     $this->id = $request->getParameter('reset_hash');
     $this->forward403unless($this->user instanceof TBGUser && $this->id == $this->user->getHashPassword(), 'Invalid password reset request');
 }
 protected final function _prepare()
 {
     if ($this->hasProvidedArgument('server')) {
         $this->_current_remote_server = $this->getProvidedArgument('server');
     } elseif (file_exists(THEBUGGENIE_PATH . '.remote_server')) {
         $this->_current_remote_server = file_get_contents(THEBUGGENIE_PATH . '.remote_server');
     } else {
         throw new Exception("Please specify an installation of The Bug Genie to connect to by running the set_remote command first.");
     }
     if ($this->hasProvidedArgument('username')) {
         $this->_current_remote_user = $this->getProvidedArgument('username');
     } elseif (file_exists(THEBUGGENIE_PATH . '.remote_username')) {
         $this->_current_remote_user = file_get_contents(THEBUGGENIE_PATH . '.remote_username');
     } else {
         $this->_current_remote_user = TBGContext::getCurrentCLIusername();
     }
     if (file_exists(THEBUGGENIE_PATH . '.remote_password_hash')) {
         $this->_current_remote_password_hash = file_get_contents(THEBUGGENIE_PATH . '.remote_password_hash');
     } else {
         $this->cliEcho('Please enter the password for user ');
         $this->cliEcho($this->_getCurrentRemoteUser(), 'white', 'bold');
         $this->cliEcho(' (the password will not be stored): ');
         $this->_current_remote_password_hash = TBGUser::hashPassword($this->_getCliInput());
     }
 }
Esempio n. 4
0
 /**
  * Load the user object into the user property
  * 
  * @return TBGUser
  */
 public static function loadUser($user = null)
 {
     try {
         self::$_user = $user === null ? TBGUser::loginCheck(self::getRequest(), self::getCurrentAction()) : $user;
         if (self::$_user->isAuthenticated()) {
             if (self::$_user->isOffline() || self::$_user->isAway()) {
                 self::$_user->setOnline();
             }
             if (!self::getRequest()->hasCookie('tbg3_original_username')) {
                 self::$_user->updateLastSeen();
             }
             if (!TBGContext::getScope()->isDefault() && !self::getRequest()->isAjaxCall() && !in_array(self::getRouting()->getCurrentRouteName(), array('add_scope', 'serve', 'debug', 'logout')) && !self::$_user->isGuest() && !self::$_user->isConfirmedMemberOfScope(TBGContext::getScope())) {
                 self::getResponse()->headerRedirect(self::getRouting()->generate('add_scope'));
             }
             self::$_user->save();
             if (!self::$_user->getGroup() instanceof TBGGroup) {
                 throw new Exception('This user account belongs to a group that does not exist anymore. <br>Please contact the system administrator.');
             }
         }
     } catch (TBGElevatedLoginException $e) {
         throw $e;
     } catch (Exception $e) {
         self::$_user = new TBGUser();
         throw $e;
     }
     return self::$_user;
 }
Esempio n. 5
0
 /**
  * Forgotten password logic (AJAX call)
  *
  * @param TBGRequest $request
  */
 public function runForgot(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     try {
         $username = str_replace('%2E', '.', $request['forgot_password_username']);
         if (!empty($username)) {
             if (($user = TBGUser::getByUsername($username)) instanceof TBGUser) {
                 if ($user->isActivated() && $user->isEnabled() && !$user->isDeleted()) {
                     if ($user->getEmail()) {
                         TBGMailing::getModule()->sendForgottenPasswordEmail($user);
                         return $this->renderJSON(array('message' => $i18n->__('Please use the link in the email you received')));
                     } else {
                         throw new Exception($i18n->__('Cannot find an email address for this user'));
                     }
                 } else {
                     throw new Exception($i18n->__('Forbidden for this username, please contact your administrator'));
                 }
             } else {
                 throw new Exception($i18n->__('This username does not exist'));
             }
         } else {
             throw new Exception($i18n->__('Please enter an username'));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('error' => $e->getMessage()));
     }
 }
 public function addIdentity($identity, $email, $user_id)
 {
     $user = TBGUsersTable::getTable()->selectById($user_id);
     $crit = $this->getCriteria();
     $crit->addInsert(self::IDENTITY, $identity);
     $crit->addInsert(self::IDENTITY_HASH, TBGUser::hashPassword($identity, $user->getSalt()));
     $crit->addInsert(self::UID, $user_id);
     $type = 'openid';
     foreach (self::getProviders() as $provider => $string) {
         if (stripos($identity, $string) !== false) {
             $type = $provider;
             break;
         }
     }
     $crit->addInsert(self::TYPE, $type);
     $this->doInsert($crit);
 }
 /**
  * Load the user object into the user property
  * 
  * @return TBGUser
  */
 public static function loadUser($user = null)
 {
     try {
         self::$_user = $user === null ? TBGUser::loginCheck(self::getRequest()->getParameter('tbg3_username'), self::getRequest()->getParameter('tbg3_password')) : $user;
         if (self::$_user->isAuthenticated()) {
             if (self::$_user->isOffline() || self::$_user->isAway()) {
                 self::$_user->setOnline();
             }
             self::$_user->updateLastSeen();
             self::$_user->setTimezone(TBGSettings::getUserTimezone());
             self::$_user->setLanguage(TBGSettings::getUserLanguage());
             self::$_user->save();
             if (!self::$_user->getGroup() instanceof TBGGroup) {
                 throw new Exception('This user account belongs to a group that does not exist anymore. <br>Please contact the system administrator.');
             }
         }
     } catch (Exception $e) {
         throw $e;
     }
     return self::$_user;
 }
Esempio n. 8
0
 public function runAuthenticate(TBGRequest $request)
 {
     $username = trim($request['username']);
     $password = trim($request['password']);
     if ($username) {
         $user = TBGUsersTable::getTable()->getByUsername($username);
         if ($password && $user instanceof TBGUser) {
             foreach ($user->getApplicationPasswords() as $app_password) {
                 if (!$app_password->isUsed()) {
                     if ($app_password->getHashPassword() == TBGUser::hashPassword($password, $user->getSalt())) {
                         $app_password->useOnce();
                         $app_password->save();
                         return $this->renderJSON(array('token' => $app_password->getHashPassword()));
                     }
                 }
             }
         }
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => 'Incorrect username or application password'));
 }
 /**
  * Adds a user to the client
  *
  * @param TBGUser $user
  */
 public function addMember(TBGUser $user)
 {
     $crit = new B2DBCriteria();
     $crit->addInsert(TBGClientMembersTable::SCOPE, TBGContext::getScope()->getID());
     $crit->addInsert(TBGClientMembersTable::CID, $this->_id);
     $crit->addInsert(TBGClientMembersTable::UID, $user->getID());
     B2DB::getTable('TBGClientMembersTable')->doInsert($crit);
     if ($this->_members === null) {
         $this->_members = array();
     }
     $this->_members[] = $user->getID();
     array_unique($this->_members);
 }
Esempio n. 10
0
 public function runConfigureWorkflowTransition(TBGRequest $request)
 {
     $this->workflow = null;
     $this->transition = null;
     try {
         $this->workflow = TBGWorkflowsTable::getTable()->selectById((int) $request['workflow_id']);
         if ($request->hasParameter('transition_id')) {
             $mode = $request['mode'];
             $this->transition = TBGWorkflowTransitionsTable::getTable()->selectById((int) $request['transition_id']);
             if ($request->isPost()) {
                 if ($mode == 'edit') {
                     if (!$this->transition->isInitialTransition()) {
                         $this->transition->setName($request['transition_name']);
                         $this->transition->setDescription($request['transition_description']);
                         if ($request['template']) {
                             $this->transition->setTemplate($request['template']);
                         } else {
                             $this->transition->setTemplate(null);
                         }
                     }
                     try {
                         $step = TBGWorkflowStepsTable::getTable()->selectById((int) $request['outgoing_step_id']);
                         $this->transition->setOutgoingStep($step);
                     } catch (Exception $e) {
                     }
                     $this->transition->save();
                     $transition = $this->transition;
                     $redirect_transition = true;
                 } elseif ($mode == 'delete') {
                     $this->transition->deleteTransition($request['direction']);
                     return $this->renderJSON('ok');
                 } elseif ($mode == 'delete_action') {
                     $this->action = TBGWorkflowTransitionActionsTable::getTable()->selectById((int) $request['action_id']);
                     $this->action->delete();
                     return $this->renderJSON(array('message' => $this->getI18n()->__('The action has been deleted')));
                 } elseif ($mode == 'new_action') {
                     $action = new TBGWorkflowTransitionAction();
                     $action->setActionType($request['action_type']);
                     $action->setTransition($this->transition);
                     $action->setWorkflow($this->workflow);
                     $action->setTargetValue('');
                     $action->save();
                     return $this->renderJSON(array('content' => $this->getComponentHTML('configuration/workflowtransitionaction', array('action' => $action))));
                 } elseif ($mode == 'update_action') {
                     $this->action = TBGWorkflowTransitionActionsTable::getTable()->selectById((int) $request['action_id']);
                     $this->action->setTargetValue($request['target_value']);
                     $this->action->save();
                     $text = $request['target_value'];
                     switch ($this->action->getActionType()) {
                         case TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE:
                             if ($this->action->hasTargetValue()) {
                                 $target_details = explode('_', $this->action->getTargetValue());
                                 $text = $target_details[0] == 'user' ? TBGUser::getB2DBTable()->selectById((int) $target_details[1])->getNameWithUsername() : TBGTeam::getB2DBTable()->selectById((int) $target_details[1])->getName();
                             } else {
                                 $text = $this->getI18n()->__('User specified during transition');
                             }
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION:
                             $text = $this->action->getTargetValue() ? TBGListTypesTable::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Resolution specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_REPRODUCABILITY:
                             $text = $this->action->getTargetValue() ? TBGListTypesTable::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Reproducability specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_STATUS:
                             $text = $this->action->getTargetValue() ? TBGListTypesTable::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Status specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_PRIORITY:
                             $text = $this->action->getTargetValue() ? TBGListTypesTable::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Priority specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_MILESTONE:
                             $text = $this->action->getTargetValue() ? TBGMilestonesTable::getTable()->selectById((int) $this->action->getTargetValue())->getName() : $this->getI18n()->__('Milestone specified by user');
                             break;
                     }
                     return $this->renderJSON(array('content' => $text));
                 } elseif ($mode == 'delete_validation_rule') {
                     $this->rule = TBGWorkflowTransitionValidationRulesTable::getTable()->selectById((int) $request['rule_id']);
                     $this->rule->delete();
                     return $this->renderJSON(array('message' => $this->getI18n()->__('The validation rule has been deleted')));
                 } elseif ($mode == 'new_validation_rule') {
                     $rule = new TBGWorkflowTransitionValidationRule();
                     if ($request['postorpre'] == 'post') {
                         $exists = (bool) $this->transition->hasPostValidationRule($request['rule']);
                         if (!$exists) {
                             $rule->setPost();
                         }
                     } elseif ($request['postorpre'] == 'pre') {
                         $exists = (bool) $this->transition->hasPreValidationRule($request['rule']);
                         if (!$exists) {
                             $rule->setPre();
                         }
                     }
                     if ($exists) {
                         $this->getResponse()->setHttpStatus(400);
                         return $this->renderJSON(array('message' => $this->getI18n()->__('This validation rule already exist')));
                     }
                     $rule->setRule($request['rule']);
                     $rule->setRuleValue('');
                     $rule->setTransition($this->transition);
                     $rule->setWorkflow($this->workflow);
                     $rule->save();
                     return $this->renderJSON(array('content' => $this->getTemplateHTML('configuration/workflowtransitionvalidationrule', array('rule' => $rule))));
                 } elseif ($mode == 'update_validation_rule') {
                     $this->rule = TBGWorkflowTransitionValidationRulesTable::getTable()->selectById((int) $request['rule_id']);
                     $text = null;
                     switch ($this->rule->getRule()) {
                         case TBGWorkflowTransitionValidationRule::RULE_MAX_ASSIGNED_ISSUES:
                             $this->rule->setRuleValue($request['rule_value']);
                             $text = $this->rule->getRuleValue() ? $this->rule->getRuleValue() : $this->getI18n()->__('Unlimited');
                             break;
                         case TBGWorkflowTransitionValidationRule::RULE_PRIORITY_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_REPRODUCABILITY_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_RESOLUTION_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_STATUS_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_TEAM_MEMBERSHIP_VALID:
                             $this->rule->setRuleValue(join(',', $request['rule_value']));
                             $text = $this->rule->getRuleValue() ? $this->rule->getRuleValueAsJoinedString() : $this->getI18n()->__('Any valid value');
                             break;
                     }
                     $this->rule->save();
                     return $this->renderJSON(array('content' => $text));
                 }
             }
         } elseif ($request->isPost() && $request->hasParameter('step_id')) {
             $step = TBGWorkflowStepsTable::getTable()->selectById((int) $request['step_id']);
             /*if ($step->isCore() || $workflow->isCore())
             		{
             			throw new InvalidArgumentException("The default workflow cannot be edited");
             		}*/
             if ($request['add_transition_type'] == 'existing' && $request->hasParameter('existing_transition_id')) {
                 $transition = TBGWorkflowTransitionsTable::getTable()->selectById((int) $request['existing_transition_id']);
                 $redirect_transition = false;
             } else {
                 if ($request['transition_name'] && $request['outgoing_step_id'] && $request->hasParameter('template')) {
                     if (($outgoing_step = TBGWorkflowStepsTable::getTable()->selectById((int) $request['outgoing_step_id'])) && $step instanceof TBGWorkflowStep) {
                         if (array_key_exists($request['template'], TBGWorkflowTransition::getTemplates())) {
                             $transition = new TBGWorkflowTransition();
                             $transition->setWorkflow($this->workflow);
                             $transition->setName($request['transition_name']);
                             $transition->setDescription($request['transition_description']);
                             $transition->setOutgoingStep($outgoing_step);
                             $transition->setTemplate($request['template']);
                             $transition->save();
                             $step->addOutgoingTransition($transition);
                             $redirect_transition = true;
                         } else {
                             throw new InvalidArgumentException($this->getI18n()->__('Please select a valid template'));
                         }
                     } else {
                         throw new InvalidArgumentException($this->getI18n()->__('Please select a valid outgoing step'));
                     }
                 } else {
                     throw new InvalidArgumentException($this->getI18n()->__('Please fill in all required fields'));
                 }
             }
             $step->addOutgoingTransition($transition);
         } else {
             throw new InvalidArgumentException('Invalid action');
         }
     } catch (InvalidArgumentException $e) {
         //throw $e;
         $this->error = $e->getMessage();
     } catch (Exception $e) {
         throw $e;
         $this->error = $this->getI18n()->__('This workflow / transition does not exist');
     }
     if (isset($redirect_transition) && $redirect_transition) {
         $this->forward(TBGContext::getRouting()->generate('configure_workflow_transition', array('workflow_id' => $this->workflow->getID(), 'transition_id' => $transition->getID())));
     } elseif (isset($redirect_transition)) {
         $this->forward(TBGContext::getRouting()->generate('configure_workflow_steps', array('workflow_id' => $this->workflow->getID())));
     }
 }
Esempio n. 11
0
 /**
  * Check if the given user is a friend of this user
  *
  * @param TBGUser $user The user to check
  * 
  * @return boolean
  */
 public function isFriend($user)
 {
     $this->_setupFriends();
     if (empty($this->_friends)) {
         return false;
     }
     return array_key_exists($user->getID(), $this->_friends);
 }
 public function canUserSet(TBGUser $user)
 {
     return $user->hasPermission($this->getPermissionsKey(), $this->getID(), 'core', true, true);
 }
Esempio n. 13
0
 public function hasUsersAvailable()
 {
     return $this->getMaxUsers() ? TBGUser::getUsersCount() < $this->getMaxUsers() : true;
 }
Esempio n. 14
0
 /**
  * Import all valid users
  * 
  * @param TBGRequest $request
  */
 public function runImportUsers(TBGRequest $request)
 {
     $validgroups = TBGContext::getModule('auth_ldap')->getSetting('groups');
     $base_dn = TBGContext::getModule('auth_ldap')->getSetting('b_dn');
     $dn_attr = TBGContext::getModule('auth_ldap')->getSetting('dn_attr');
     $username_attr = TBGContext::getModule('auth_ldap')->getSetting('u_attr');
     $fullname_attr = TBGContext::getModule('auth_ldap')->getSetting('f_attr');
     $buddyname_attr = TBGContext::getModule('auth_ldap')->getSetting('b_attr');
     $email_attr = TBGContext::getModule('auth_ldap')->getSetting('e_attr');
     $groups_members_attr = TBGContext::getModule('auth_ldap')->getSetting('g_attr');
     $user_class = TBGContext::getModule('auth_ldap')->getSetting('u_type');
     $group_class = TBGContext::getModule('auth_ldap')->getSetting('g_type');
     $users = array();
     $importcount = 0;
     $updatecount = 0;
     try {
         /*
          * Connect and bind to the control user
          */
         $connection = TBGContext::getModule('auth_ldap')->connect();
         TBGContext::getModule('auth_ldap')->bind($connection, TBGContext::getModule('auth_ldap')->getSetting('control_user'), TBGContext::getModule('auth_ldap')->getSetting('control_pass'));
         /*
          * Get a list of all users of a certain objectClass
          */
         $fields = array($fullname_attr, $buddyname_attr, $username_attr, $email_attr, 'cn', $dn_attr);
         $filter = '(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')';
         $results = ldap_search($connection, $base_dn, $filter, $fields);
         if (!$results) {
             TBGLogging::log('failed to search for users: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection));
         }
         $data = ldap_get_entries($connection, $results);
         /*
          * For every user that exists, process it.
          */
         for ($i = 0; $i != $data['count']; $i++) {
             $user_dn = $data[$i][strtolower($dn_attr)][0];
             /*
              * If groups are specified, perform group restriction tests
              */
             if ($validgroups != '') {
                 /*
                  * We will repeat this for every group, but groups are supplied as a comma-separated list
                  */
                 if (strstr($validgroups, ',')) {
                     $groups = explode(',', $validgroups);
                 } else {
                     $groups = array();
                     $groups[] = $validgroups;
                 }
                 // Assumed we are initially banned
                 $allowed = false;
                 foreach ($groups as $group) {
                     // No need to carry on looking if we have access
                     if ($allowed == true) {
                         continue;
                     }
                     /*
                      * Find the group we are looking for, we search the entire directory
                      * We want to find 1 group, if we don't get 1, silently ignore this group.
                      */
                     $fields2 = array($groups_members_attr);
                     $filter2 = '(&(cn=' . TBGLDAPAuthentication::getModule()->escape($group) . ')(objectClass=' . TBGLDAPAuthentication::getModule()->escape($group_class) . '))';
                     $results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
                     if (!$results2) {
                         TBGLogging::log('failed to search for user: '******'ldap', TBGLogging::LEVEL_FATAL);
                         throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection));
                     }
                     $data2 = ldap_get_entries($connection, $results2);
                     if ($data2['count'] != 1) {
                         continue;
                     }
                     /*
                      * Look through the group's member list. If we are found, grant access.
                      */
                     foreach ($data2[0][strtolower($groups_members_attr)] as $member) {
                         $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member);
                         $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $user_dn);
                         if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) {
                             $allowed = true;
                         }
                     }
                 }
                 if ($allowed == false) {
                     continue;
                 }
             }
             $users[$i] = array();
             /*
              * Set user's properties.
              * Realname is obtained from directory, if not found we set it to the username
              * Email is obtained from directory, if not found we set it to blank
              */
             if (!array_key_exists(strtolower($fullname_attr), $data[$i])) {
                 $users[$i]['realname'] = $data[$i]['cn'][0];
             } else {
                 $users[$i]['realname'] = $data[$i][strtolower($fullname_attr)][0];
             }
             if (!array_key_exists(strtolower($buddyname_attr), $data[$i])) {
                 $users[$i]['buddyname'] = $data[$i]['cn'][0];
             } else {
                 $users[$i]['buddyname'] = $data[$i][strtolower($buddyname_attr)][0];
             }
             if (!array_key_exists(strtolower($email_attr), $data[$i])) {
                 $users[$i]['email'] = '';
             } else {
                 $users[$i]['email'] = $data[$i][strtolower($email_attr)][0];
             }
             $users[$i]['username'] = $data[$i][strtolower($username_attr)][0];
         }
     } catch (Exception $e) {
         TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed'));
         TBGContext::setMessage('module_error_details', $e->getMessage());
         $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
     }
     /*
      * For every user that was found, either create a new user object, or update
      * the existing one. This will update the created and updated counts as appropriate.
      */
     foreach ($users as $ldapuser) {
         $username = $ldapuser['username'];
         $email = $ldapuser['email'];
         $realname = $ldapuser['realname'];
         $buddyname = $ldapuser['buddyname'];
         try {
             $user = TBGUser::getByUsername($username);
             if ($user instanceof TBGUser) {
                 $user->setRealname($realname);
                 $user->setEmail($email);
                 // update email address
                 $user->save();
                 $updatecount++;
             } else {
                 // create user
                 $user = new TBGUser();
                 $user->setUsername($username);
                 $user->setRealname($realname);
                 $user->setBuddyname($buddyname);
                 $user->setEmail($email);
                 $user->setEnabled();
                 $user->setActivated();
                 $user->setPassword($user->getJoinedDate() . $username);
                 $user->setJoined();
                 $user->save();
                 $importcount++;
             }
         } catch (Exception $e) {
             ldap_unbind($connection);
             TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed'));
             TBGContext::setMessage('module_error_details', $e->getMessage());
             $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
         }
     }
     ldap_unbind($connection);
     TBGContext::setMessage('module_message', TBGContext::getI18n()->__('Import successful! %imp users imported, %upd users updated from LDAP', array('%imp' => $importcount, '%upd' => $updatecount)));
     $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
 }
					<b><?php 
        echo __('This user was last seen online at %time%', array('%time%' => ''));
        ?>
</b><?php 
        echo tbg_formatTime($user->getLastSeen(), 11);
        ?>
 
				<?php 
    }
    ?>
			</div>
			<?php 
    TBGEvent::createNew('core', 'useractions_top', $user)->trigger();
    ?>
			<?php 
    if (TBGUser::isThisGuest() == false && $user->getID() != $tbg_user->getID()) {
        ?>
				<div style="padding: 2px;<?php 
        if ($tbg_user->isFriend($user)) {
            ?>
 display: none;<?php 
        }
        ?>
" id="add_friend_<?php 
        echo $user->getID() . '_' . $rnd_no;
        ?>
">
					<?php 
        echo javascript_link_tag(__('Become friends'), array('onclick' => "_updateDivWithJSONFeedback('" . make_url('toggle_friend', array('mode' => 'add', 'user_id' => $user->getID())) . "', null, 'toggle_friend_{$user->getID()}_{$rnd_no}_indicator', null, null, 'add_friend_{$user->getID()}_{$rnd_no}', ['add_friend_{$user->getID()}_{$rnd_no}'], ['remove_friend_{$user->getID()}_{$rnd_no}']);"));
        ?>
				</div>
Esempio n. 16
0
 public function runAccountPickUsername(TBGRequest $request)
 {
     if (TBGUser::isUsernameAvailable($request['selected_username'])) {
         $user = $this->getUser();
         $user->setUsername($request['selected_username']);
         $user->setOpenIdLocked(false);
         $user->setPassword(TBGUser::createPassword());
         $user->save();
         $this->getResponse()->setCookie('tbg3_username', $user->getUsername());
         $this->getResponse()->setCookie('tbg3_password', $user->getPassword());
         TBGContext::setMessage('username_chosen', true);
         $this->forward($this->getRouting()->generate('account'));
     }
     TBGContext::setMessage('error', $this->getI18n()->__('Could not pick the username "%username"', array('%username' => $request['selected_username'])));
     $this->forward($this->getRouting()->generate('account'));
 }
Esempio n. 17
0
<?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>
							<?php 
                echo __('Set resolution to %resolution', array('%resolution' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? TBGContext::factory()->TBGResolution((int) $action->getTargetValue())->getName() : __('Resolution provided by user')) . '</span>'));
                ?>
						<?php 
            } elseif ($action->getActionType() == TBGWorkflowTransitionAction::ACTION_SET_REPRODUCABILITY) {
                ?>
							<?php 
                echo __('Set reproducability to %reproducability', array('%reproducability' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($action->getTargetValue() ? TBGContext::factory()->TBGReproducability((int) $action->getTargetValue())->getName() : __('Reproducability provided by user')) . '</span>'));
                ?>
						<?php 
            } elseif ($action->getActionType() == TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE) {
                ?>
							<?php 
                if ($action->hasTargetValue()) {
                    $target_details = explode('_', $action->getTargetValue());
                    echo __('Assign issue to %assignee', array('%assignee' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . ($target_details[0] == 'user' ? TBGUser::getB2DBTable()->selectById((int) $target_details[1])->getNameWithUsername() : TBGTeam::getB2DBTable()->selectById((int) $target_details[1])->getName()) . '</span>'));
                } else {
                    echo __('Assign issue to %assignee', array('%assignee' => '<span id="workflowtransitionaction_' . $action->getID() . '_value" style="font-weight: bold;">' . __('User or team specified during transition') . '</span>'));
                }
                ?>
						<?php 
            }
            ?>
					<?php 
        } elseif ($action->getTargetValue()) {
            ?>
						<span class="generic_error_message"><?php 
            echo __('Invalid transition configuration');
            ?>
</span>
					<?php 
 /**
  * Set password
  * 
  * @param string $newpassword
  * 
  * @see TBGUser::changePassword
  */
 public function setPassword($newpassword)
 {
     $this->_password = TBGUser::hashPassword($newpassword, $this->getUser()->getSalt());
 }
Esempio n. 20
0
 /**
  * Return if the specified user can view this comment
  *
  * @param TBGUser $user A User
  *
  * @return boolean
  */
 public function isViewableByUser(TBGUser $user)
 {
     $can_view = false;
     try {
         // Show comment if valid user and...
         if ($user instanceof TBGUser) {
             if (!$this->isPublic() && $user->canSeeNonPublicComments() || $this->isPublic() && $user->canViewComments() || $this->postedByUser($user->getID())) {
                 $can_view = true;
             }
             //endif
         }
         //endif
     } catch (Exception $e) {
     }
     return $can_view;
 }
Esempio n. 21
0
 public function removeMember(TBGUser $user)
 {
     if ($this->_members !== null) {
         unset($this->_members[$user->getID()]);
     }
     if ($this->_num_members !== null) {
         $this->_num_members--;
     }
 }
 public function doLogin($username, $password, $mode = 1)
 {
     $validgroups = $this->getSetting('groups');
     $base_dn = $this->getSetting('b_dn');
     $dn_attr = $this->escape($this->getSetting('dn_attr'));
     $username_attr = $this->escape($this->getSetting('u_attr'));
     $fullname_attr = $this->escape($this->getSetting('f_attr'));
     $buddyname_attr = $this->escape($this->getSetting('b_attr'));
     $email_attr = $this->escape($this->getSetting('e_attr'));
     $groups_members_attr = $this->escape($this->getSetting('g_attr'));
     $user_class = TBGContext::getModule('auth_ldap')->getSetting('u_type');
     $group_class = TBGContext::getModule('auth_ldap')->getSetting('g_type');
     $email = null;
     $integrated_auth = $this->getSetting('integrated_auth');
     /*
      * Do the LDAP check here.
      * 
      * If a connection error or something, throw an exception and log
      * 
      * If we can, set $mail and $realname to correct values from LDAP
      * otherwise don't touch those variables.
      * 
      * To log do:
      * TBGLogging::log('error goes here', 'ldap', TBGLogging::LEVEL_FATAL);
      */
     try {
         /*
          * First job is to connect to our control user (may be an anonymous bind)
          * so we can find the user we want to log in as/validate.
          */
         $connection = $this->connect();
         $control_user = $this->getSetting('control_user');
         $control_password = $this->getSetting('control_pass');
         $this->bind($connection, $control_user, $control_password);
         // Assume bind successful, otherwise we would have had an exception
         /*
          * Search for a user with the username specified. We search in the base_dn, so we can
          * find users in multiple parts of the directory, and only return users of a specific
          * class (default person).
          * 
          * We want exactly 1 user to be returned. We get the user's full name, email, cn
          * and dn.
          */
         $fields = array($fullname_attr, $buddyname_attr, $email_attr, 'cn', $dn_attr);
         $filter = '(&(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')(' . $username_attr . '=' . $this->escape($username) . '))';
         $results = ldap_search($connection, $base_dn, $filter, $fields);
         if (!$results) {
             TBGLogging::log('failed to search for user: '******'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection));
         }
         $data = ldap_get_entries($connection, $results);
         // User does not exist
         if ($data['count'] == 0) {
             TBGLogging::log('could not find user ' . $username . ', class ' . $user_class . ', attribute ' . $username_attr, 'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('User does not exist in the directory'));
         }
         // If we have more than 1 user, something is seriously messed up...
         if ($data['count'] > 1) {
             TBGLogging::log('too many users for ' . $username . ', class ' . $user_class . ', attribute ' . $username_attr, 'ldap', TBGLogging::LEVEL_FATAL);
             throw new Exception(TBGContext::geti18n()->__('This user was found multiple times in the directory, please contact your admimistrator'));
         }
         /*
          * If groups are specified, perform group restriction tests
          */
         if ($validgroups != '') {
             /*
              * We will repeat this for every group, but groups are supplied as a comma-separated list
              */
             if (strstr($validgroups, ',')) {
                 $groups = explode(',', $validgroups);
             } else {
                 $groups = array();
                 $groups[] = $validgroups;
             }
             // Assumed we are initially banned
             $allowed = false;
             foreach ($groups as $group) {
                 // No need to carry on looking if we have access
                 if ($allowed == true) {
                     continue;
                 }
                 /*
                  * Find the group we are looking for, we search the entire directory as per users (See that stuff)
                  * We want to find 1 group, if we don't get 1, silently ignore this group.
                  */
                 $fields2 = array($groups_members_attr);
                 $filter2 = '(&(objectClass=' . TBGLDAPAuthentication::getModule()->escape($group_class) . ')(cn=' . $this->escape($group) . '))';
                 $results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
                 if (!$results2) {
                     TBGLogging::log('failed to search for user after binding: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL);
                     throw new Exception(TBGContext::geti18n()->__('Search failed ') . ldap_error($connection));
                 }
                 $data2 = ldap_get_entries($connection, $results2);
                 if ($data2['count'] != 1) {
                     continue;
                 }
                 /*
                  * Look through the group's member list. If we are found, grant access.
                  */
                 foreach ($data2[0][strtolower($groups_members_attr)] as $member) {
                     $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member);
                     $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $data[0][strtolower($dn_attr)][0]);
                     if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) {
                         $allowed = true;
                     }
                 }
             }
             if ($allowed == false) {
                 throw new Exception(TBGContext::getI18n()->__('You are not a member of a group allowed to log in'));
             }
         }
         /*
          * Set user's properties.
          * Realname is obtained from directory, if not found we set it to the username
          * Email is obtained from directory, if not found we set it to blank
          */
         if (!array_key_exists(strtolower($fullname_attr), $data[0])) {
             $realname = $username;
         } else {
             $realname = $data[0][strtolower($fullname_attr)][0];
         }
         if (!array_key_exists(strtolower($buddyname_attr), $data[0])) {
             $buddyname = $username;
         } else {
             $buddyname = $data[0][strtolower($buddyname_attr)][0];
         }
         if (!array_key_exists(strtolower($email_attr), $data[0])) {
             $email = '';
         } else {
             $email = $data[0][strtolower($email_attr)][0];
         }
         /*
          * If we are performing a non integrated authentication login, 
          * now bind to the user and see if the credentials
          * are valid. We bind using the full DN of the user, so no need for DOMAIN\ stuff
          * on Windows, and more importantly it fixes other servers.
          * 
          * If the bind fails (exception), we throw a nicer exception and don't continue.
          */
         if ($mode == 1 && !$integrated_auth) {
             try {
                 if (!is_array($data[0][strtolower($dn_attr)])) {
                     $dn = $data[0][strtolower($dn_attr)];
                 } else {
                     $dn = $data[0][strtolower($dn_attr)][0];
                 }
                 $bind = $this->bind($connection, $this->escape($dn), $password);
             } catch (Exception $e) {
                 throw new Exception(TBGContext::geti18n()->__('Your password was not accepted by the server'));
             }
         } elseif ($mode == 1) {
             if (!isset($_SERVER[$this->getSetting('integrated_auth_header')]) || $_SERVER[$this->getSetting('integrated_auth_header')] != $username) {
                 throw new Exception(TBGContext::geti18n()->__('HTTP authentication internal error.'));
             }
         }
     } catch (Exception $e) {
         ldap_unbind($connection);
         throw $e;
     }
     try {
         /*
          * Get the user object. If the user exists, update the user's
          * data from the directory.
          */
         $user = TBGUser::getByUsername($username);
         if ($user instanceof TBGUser) {
             $user->setBuddyname($buddyname);
             $user->setRealname($realname);
             $user->setPassword($user->getJoinedDate() . $username);
             // update password
             $user->setEmail($email);
             // update email address
             $user->save();
         } else {
             /*
              * If not, and we are performing an initial login, create the user object
              * if we are validating a log in, kick the user out as the session is invalid.
              */
             if ($mode == 1) {
                 // create user
                 $user = new TBGUser();
                 $user->setUsername($username);
                 $user->setRealname('temporary');
                 $user->setBuddyname($username);
                 $user->setEmail('temporary');
                 $user->setEnabled();
                 $user->setActivated();
                 $user->setJoined();
                 $user->setPassword($user->getJoinedDate() . $username);
                 $user->save();
             } else {
                 throw new Exception('User does not exist in TBG');
             }
         }
     } catch (Exception $e) {
         ldap_unbind($connection);
         throw $e;
     }
     ldap_unbind($connection);
     /*
      * Set cookies and return user row for general operations.
      */
     TBGContext::getResponse()->setCookie('tbg3_username', $username);
     TBGContext::getResponse()->setCookie('tbg3_password', TBGUser::hashPassword($user->getJoinedDate() . $username, $user->getSalt()));
     return TBGUsersTable::getTable()->getByUsername($username);
 }
Esempio n. 23
0
 public function removeMember(TBGUser $user)
 {
     if ($this->_members !== null) {
         unset($this->_members[$user->getID()]);
     }
     if ($this->_num_members !== null) {
         $this->_num_members--;
     }
     TBGClientMembersTable::getTable()->removeUserFromClient($user->getID(), $this->getID());
 }
Esempio n. 24
0
?>
</div>
			<?php 
if ($user->isEmailPublic() || $tbg_user->canAccessConfigurationPage(TBGSettings::CONFIGURATION_SECTION_USERS)) {
    ?>
				<div class="user_email"><?php 
    echo $user->getEmail();
    ?>
</div>
			<?php 
}
?>
		</div>
		<div class="user_details">
		<?php 
if (TBGUser::isThisGuest() == false) {
    ?>
			<div id="friends_message_<?php 
    echo $user->getUsername() . '_' . $rnd_no;
    ?>
" style="padding: 2px 0 2px 0; font-size: 0.9em;"></div>
			<?php 
    if ($user->getID() != TBGContext::getUser()->getID() && !TBGContext::getUser()->isFriend($user) && !$user->isGuest()) {
        ?>
				<div id="friends_link_<?php 
        echo $user->getUsername() . '_' . $rnd_no;
        ?>
">
					<span style="padding: 2px; <?php 
        if (TBGContext::getUser()->isFriend($user)) {
            ?>
Esempio n. 25
0
 public function runUpdateIssueDetails(TBGRequest $request)
 {
     $this->forward403if(TBGContext::getCurrentProject()->isArchived());
     $this->error = false;
     try {
         $i18n = TBGContext::getI18n();
         $issue = TBGIssue::getIssueFromLink($request['issue_no']);
         if ($issue->getProject()->getID() != $this->selected_project->getID()) {
             throw new Exception($i18n->__('This issue is not valid for this project'));
         }
         if (!$issue instanceof TBGIssue) {
             die;
         }
         $workflow_transition = null;
         if ($passed_transition = $request['workflow_transition']) {
             //echo "looking for transition ";
             $key = str_replace(' ', '', mb_strtolower($passed_transition));
             //echo $key . "\n";
             foreach ($issue->getAvailableWorkflowTransitions() as $transition) {
                 //echo str_replace(' ', '', mb_strtolower($transition->getName())) . "?";
                 if (mb_strpos(str_replace(' ', '', mb_strtolower($transition->getName())), $key) !== false) {
                     $workflow_transition = $transition;
                     //echo "found transition " . $transition->getID();
                     break;
                 }
                 //echo "no";
             }
             if (!$workflow_transition instanceof TBGWorkflowTransition) {
                 throw new Exception("This transition ({$key}) is not valid");
             }
         }
         $fields = $request->getRawParameter('fields', array());
         $return_values = array();
         if ($workflow_transition instanceof TBGWorkflowTransition) {
             foreach ($fields as $field_key => $field_value) {
                 $classname = "TBG" . ucfirst($field_key);
                 $method = "set" . ucfirst($field_key);
                 $choices = $classname::getAll();
                 $found = false;
                 foreach ($choices as $choice_key => $choice) {
                     if (mb_strpos(str_replace(' ', '', mb_strtolower($choice->getName())), str_replace(' ', '', mb_strtolower($field_value))) !== false) {
                         $request->setParameter($field_key . '_id', $choice->getId());
                         break;
                     }
                 }
             }
             $request->setParameter('comment_body', $request['message']);
             $return_values['applied_transition'] = $workflow_transition->getName();
             if ($workflow_transition->validateFromRequest($request)) {
                 $retval = $workflow_transition->transitionIssueToOutgoingStepFromRequest($issue, $request);
                 $return_values['transition_ok'] = $retval === false ? false : true;
             } else {
                 $return_values['transition_ok'] = false;
                 $return_values['message'] = "Please pass all information required for this transition";
             }
         } elseif ($issue->isUpdateable()) {
             foreach ($fields as $field_key => $field_value) {
                 try {
                     if (in_array($field_key, array_merge(array('title', 'state'), TBGDatatype::getAvailableFields(true)))) {
                         switch ($field_key) {
                             case 'state':
                                 $issue->setState($field_value == 'open' ? TBGIssue::STATE_OPEN : TBGIssue::STATE_CLOSED);
                                 break;
                             case 'title':
                                 if ($field_value != '') {
                                     $issue->setTitle($field_value);
                                 } else {
                                     throw new Exception($i18n->__('Invalid title'));
                                 }
                                 break;
                             case 'description':
                             case 'reproduction_steps':
                                 $method = "set" . ucfirst($field_key);
                                 $issue->{$method}($field_value);
                                 break;
                             case 'status':
                             case 'resolution':
                             case 'reproducability':
                             case 'priority':
                             case 'severity':
                             case 'category':
                                 $classname = "TBG" . ucfirst($field_key);
                                 $method = "set" . ucfirst($field_key);
                                 $choices = $classname::getAll();
                                 $found = false;
                                 foreach ($choices as $choice_key => $choice) {
                                     if (str_replace(' ', '', mb_strtolower($choice->getName())) == str_replace(' ', '', mb_strtolower($field_value))) {
                                         $issue->{$method}($choice);
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     throw new Exception('Could not find this value');
                                 }
                                 break;
                             case 'percent_complete':
                                 $issue->setPercentCompleted($field_value);
                                 break;
                             case 'owner':
                             case 'assignee':
                                 $set_method = "set" . ucfirst($field_key);
                                 $unset_method = "un{$set_method}";
                                 switch (mb_strtolower($field_value)) {
                                     case 'me':
                                         $issue->{$set_method}(TBGContext::getUser());
                                         break;
                                     case 'none':
                                         $issue->{$unset_method}();
                                         break;
                                     default:
                                         try {
                                             $user = TBGUser::findUser(mb_strtolower($field_value));
                                             if ($user instanceof TBGUser) {
                                                 $issue->{$set_method}($user);
                                             }
                                         } catch (Exception $e) {
                                             throw new Exception('No such user found');
                                         }
                                         break;
                                 }
                                 break;
                             case 'estimated_time':
                             case 'spent_time':
                                 $set_method = "set" . ucfirst(str_replace('_', '', $field_key));
                                 $issue->{$set_method}($field_value);
                                 break;
                             case 'milestone':
                                 $found = false;
                                 foreach ($this->selected_project->getMilestones() as $milestone) {
                                     if (str_replace(' ', '', mb_strtolower($milestone->getName())) == str_replace(' ', '', mb_strtolower($field_value))) {
                                         $issue->setMilestone($milestone->getID());
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     throw new Exception('Could not find this milestone');
                                 }
                                 break;
                             default:
                                 throw new Exception($i18n->__('Invalid field'));
                         }
                     }
                     $return_values[$field_key] = array('success' => true);
                 } catch (Exception $e) {
                     $return_values[$field_key] = array('success' => false, 'error' => $e->getMessage());
                 }
             }
         }
         if (!$workflow_transition instanceof TBGWorkflowTransition) {
             $issue->getWorkflow()->moveIssueToMatchingWorkflowStep($issue);
         }
         if (!array_key_exists('transition_ok', $return_values) || $return_values['transition_ok']) {
             $comment = new TBGComment();
             $comment->setTitle('');
             $comment->setContent($request->getParameter('message', null, false));
             $comment->setPostedBy(TBGContext::getUser()->getID());
             $comment->setTargetID($issue->getID());
             $comment->setTargetType(TBGComment::TYPE_ISSUE);
             $comment->setModuleName('core');
             $comment->setIsPublic(true);
             $comment->setSystemComment(false);
             $comment->save();
             $issue->setSaveComment($comment);
             $issue->save();
         }
         $this->return_values = $return_values;
     } catch (Exception $e) {
         //$this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }
Esempio n. 26
0
function tbg_get_userstate_image(TBGUser $user)
{
    switch (true) {
        case $user->isOffline():
            return image_tag('user-offline.png', array('class' => 'userstate', 'title' => __($user->getState()->getName())));
            break;
        case $user->getState()->isBusy():
        case $user->getState()->isUnavailable():
            return image_tag('user-busy.png', array('class' => 'userstate', 'title' => __($user->getState()->getName())));
            break;
        case $user->getState()->isAbsent():
            return image_tag('user-invisible.png', array('class' => 'userstate', 'title' => __($user->getState()->getName())));
            break;
        case $user->getState()->isInMeeting():
            return image_tag('user-away-extended.png', array('class' => 'userstate', 'title' => __($user->getState()->getName())));
            break;
        case $user->getState()->isUnavailable():
            return image_tag('user-away.png', array('class' => 'userstate', 'title' => __($user->getState()->getName())));
            break;
        default:
            return image_tag('user-online.png', array('class' => 'userstate', 'title' => __($user->getState()->getName())));
            break;
    }
}
 public function hasValidTarget()
 {
     if (!$this->_target_value) {
         return true;
     }
     switch ($this->_action_type) {
         case self::ACTION_ASSIGN_ISSUE:
             $target_details = explode('_', $this->_target_value);
             return (bool) ($target_details[0] == 'user') ? TBGUser::doesIDExist($target_details[1]) : TBGTeam::doesIDExist($target_details[1]);
             break;
         case self::ACTION_SET_PERCENT:
             return (bool) ($this->_target_value > -1);
             break;
         case self::ACTION_SET_MILESTONE:
             return (bool) TBGMilestone::doesIDExist($this->_target_value);
             break;
         case self::ACTION_SET_PRIORITY:
             return (bool) TBGPriority::has($this->_target_value);
             break;
         case self::ACTION_SET_STATUS:
             return (bool) TBGStatus::has($this->_target_value);
             break;
         case self::ACTION_SET_REPRODUCABILITY:
             return (bool) TBGReproducability::has($this->_target_value);
             break;
         case self::ACTION_SET_RESOLUTION:
             return (bool) TBGResolution::has($this->_target_value);
             break;
         default:
             return true;
     }
 }
Esempio n. 28
0
 public function canUserSet(TBGUser $user)
 {
     $retval = $user->hasPermission($this->getPermissionsKey(), $this->getID(), 'core', true);
     $retval = $retval === null ? $user->hasPermission($this->getPermissionsKey(), 0, 'core', true) : $retval;
     return $retval !== null ? $retval : TBGSettings::isPermissive();
 }
Esempio n. 29
0
 public function runUpdateUser(TBGRequest $request)
 {
     try {
         $user = TBGContext::factory()->TBGUser($request->getParameter('user_id'));
         if ($user instanceof TBGUser) {
             $testuser = TBGUser::getByUsername($request->getParameter('username'));
             if (!$testuser instanceof TBGUser || $testuser->getID() == $user->getID()) {
                 $user->setUsername($request->getParameter('username'));
             } else {
                 return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('This username is already taken')));
             }
             $password_changed = false;
             if ($request->getParameter('password_action') == 'change' && $request->getParameter('new_password_1') && $request->getParameter('new_password_2')) {
                 if ($request->getParameter('new_password_1') == $request->getParameter('new_password_2')) {
                     $user->setPassword($request->getParameter('new_password_1'));
                     $password_changed = true;
                 } else {
                     return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('Please enter the new password twice')));
                 }
             } elseif ($request->getParameter('password_action') == 'random') {
                 $random_password = TBGUser::createPassword();
                 $user->setPassword($random_password);
                 $password_changed = true;
             }
             $user->setRealname($request->getParameter('realname'));
             $return_options = array();
             try {
                 if ($group = TBGContext::factory()->TBGGroup($request->getParameter('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(TBGContext::getI18n()->__('Invalid user group'));
             }
             $existing_teams = array_keys($user->getTeams());
             $new_teams = array();
             $user->clearTeams();
             try {
                 foreach ($request->getParameter('teams', array()) as $team_id => $team) {
                     if ($team = TBGContext::factory()->TBGTeam($team_id)) {
                         $new_teams[] = $team_id;
                         $user->addToTeam($team);
                     }
                 }
             } catch (Exception $e) {
                 throw new Exception(TBGContext::getI18n()->__('One or more teams were invalid'));
             }
             try {
                 $user->clearClients();
                 foreach ($request->getParameter('clients', array()) as $client_id => $client) {
                     if ($client = TBGContext::factory()->TBGClient($client_id)) {
                         $new_clients[] = $client_id;
                         $user->addToClient($client);
                     }
                 }
             } catch (Exception $e) {
                 throw new Exception(TBGContext::getI18n()->__('One or more clients were invalid'));
             }
             $user->setBuddyname($request->getParameter('nickname'));
             $user->setActivated((bool) $request->getParameter('activated'));
             $user->setEmail($request->getParameter('email'));
             $user->setEnabled((bool) $request->getParameter('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] = TBGContext::factory()->TBGGroup($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());
                 foreach ($teams_to_update as $team_id) {
                     $return_options['update_teams']['ids'][] = $team_id;
                     $return_options['update_teams']['membercounts'][$team_id] = TBGContext::factory()->TBGTeam($team_id)->getNumberOfMembers();
                 }
             }
             $return_options['failed'] = false;
             $template_options = array('user' => $user);
             if (isset($random_password)) {
                 $template_options['random_password'] = $random_password;
             }
             $return_options['content'] = $this->getTemplateHTML('configuration/finduser_row', $template_options);
             $return_options['title'] = TBGContext::getI18n()->__('User updated!');
             if ($password_changed) {
                 $return_options['message'] = TBGContext::getI18n()->__('The password was changed');
             }
             return $this->renderJSON($return_options);
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('This user could not be updated: %message%', array('%message%' => $e->getMessage()))));
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('failed' => true, 'error' => TBGContext::getI18n()->__('This user could not be updated')));
 }
Esempio n. 30
0
 /**
  * Register a user as working on the issue
  * 
  * @param TBGUser $user
  */
 public function startWorkingOnIssue(TBGUser $user)
 {
     $this->_addChangedProperty('_being_worked_on_by_user', $user->getID());
     $this->_being_worked_on_by_user_since = NOW;
 }