Beispiel #1
0
 public function Fire()
 {
     if ($this->input->do == 'submit') {
         if (!filter_var($this->input->email, FILTER_VALIDATE_EMAIL)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('INVALID_EMAIL')));
             return;
         }
         if (strlen($this->input->password) <= 4) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('PASSWORD_TOO_SHORT')));
             return;
         }
         $stmt = Bugdar::$db->Prepare("SELECT COUNT(*) AS count FROM users WHERE email = ?");
         $stmt->Execute(array($this->input->email));
         if ($stmt->FetchObject()->count > 0) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('EMAIL_IN_USE')));
             return;
         }
         $alias = preg_replace('/[^a-zA-Z0-9\\-_,\\. ]/', '', $this->input->alias);
         $salt = phalanx\base\Random(10);
         $user = new User();
         $user->email = $this->input->email;
         $user->alias = preg_replace('/[^a-zA-Z0-9\\-_,\\. ]/', '', $this->input->alias);
         $user->password = sha1($this->input->password);
         $user->usergroup_id = Usergroup::ROLE_REGISTERED;
         $user->Insert();
         $this->user_id = $user->user_id;
         EventPump::Pump()->PostEvent(new StandardSuccessEvent('login', l10n::S('USER_REGISTER_SUCCESS')));
     }
 }
Beispiel #2
0
 public function Fire()
 {
     if ($this->input->do == 'submit') {
         $bug = new Bug($this->input->bug_id);
         try {
             $bug->FetchInto();
         } catch (phalanx\data\ModelException $e) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND')));
             return;
         }
         $body = trim($this->input->body);
         if (empty($body)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('COMMENT_MISSING_BODY')));
             return;
         }
         $comment = new Comment();
         $comment->bug_id = $bug_id;
         $comment->post_user_id = Bugdar::$auth->current_user();
         $comment->post_date = time();
         $comment->body = $body;
         $comment->Insert();
         $this->comment_id = $comment->comment_id;
         $search = new SearchEngine();
         $search->IndexBug($bug);
         EventPump::Pump()->PostEvent(new StandardSuccessEvent('view_bug/' . $bug_id, l10n::S('USER_REGISTER_SUCCESS')));
     }
 }
Beispiel #3
0
 public function Fire()
 {
     $stmt = Bugdar::$db->Prepare("SELECT * FROM " . TABLE_PREFIX . "users WHERE user_id = :id OR alias = :id");
     $stmt->Execute(array('id' => $this->input->_id));
     if (!($this->user = $stmt->FetchObject())) {
         EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('INVALID_USER')));
     }
 }
Beispiel #4
0
 public function testBadPassword()
 {
     Bugdar::$auth = new AuthenticationTest(NULL);
     $data = new phalanx\base\PropertyBag(array('do' => 'fire', 'email' => self::EMAIL, 'password' => 'foo'));
     $event = new UserLoginEvent($data);
     $self =& $this;
     EventPump::Pump()->PostEvent($event);
     $this->assertFalse($event->was_successful());
 }
Beispiel #5
0
 public function testInvalidEmail()
 {
     Bugdar::$auth = new AuthenticationTest(NULL);
     $data = new phalanx\base\PropertyBag(array('do' => 'submit', 'email' => 'robert', 'alias' => 'Robert', 'password' => 'abc123'));
     $event = new UserRegisterEvent($data);
     EventPump::Pump()->PostEvent($event);
     $last_event = EventPump::Pump()->GetEventChain()->Top();
     $this->assertType('StandardErrorEvent', $last_event);
 }
Beispiel #6
0
 public function testSavingInvalidSetting()
 {
     $data = new \phalanx\base\PropertyBag(array('settings' => array('webroot' => '/bugdar2/', 'badsetting' => 'test'), '_method' => 'POST'));
     $event = new AdminSettingsEvent($data);
     EventPump::Pump()->PostEvent($event);
     $settings = $event->settings();
     $this->assertEquals('/bugdar2/', $settings['webroot']);
     $this->assertNull($settings['badsetting']);
     $row = Bugdar::$db->Query("SELECT * FROM settings WHERE setting = 'webroot'")->FetchObject();
     $this->assertEquals('/bugdar2/', $row->value);
     $row = Bugdar::$db->Query("SELECT * FROM settings WHERE setting = 'badsetting'")->FetchObject();
     $this->assertNull($row->value);
 }
