Esempio n. 1
0
 /**
  * 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());
 }
Esempio n. 2
0
 /**
  * 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));
     }
 }
Esempio n. 3
0
 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()));
     }
 }
Esempio n. 4
0
 /**
  * Configuration import page
  *
  * @param framework\Request $request
  */
 public function runIndex(framework\Request $request)
 {
     if ($request->isPost()) {
         if ($request['import_sample_data']) {
             $transaction = \b2db\Core::startTransaction();
             $users = array();
             $user1 = new entities\User();
             $user1->setUsername('john');
             $user1->setPassword('john');
             $user1->setBuddyname('John');
             $user1->setRealname('John');
             $user1->setActivated();
             $user1->setEnabled();
             $user1->save();
             $users[] = $user1;
             $user2 = new entities\User();
             $user2->setUsername('jane');
             $user2->setPassword('jane');
             $user2->setBuddyname('Jane');
             $user2->setRealname('Jane');
             $user2->setActivated();
             $user2->setEnabled();
             $user2->save();
             $users[] = $user2;
             $user3 = new entities\User();
             $user3->setUsername('jackdaniels');
             $user3->setPassword('jackdaniels');
             $user3->setBuddyname('Jack');
             $user3->setRealname('Jack Daniels');
             $user3->setActivated();
             $user3->setEnabled();
             $user3->save();
             $users[] = $user3;
             $project1 = new entities\Project();
             $project1->setName('Sample project 1');
             $project1->setOwner($users[rand(0, 2)]);
             $project1->setLeader($users[rand(0, 2)]);
             $project1->setQaResponsible($users[rand(0, 2)]);
             $project1->setDescription('This is a sample project that is awesome. Try it out!');
             $project1->setHomepage('http://www.google.com');
             $project1->save();
             $project2 = new entities\Project();
             $project2->setName('Sample project 2');
             $project2->setOwner($users[rand(0, 2)]);
             $project2->setLeader($users[rand(0, 2)]);
             $project2->setQaResponsible($users[rand(0, 2)]);
             $project2->setDescription('This is the second sample project. Not as awesome as the first one, but still worth a try!');
             $project2->setHomepage('http://www.bing.com');
             $project2->save();
             foreach (array($project1, $project2) as $project) {
                 for ($cc = 1; $cc <= 5; $cc++) {
                     $milestone = new entities\Milestone();
                     $milestone->setName("Milestone {$cc}");
                     $milestone->setProject($project);
                     $milestone->setType(entities\Milestone::TYPE_REGULAR);
                     if ((bool) rand(0, 1)) {
                         $milestone->setScheduledDate(NOW + 100000 * (20 * $cc));
                     }
                     $milestone->save();
                 }
             }
             $p1_milestones = $project1->getMilestones();
             $p2_milestones = $project2->getMilestones();
             $issues = array();
             $priorities = entities\Priority::getAll();
             $categories = entities\Category::getAll();
             $severities = entities\Severity::getAll();
             $statuses = entities\Status::getAll();
             $reproducabilities = entities\Reproducability::getAll();
             $lorem_ipsum = \thebuggenie\modules\publish\entities\tables\Articles::getTable()->getArticleByName('LoremIpsum');
             $lorem_words = explode(' ', $lorem_ipsum->getContent());
             foreach (array('bugreport', 'featurerequest', 'enhancement', 'idea') as $issuetype) {
                 $issuetype = entities\Issuetype::getByKeyish($issuetype);
                 for ($cc = 1; $cc <= 10; $cc++) {
                     $issue1 = new entities\Issue();
                     $issue1->setProject($project1);
                     $issue1->setPostedBy($users[rand(0, 2)]);
                     $issue1->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue1->setTitle(ucfirst($title_string));
                     $issue1->setDescription($description_string);
                     $issue1->setIssuetype($issuetype);
                     $issue1->setMilestone($p1_milestones[array_rand($p1_milestones)]);
                     $issue1->setPriority($priorities[array_rand($priorities)]);
                     $issue1->setCategory($categories[array_rand($categories)]);
                     $issue1->setSeverity($severities[array_rand($severities)]);
                     $issue1->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue1->setPercentCompleted(rand(0, 100));
                     $issue1->save();
                     $issue1->setStatus($statuses[array_rand($statuses)]);
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue1->save();
                     $issues[] = $issue1;
                     $issue2 = new entities\Issue();
                     $issue2->setProject($project2);
                     $issue2->setPostedBy($users[rand(0, 2)]);
                     $issue2->setPosted(NOW - 86400 * rand(1, 30));
                     $title_string = '';
                     $description_string = '';
                     $rand_length = rand(4, 15);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $title_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $title_string .= '.';
                             $ucnext = true;
                         }
                         $title_string .= ' ';
                     }
                     $rand_length = rand(40, 500);
                     $ucnext = true;
                     for ($ll = 1; $ll <= $rand_length; $ll++) {
                         $word = str_replace(array(',', '.', "\r", "\n"), array('', '', '', ''), $lorem_words[array_rand($lorem_words)]);
                         $word = $ucnext || rand(1, 40) == 19 ? ucfirst($word) : mb_strtolower($word);
                         $description_string .= $word;
                         $ucnext = false;
                         if ($ll == $rand_length || rand(1, 15) == 5) {
                             $description_string .= '.';
                             $ucnext = true;
                             $description_string .= $ll != $rand_length && rand(1, 15) == 8 ? "\n\n" : ' ';
                         } else {
                             $description_string .= ' ';
                         }
                     }
                     $issue2->setTitle(ucfirst($title_string));
                     $issue2->setDescription($description_string);
                     $issue2->setIssuetype($issuetype);
                     $issue2->setMilestone($p2_milestones[array_rand($p2_milestones)]);
                     $issue2->setPriority($priorities[array_rand($priorities)]);
                     $issue2->setCategory($categories[array_rand($categories)]);
                     $issue2->setSeverity($severities[array_rand($severities)]);
                     $issue2->setReproducability($reproducabilities[array_rand($reproducabilities)]);
                     $issue2->setPercentCompleted(rand(0, 100));
                     if (rand(0, 1)) {
                         $issue1->setAssignee($users[array_rand($users)]);
                     }
                     $issue2->save();
                     $issue2->setStatus($statuses[array_rand($statuses)]);
                     $issue2->save();
                     $issues[] = $issue2;
                 }
             }
             $rand_issues_to_close = rand(8, 40);
             $resolutions = entities\Resolution::getAll();
             for ($cc = 1; $cc <= $rand_issues_to_close; $cc++) {
                 $issue = array_slice($issues, array_rand($issues), 1);
                 $issue = $issue[0];
                 $issue->setResolution($resolutions[array_rand($resolutions)]);
                 $issue->close();
                 $issue->save();
             }
             $this->imported_data = true;
             $roles = entities\Role::getAll();
             foreach (array($project1, $project2) as $project) {
                 foreach ($users as $user) {
                     $project->addAssignee($user, $roles[array_rand($roles)]);
                 }
             }
             $transaction->commitAndEnd();
         }
     }
     $project1 = entities\Project::getByKey('sampleproject1');
     $project2 = entities\Project::getByKey('sampleproject2');
     $this->canimport = !$project1 instanceof entities\Project && !$project2 instanceof entities\Project;
 }