From a703877122e8c89e2888973be66afcc193b40629 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 13 Jun 2013 13:38:32 +0200 Subject: [PATCH 1/2] Adding support do disable account registration * Adding new configuration variable, see `global.inc.dist.php` * If you are not able to register anymore check the config var is * set Requested in and fixes #150 --- public/include/config/global.inc.dist.php | 1 + public/include/pages/register.inc.php | 12 ++++++++---- public/include/pages/register/register.inc.php | 9 ++++----- public/templates/mmcFE/register/disabled.tpl | 3 +++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 public/templates/mmcFE/register/disabled.tpl diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index e8d12774..4347a513 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -30,6 +30,7 @@ $config = array( 'max' => 250 ), 'website' => array( + 'registration' => true, // Allow new users to register 'name' => 'The Pool', 'slogan' => 'Resistance is futile', 'email' => 'test@example.com', // Mail address used for notifications diff --git a/public/include/pages/register.inc.php b/public/include/pages/register.inc.php index aecab054..f1c4cb73 100644 --- a/public/include/pages/register.inc.php +++ b/public/include/pages/register.inc.php @@ -1,9 +1,13 @@ assign("CONTENT", "default.tpl"); +if (!$config['website']['registration']) { + $_SESSION['POPUP'][] = array('CONTENT' => 'Account registration is currently disabled. Please try again later.', 'TYPE' => 'errormsg'); + $smarty->assign("CONTENT", "disabled.tpl"); +} else { + // Tempalte specifics + $smarty->assign("CONTENT", "default.tpl"); +} ?> diff --git a/public/include/pages/register/register.inc.php b/public/include/pages/register/register.inc.php index 53e941bf..2e4e4885 100644 --- a/public/include/pages/register/register.inc.php +++ b/public/include/pages/register/register.inc.php @@ -1,11 +1,10 @@ register($_POST['username'], $_POST['password1'], $_POST['password2'], $_POST['pin'], $_POST['email1'], $_POST['email2'])) { +if (!$config['website']['registration']) { + $_SESSION['POPUP'][] = array('CONTENT' => 'Account registration is currently disabled. Please try again later.', 'TYPE' => 'errormsg'); +} else if ($user->register($_POST['username'], $_POST['password1'], $_POST['password2'], $_POST['pin'], $_POST['email1'], $_POST['email2']) && $config['website']['registration']) { $_SESSION['POPUP'][] = array('CONTENT' => 'Account created, please login'); } else { $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to create account: ' . $user->getError(), 'TYPE' => 'errormsg'); diff --git a/public/templates/mmcFE/register/disabled.tpl b/public/templates/mmcFE/register/disabled.tpl new file mode 100644 index 00000000..5e5ac8ee --- /dev/null +++ b/public/templates/mmcFE/register/disabled.tpl @@ -0,0 +1,3 @@ +{include file="global/block_header.tpl" BLOCK_HEADER="Registration disabled" BLOCK_STYLE="clear:none;"} +

We are currently not accepting new user registrations.

+{include file="global/block_footer.tpl"} From 6a5f9388954673d8130a8a3de317639e042017f4 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 13 Jun 2013 13:46:32 +0200 Subject: [PATCH 2/2] Store Users IP address in accounts after login Fixes #177 --- public/include/classes/user.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php index cc8d7c70..9e69b01d 100644 --- a/public/include/classes/user.class.php +++ b/public/include/classes/user.class.php @@ -69,7 +69,6 @@ class User { ); return $this->updateSingle($id, $field); } - public function setUserToken($id) { $field = array( 'name' => 'token', @@ -78,6 +77,10 @@ class User { ); return $this->updateSingle($id, $field); } + private function setUserIp($id, $ip) { + $field = array( 'name' => 'loggedIp', 'type' => 's', 'value' => $ip ); + return $this->updateSingle($id, $field); + } /** * Fetch all users for administrative tasks @@ -106,6 +109,7 @@ class User { } if ( $this->checkUserPassword($username, $password)) { $this->createSession($username); + $this->setUserIp($this->getUserId($username), $_SERVER['REMOTE_ADDR']); return true; } $this->setErrorMessage("Invalid username or password");