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')));
 }
示例#2
0
 /**
  * Return (or create, assuming no external auth backend) a user based on
  * a provided openid identity
  * 
  * @param string $identity
  * 
  * @return TBGUser 
  */
 public static function getByOpenID($identity)
 {
     $user = null;
     if ($user_id = TBGOpenIdAccountsTable::getTable()->getUserIDfromIdentity($identity)) {
         $user = TBGContext::factory()->TBGUser($user_id);
     } elseif (!TBGSettings::isUsingExternalAuthenticationBackend() && TBGSettings::getOpenIDStatus() == 'all') {
         $user = new TBGUser();
         $user->setPassword(TBGUser::createPassword());
         $user->setUsername(TBGUser::createPassword() . TBGUser::createPassword());
         $user->setOpenIdLocked();
         $user->setActivated();
         $user->setEnabled();
         $user->setValidated();
         $user->save();
     }
     return $user;
 }
 /**
  * Registration logic part 2 - add user data
  *  
  * @param TBGRequest $request
  */
 public function runRegister2(TBGRequest $request)
 {
     TBGContext::loadLibrary('common');
     $i18n = TBGContext::getI18n();
     try {
         $username = $request->getParameter('username');
         $buddyname = $request->getParameter('buddyname');
         $email = $request->getParameter('email_address');
         $confirmemail = $request->getParameter('email_confirm');
         $security = $request->getParameter('verification_no');
         $realname = $request->getParameter('realname');
         $fields = array();
         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;
             $valid_domain = false;
             if (tbg_check_syntax($email, "EMAIL")) {
                 $email_ok = true;
             }
             if ($email_ok && TBGSettings::get('limit_registration') != '') {
                 $allowed_domains = preg_replace('/[[:space:]]*,[[:space:]]*/', '|', TBGSettings::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 (count($allowed_domains) > 0)
                 		{
                 			foreach ($allowed_domains as $allowed_domain)
                 			{
                 				$allowed_domain = '@' . trim($allowed_domain);
                 				if (strpos($email, $allowed_domain) !== false ) //strpos checks if $to
                 				{
                 					$valid_domain = true;
                 					break;
                 				}
                 			}
                 			
                 		}
                 		else
                 		{
                 			$valid_domain = true;
                 		}*/
             }
             /*if ($valid_domain == 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 = TBGUser::createPassword();
             $user = new TBGUser();
             $user->setUsername($username);
             $user->setRealname($realname);
             $user->setBuddyname($buddyname);
             $user->setGroup(TBGSettings::getDefaultGroup());
             $user->setEnabled();
             $user->setPassword($password);
             $user->setEmail($email);
             $user->setJoined();
             $user->save();
             if ($user->isActivated()) {
                 return $this->renderJSON(array('message' => $i18n->__('A password has been autogenerated for you. To log in, use the following password:'******' <b>' . $password . '</b>'));
             }
             return $this->renderJSON(array('message' => $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.')));
         } 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) {
         return $this->renderJSON(array('failed' => true, 'error' => $i18n->__($e->getMessage()), 'fields' => $fields));
     }
 }
示例#4
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'));
 }
示例#5
0
 public function listen_registerUser(TBGEvent $event)
 {
     if ($this->isActivationNeeded() && $this->isOutgoingNotificationsEnabled()) {
         $user = $event->getSubject();
         $password = TBGUser::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();
     }
 }