Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration refactoring #1469

Merged
merged 16 commits into from Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Config/Menu/noUserMainMenu.default.php
@@ -1,4 +1,6 @@
<?php
use Utils\Uri\SimpleRouter;

/**
* This is simple configuration of links presented in sidebar of the page
* for non-authorized users only.
Expand All @@ -24,7 +26,7 @@
$menu = [ // DON'T CHANGE $menu var name!

/* 'translation key' => 'url' */
'mnu_registration' => '/register.php',
'mnu_registration' => SimpleRouter::getLink('UserRegistration'),
'mnu_news' => '/news.php',
'mnu_rules' => [$links['wiki']['rules']],
'mnu_newCaches' => '/newcaches.php',
Expand Down
102 changes: 79 additions & 23 deletions Controllers/Admin/UserAdminController.php
Expand Up @@ -2,20 +2,22 @@
namespace Controllers\Admin;

use Controllers\BaseController;
use Utils\Uri\Uri;
use lib\Objects\User\User;
use lib\Objects\User\AdminNote;
use Utils\Text\UserInputFilter;
use Utils\Uri\SimpleRouter;
use Utils\Uri\Uri;
use lib\Controllers\Php7Handler;
use lib\Objects\User\AdminNote;
use lib\Objects\User\User;
use lib\Objects\User\UserAdmin;
use lib\Objects\User\UserAuthorization;
use Utils\Uri\SimpleRouter;
use lib\Objects\User\UserEmailSender;
use lib\Objects\User\UserNotify;

class UserAdminController extends BaseController
{

private $infoMsg = null;

private $errorMsg = null;

/**
Expand Down Expand Up @@ -66,6 +68,12 @@ public function addNote($userId = null)
$this->index($userId);
}

/**
* (un)bans user $userId (depends of $state)
*
* @param int $userId
* @param boolean $state
*/
public function userBan($userId = null, $state = null)
{
$this->checkSecurityAndPrepare($userId);
Expand All @@ -76,15 +84,21 @@ public function userBan($userId = null, $state = null)

if ($state) { // ban
UserAuthorization::removeUserSessions($this->viewedUser);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::BAN);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::BAN);
} else { // unban
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::UNBAN);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::UNBAN);
}
}
unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin','index', $userId));
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

/**
* (un)bans stats for user $userId (depends of $state)
*
* @param int $userId
* @param boolean $state
*/
public function statBan($userId = null, $state = null)
{
$this->checkSecurityAndPrepare($userId);
Expand All @@ -94,15 +108,21 @@ public function statBan($userId = null, $state = null)
UserAdmin::setStatBanStatus($this->viewedUser, $state);

if ($state) { // ban stats
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::BAN_STATS);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::BAN_STATS);
} else { // unban stats
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::UNBAN_STATS);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::UNBAN_STATS);
}
}
unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin','index', $userId));
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

/**
* Sets VerifyAll flag for $userId to $state
*
* @param int $userId
* @param boolean $state
*/
public function verifyAll($userId = null, $state = null)
{
$this->checkSecurityAndPrepare($userId);
Expand All @@ -112,15 +132,21 @@ public function verifyAll($userId = null, $state = null)
UserAdmin::setVerifyAllStatus($this->viewedUser, $state);

if ($state) { // verify all
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::VERIFY_ALL);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::VERIFY_ALL);
} else { // remove verify all
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::NO_VERIFY_ALL);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::NO_VERIFY_ALL);
}
}
unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin','index', $userId));
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

/**
* Sets Ignore_founds flag for $userId to $state
*
* @param int $userId
* @param boolean $state
*/
public function createNoLimit($userId = null, $state = null)
{
$this->checkSecurityAndPrepare($userId);
Expand All @@ -130,15 +156,21 @@ public function createNoLimit($userId = null, $state = null)
UserAdmin::setCreateWithoutLimitStatus($this->viewedUser, $state);

if ($state) { // user can create
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::IGNORE_FOUND_LIMIT);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::IGNORE_FOUND_LIMIT);
} else { // user cannot create
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::IGNORE_FOUND_LIMIT_RM);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::IGNORE_FOUND_LIMIT_RM);
}
}
unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin','index', $userId));
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

/**
* Changes new caches notify state for $userId
*
* @param int $userId
* @param boolean $state
*/
public function notifyCaches($userId = null, $state = null)
{
$this->checkSecurityAndPrepare($userId);
Expand All @@ -148,15 +180,21 @@ public function notifyCaches($userId = null, $state = null)
UserNotify::setUserCachesNotify($this->viewedUser, $state);

if ($state) { // turn on caches notify
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::NOTIFY_CACHES_ON);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::NOTIFY_CACHES_ON);
} else { // turn off caches notify
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::NOTIFY_CACHES_OFF);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::NOTIFY_CACHES_OFF);
}
}
unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin','index', $userId));
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

/**
* Changes new logs notify state for $userId
*
* @param int $userId
* @param boolean $state
*/
public function notifyLogs($userId = null, $state = null)
{
$this->checkSecurityAndPrepare($userId);
Expand All @@ -166,13 +204,32 @@ public function notifyLogs($userId = null, $state = null)
UserNotify::setUserLogsNotify($this->viewedUser, $state);

if ($state) { // turn on logs notify
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::NOTIFY_LOGS_ON);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::NOTIFY_LOGS_ON);
} else { // turn off logs notify
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), TRUE, AdminNote::NOTIFY_LOGS_OFF);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::NOTIFY_LOGS_OFF);
}
}
unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin','index', $userId));
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

/**
* Activate user
*
* @param int $userId
*/
public function activateUser($userId = null)
{
$this->checkSecurityAndPrepare($userId);

if (! $this->viewedUser->isUserActivated()) {
User::activateUser($this->viewedUser->getUserId());
UserEmailSender::sendPostActivationMessage($this->viewedUser);
AdminNote::addAdminNote($this->loggedUser->getUserId(), $this->viewedUser->getUserId(), true, AdminNote::ACTIVATE);
}

unset($this->viewedUser);
$this->view->redirect(SimpleRouter::getLink('Admin.UserAdmin', 'index', $userId));
}

private function checkSecurityAndPrepare($userId)
Expand All @@ -183,5 +240,4 @@ private function checkSecurityAndPrepare($userId)
$this->view->redirect('/');
}
}

}
25 changes: 25 additions & 0 deletions Controllers/TestController.php
Expand Up @@ -320,5 +320,30 @@ public function cookieTest()
d(headers_list());

}

public function registration()
{
if($this->isUserLogged()){
return $this->alreadyRegistered();
}

$this->view->loadJQuery();
$this->view->setTemplate('test/userRegistration');
// local css
$this->view->addLocalCss( Uri::getLinkWithModificationTime(
'/tpl/stdstyle/test/userRegistration.css'));


$this->view->buildView();
}


private function alreadyRegistered()
{
$this->view->setTemplate('test/alreadyRegistered');


$this->view->buildView();
}
}