Beispiel #7
0
 public function Fire()
 {
     $bug = new Bug($this->input->_id);
     try {
         $bug->FetchInto();
     } catch (\phalanx\data\ModelException $e) {
         EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND')));
         return;
     }
     $this->bug = $bug;
     $this->bug_reporter = $bug->FetchReporter();
     $this->attributes = $bug->FetchAttributes();
     $this->comments = $bug->FetchComments();
 }
 public function Fire()
 {
     // If an ID was passed, try updating the record.
     if ($this->input->_id) {
         try {
             $this->usergroup = new Usergroup($this->input->_id);
             $this->usergroup->FetchInto();
         } catch (\phalanx\data\ModelException $e) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('ERROR_INVALID_ID')));
             return;
         }
     } else {
         // Otherwise, create a new one.
         $this->usergroup = new Usergroup();
     }
     if ($this->input->_method == 'POST') {
         $title = \phalanx\data\Cleaner::HTML($this->input->title);
         if (empty($title)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent('The title field is required.'));
             return;
         }
         $this->usergroup->title = $title;
         if (!empty($this->input->display_title)) {
             $this->usergroup->display_title = \phalanx\data\Cleaner::HTML($this->input->display_title);
         }
         $mask = 0;
         foreach ($this->input->permissions as $name => $bit) {
             $mask += $bit * Usergroup::$permissions[$name];
         }
         $this->usergroup->mask = $mask;
         // Save the actual record.
         if ($this->input->_id) {
             $this->usergroup->Update();
         } else {
             $this->usergroup->Insert();
         }
     }
 }
Beispiel #9
0
function EventLink($event, $params = NULL)
{
    // Determine the base URL.
    $url = Bugdar::$settings['webroot'];
    // Use the ViewOutputHandler's closure to convert the class name to viewese.
    // We then reverse new_comment to get comment_new.
    $f = EventPump::Pump()->output_handler()->template_loader();
    $parts = explode('_', $f($event));
    $parts = array_reverse($parts);
    $url .= implode('_', $parts);
    // Append parameters.
    if ($params !== NULL) {
        if (KeyDescender::IsDescendable($params)) {
            foreach ($params as $key => $value) {
                $url .= '/' . Cleaner::HTML($key) . '/' . Cleaner::HTML($value);
            }
        } else {
            // This is a single-value type. HTML encode it and append it as the _id
            // parameter.
            $url .= '/' . Cleaner::HTML($params);
        }
    }
    return $url;
}
Beispiel #10
0
 public function Fire()
 {
     if ($this->input->do == 'fire') {
         $user = new User();
         $user->set_condition('email = :email');
         $user->email = $this->input->email;
         try {
             $user = $user->Fetch();
         } catch (phalanx\data\ModelException $e) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('LOGIN_FAILED')));
             return;
         }
         if ($user->password != md5(sha1($this->input->password) . $user->salt)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('LOGIN_FAILED')));
             return;
         }
         // We need to set _COOKIE values so that if the last_event requires
         // authentication, we can return the correct state.
         $expires = time() + 60 * 60 * 5;
         $this->_SetCookie('bugdar_user', $user->user_id, $expires);
         $this->_SetCookie('bugdar_pass', $user->authkey, $expires);
         $last_event = NULL;
         if ($this->input->last_event) {
             $last_event = unserialize(base64_decode($this->input->last_event));
             $class = $last_event[0];
             $input = $last_event[1];
             if (!class_exists($class)) {
                 $path = phalanx\base\CamelCaseToUnderscore($class);
                 $path = preg_replace('/_event$/', '', $path);
                 require_once BUGDAR_ROOT . "/events/{$path}.php";
             }
             $last_event = new $class($input);
         }
         $this->successful = TRUE;
         EventPump::Pump()->PostEvent($last_event ?: new StandardSuccessEvent('home', l10n::S('LOGIN_SUCCESSFUL')));
         return;
     }
     // Find the first non-UserLoginEvent that was processed. If the event
     // hasn't been finished, then this event preempted it and we should
     // store its data so that the user can return to what she was doing.
     $events = EventPump::Pump()->GetAllEvents();
     foreach ($events as $event) {
         if (!$event instanceof $this && $event->state() != EventPump::EVENT_FINISHED) {
             $this->last_event = base64_encode(serialize(array(get_class($event), $event->input)));
             break;
         }
     }
 }
