Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
From d43c96787bd2f616d329cc7f99841b8bd11c7c24 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 31 May 2010 18:06:04 -0400 Subject: [PATCH] * Roll phalanx to 9a10099 to pick up CancelDeferredEvents(). * Add test for registering duplicate emails. --- events/standard_error.php | 2 +- events/user_register.php | 15 ++++++++++----- phalanx | 2 +- testing/standard_events.php | 4 +++- testing/tests/events/user_register_test.php | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/events/standard_error.php b/events/standard_error.php index 31b77bf..7cf1a7c 100644 --- a/events/standard_error.php +++ b/events/standard_error.php @@ -36,7 +36,7 @@ class StandardErrorEvent extends phalanx\events\Event public function Fire() { - // Do nothing. + phalanx\events\EventPump::Pump()->CancelDeferredEvents(); } public function Cleanup() diff --git a/events/user_register.php b/events/user_register.php index 0137a9a..a7ed9f0 100644 --- a/events/user_register.php +++ b/events/user_register.php @@ -48,18 +48,23 @@ class UserRegisterEvent extends phalanx\events\Event public function Fire() { - if ($this->input->do == 'submit') - { - if (!filter_var($this->input->email, FILTER_VALIDATE_EMAIL)) + 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) + 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) + 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); diff --git a/phalanx b/phalanx index e12964b..9a10099 160000 --- a/phalanx +++ b/phalanx @@ -1 +1 @@ -Subproject commit e12964bc7e5078fd23454c3c9d185b3815b5f35f +Subproject commit 9a1009908885c8f691e9d5fbe2685cc6b450b1f4 diff --git a/testing/standard_events.php b/testing/standard_events.php index 3e2754e..fb833c9 100644 --- a/testing/standard_events.php +++ b/testing/standard_events.php @@ -54,5 +54,7 @@ class StandardErrorEvent extends phalanx\events\Event } public function Fire() - {} + { + phalanx\events\EventPump::Pump()->CancelDeferredEvents(); + } } diff --git a/testing/tests/events/user_register_test.php b/testing/tests/events/user_register_test.php index d61b31e..7b3b8e2 100644 --- a/testing/tests/events/user_register_test.php +++ b/testing/tests/events/user_register_test.php @@ -53,4 +53,20 @@ class UserRegisterEventTest extends BugdarTestCase $this->assertEquals(md5(sha1($data->password) . $user->salt), $user->password); $this->assertGreaterThanOrEqual(5, strlen($user->authkey)); } + + public function testDuplicateEmail() + { + Bugdar::$auth = new AuthenticationTest(NULL); + $data = new phalanx\base\PropertyBag(array( + 'do' => 'submit', + 'email' => 'robert@bluestatic.org', + 'alias' => 'Robert', + 'password' => 'abc123' + )); + $event = new UserRegisterEvent($data); + EventPump::Pump()->PostEvent($event); + + $last_event = EventPump::Pump()->GetEventChain()->Top(); + $this->assertType('StandardErrorEvent', $last_event); + } } -- 1.7.11.3