Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added checks for open registration before displaying register link #1392

Closed
wants to merge 1 commit into from

2 participants

@brandonroberts

Only displays the register link if registration is enabled.

@ginatrapani

Looks like we're running the wrong controller here, we want to test the PasswordResetController

@ginatrapani

This function name should start with testOf

@ginatrapani
Owner

Thank you for the pull request, I've merged these changes in d02963a.

In addition to the test fixes mentioned in the comments, I made a few minor modifications:

  • I changed the name of the variable 'closed' to 'is_registration_open.' As per our style guide, when it comes to variable names we opt for clarity over brevity, and boolean vars generally start with is_ / has_ / or does_

  • I added assertions in the tests that make sure the word Register appears or doesn't appear in the resulting markup, in addition to asserting is_registration_closed was set.

  • I cleaned up some whitespace.

Thanks again for this work, and apologies for the delay on the code review. I was happy to see you added tests for your changes and referenced the issue in your branch name and commit message. Appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 6, 2012
  1. @brandonroberts

    Issue #1370: Added checks for open registration based on application …

    brandonroberts authored
    …options before displaying register link
This page is out of date. Refresh to see the latest.
View
26 tests/TestOfForgotPasswordController.php
@@ -139,4 +139,30 @@ public function testOfControllerWithValidEmailAddressAndSSL() {
https:\/\/mytestthinkup'.str_replace('/', '\/', $site_root_path).'session\/reset.php/';
$this->assertPattern($expected_forgot_email_pattern, $actual_forgot_email);
}
+
+ public function testOfControllerWithRegistrationOpen() {
+ // make sure registration is on...
+ $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open',
+ 'option_value' => 'true');
+ $bdata = FixtureBuilder::build('options', $bvalues);
+
+ $controller = new ForgotPasswordController(true);
+ $result = $controller->go();
+
+ $v_mgr = $controller->getViewManager();
+ $this->assertEqual($v_mgr->getTemplateDataItem('closed'), false);
+ }
+
+ public function testOfControllerWithRegistrationClosed() {
+ // make sure registration is closed
+ $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open',
+ 'option_value' => 'false');
+ $bdata = FixtureBuilder::build('options', $bvalues);
+
+ $controller = new ForgotPasswordController(true);
+ $result = $controller->go();
+
+ $v_mgr = $controller->getViewManager();
+ $this->assertEqual($v_mgr->getTemplateDataItem('closed'), true);
+ }
}
View
26 tests/TestOfLoginController.php
@@ -255,4 +255,30 @@ public function testFailedLoginLockout() {
$i = $i + 1;
}
}
+
+ public function testOfControllerWithRegistrationOpen() {
+ // make sure registration is on...
+ $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open',
+ 'option_value' => 'true');
+ $bdata = FixtureBuilder::build('options', $bvalues);
+
+ $controller = new LoginController(true);
+ $result = $controller->go();
+
+ $v_mgr = $controller->getViewManager();
+ $this->assertEqual($v_mgr->getTemplateDataItem('closed'), false);
+ }
+
+ public function testOfControllerWithRegistrationClosed() {
+ // make sure registration is closed
+ $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open',
+ 'option_value' => 'false');
+ $bdata = FixtureBuilder::build('options', $bvalues);
+
+ $controller = new LoginController(true);
+ $result = $controller->go();
+
+ $v_mgr = $controller->getViewManager();
+ $this->assertEqual($v_mgr->getTemplateDataItem('closed'), true);
+ }
}
View
26 tests/TestOfPasswordResetController.php
@@ -209,4 +209,30 @@ public function testOwnerHasCleanStateAfterSuccessfulPasswordReset() {
$this->assertEqual($owner->account_status, '');
$this->assertEqual($owner->failed_logins, 0);
}
+
+ public function testOfControllerWithRegistrationOpen() {
+ // make sure registration is on...
+ $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open',
+ 'option_value' => 'true');
+ $bdata = FixtureBuilder::build('options', $bvalues);
+
+ $controller = new PasswordResetController(true);
+ $result = $controller->go();
+
+ $v_mgr = $controller->getViewManager();
+ $this->assertEqual($v_mgr->getTemplateDataItem('closed'), false);
+ }
+
+ public function PasswordResetController() {
+ // make sure registration is closed
+ $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_registration_open',
+ 'option_value' => 'false');
+ $bdata = FixtureBuilder::build('options', $bvalues);
+
+ $controller = new LoginController(true);
+ $result = $controller->go();
+
+ $v_mgr = $controller->getViewManager();
+ $this->assertEqual($v_mgr->getTemplateDataItem('closed'), true);
+ }
}
View
7 webapp/_lib/controller/class.ForgotPasswordController.php
@@ -32,6 +32,12 @@
class ForgotPasswordController extends ThinkUpController {
public function control() {
+ $config = Config::getInstance();
+ $is_registration_open = $config->getValue('is_registration_open');
+ if (!$is_registration_open) {
+ $this->addToView('closed', true);
+ }
+
if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send Reset') {
$this->disableCaching();
@@ -43,7 +49,6 @@ public function control() {
$es = new ViewManager();
$es->caching=false;
- $config = Config::getInstance();
$es->assign('apptitle', $config->getValue('app_title_prefix')."ThinkUp" );
$es->assign('recovery_url', "session/reset.php?token=$token");
$es->assign('server', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost');
View
8 webapp/_lib/controller/class.LoginController.php
@@ -36,6 +36,14 @@ public function control() {
$this->setViewTemplate('session.login.tpl');
$this->view_mgr->addHelp('login', 'userguide/accounts/index');
$this->disableCaching();
+
+ $config = Config::getInstance();
+ $is_registration_open = $config->getValue('is_registration_open');
+
+ if (!$is_registration_open) {
+ $this->addToView('closed', true);
+ }
+
//don't show login form if already logged in
if ($this->isLoggedIn()) {
$controller = new DashboardController(true);
View
7 webapp/_lib/controller/class.PasswordResetController.php
@@ -37,6 +37,13 @@ public function control() {
$this->view_mgr->addHelp('reset', 'userguide/accounts/index');
$this->setViewTemplate('session.resetpassword.tpl');
$this->disableCaching();
+
+ $config = Config::getInstance();
+ $is_registration_open = $config->getValue('is_registration_open');
+
+ if (!$is_registration_open) {
+ $this->addToView('closed', true);
+ }
if (!isset($_GET['token']) || !preg_match('/^[\da-f]{32}$/', $_GET['token']) ||
(!$user = $owner_dao->getByPasswordToken($_GET['token']))) {
View
4 webapp/_lib/view/session.forgot.tpl
@@ -42,7 +42,9 @@
</form>
</div>
<div class="view-all">
- <a href="register.php">Register</a> |
+ {if !$closed}
+ <a href="register.php">Register</a> |
+ {/if}
<a href="login.php">Log In</a>
</div>
View
2  webapp/_lib/view/session.login.tpl
@@ -43,7 +43,9 @@
</form>
</div>
<div class="view-all">
+ {if !$closed}
<a href="register.php">Register</a> |
+ {/if}
<a href="forgot.php">Forgot password</a>
</div>
</div>
View
4 webapp/_lib/view/session.resetpassword.tpl
@@ -53,7 +53,9 @@
</form>
</div>
<div class="view-all">
- <a href="register.php">Register</a> |
+ {if !$closed}
+ <a href="register.php">Register</a> |
+ {/if}
<a href="login.php">Log In</a>
</div>
</div>
Something went wrong with that request. Please try again.