Beispiel #11
0
 public function Fire()
 {
     $do_insert = $this->input->action == 'insert';
     $do_update = $this->input->action == 'update';
     if ($this->input->_method != 'POST') {
         EventPump::Pump()->RaiseEvent(new StandardErrorEvent('Request must be POSTed'));
         return;
     }
     // Create an empty Model object if creating a new bug, or fetch the data of
     // an existing bug to update.
     if ($do_insert) {
         $bug = new Bug();
     } else {
         if ($do_update) {
             $bug = new Bug($this->input->bug_id);
             try {
                 $bug->FetchInto();
             } catch (\phalanx\data\ModelException $e) {
                 EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND')));
                 return;
             }
         } else {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent('Invalid bug operation'));
             return;
         }
     }
     $this->action = $this->input->action;
     $user = Bugdar::$auth->current_user();
     $title = trim($this->input->title);
     if (empty($title) && $do_insert) {
         EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_MISSING_TITLE')));
         return;
     }
     Bugdar::$db->BeginTransaction();
     $now = time();
     if (!empty($title)) {
         $bug->title = $title;
     }
     if ($do_insert) {
         $bug->reporting_user_id = $user->user_id;
         $bug->reporting_date = $now;
         $bug->Insert();
     } else {
         if ($do_update) {
             $bug->Update();
         }
     }
     // Now set the bug_id output value, which will be set after a call to
     // Insert().  Updated bugs will have this set from FetchInto().
     $this->bug_id = $bug->bug_id;
     // Add a comment if one is present.
     $body = trim($this->input->comment_body);
     if (!empty($body) || $do_insert) {
         if ($do_insert && empty($body)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('COMMENT_MISSING_BODY')));
             return;
         }
         $comment = new Comment();
         $comment->bug_id = $this->bug_id;
         $comment->post_user_id = $user->user_id;
         $comment->post_date = $now;
         $comment->body = $body;
         $comment->Insert();
         $this->comment_id = $comment->comment_id;
         // Update the bug so it can find that first comment easiliy.
         if ($do_insert) {
             $bug = new Bug($bug->bug_id);
             $bug->first_comment_id = $comment->comment_id;
             $bug->Update();
             $bug->FetchInto();
         }
     }
     // Handle tags.
     if (is_array($this->input->tags_new)) {
         foreach ($this->input->tags_new as $tag) {
             $bug->SetAttribute('', $tag);
         }
     }
     if (is_array($this->input->tags_deleted)) {
         foreach ($this->input->tags_deleted as $tag) {
             $bug->RemoveAttribute($tag, TRUE);
         }
     }
     // Create a map of all the set attributes.
     $set_attributes = array();
     if (is_array($this->input->attributes)) {
         foreach ($this->input->attributes as $attr) {
             // If this is an empty attribute, ignore it.
             if (empty($attr['title']) || empty($attr['value'])) {
                 continue;
             }
             $set_attributes[$attr['title']] = $attr['value'];
         }
         // Get all potential attributes; this includes defined tags.
         $attributes = Attribute::FetchGroup();
         foreach ($attributes as $attr) {
             // If the user is allowed to write to this attribute, update the
             // value.
             if ($attr->is_attribute() && $attr->CheckAccess($user, $bug) & Attribute::ACCESS_WRITE) {
                 // If there is no value for this attribute, then it was removed.
                 if (!isset($set_attributes[$attr->title])) {
                     $bug->RemoveAttribute($attr->title, $attr->is_tag());
                     continue;
                 }
                 // Otherwise, update the value.
                 $validate = $attr->Validate($set_attributes[$attr->title]);
                 if ($validate[0]) {
                     $bug->SetAttribute($attr->title, $validate[1]);
                     unset($set_attributes[$attr->title]);
                 }
             }
         }
         // Any remaining set_attributes are not formally defined.  If the user
         // has permission to set ad-hoc attributes, do so.
         if (TRUE) {
             // TODO: check permission
             foreach ($set_attributes as $title => $value) {
                 $bug->SetAttribute($title, $value);
             }
         }
     }
     Bugdar::$db->Commit();
     $search = new SearchEngine();
     $search->IndexBug($bug);
     $string = $do_insert ? l10n::S('BUG_CREATED_SUCCESSFULLY') : l10n::S('BUG_EDIT_SUCCESS');
     EventPump::Pump()->PostEvent(new StandardSuccessEvent('view_bug/' . $this->bug_id, $string));
 }
Beispiel #12
0
 public function testNewBugMissingTitle()
 {
     $data = new phalanx\base\PropertyBag(array('_method' => 'POST', 'action' => 'insert', 'comment_body' => 'This is a Test Bug'));
     $event = new BugEditEvent($data);
     $time = time();
     EventPump::Pump()->PostEvent($event);
     $this->assertEquals(EventPump::EVENT_FIRE, $event->state());
     $this->assertType('StandardErrorEvent', EventPump::Pump()->GetEventChain()->Top());
 }
Beispiel #13
0
 public function Fire()
 {
     Bugdar::$auth->Logout();
     EventPump::Pump()->PostEvent(new StandardSuccessEvent('home', l10n::S('LOGOUT_SUCCESS')));
 }
Beispiel #14
0
 public function Fire()
 {
     EventPump::Pump()->PostEvent(new BugListEvent());
 }