improved maintenance feature

This commit is contained in:
lakshya chauhan
2022-04-04 21:01:13 +05:30
parent d15654c820
commit 617f04c975
6 changed files with 336 additions and 86 deletions

View File

@@ -214,7 +214,46 @@ class FrontControllerCore extends Controller
self::$initialized = true;
parent::init();
$this->context->smarty->assign([
'css_dir' => _THEME_CSS_DIR_,
'img_ps_dir' => _PS_IMG_,
'tpl_dir' => _PS_THEME_DIR_,
'js_dir' => _THEME_JS_DIR_,
'base_dir' => __PS_BASE_URI__,
'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code,
]);
/* get page name to display it in body id */
// Are we in a payment module
$module_name = '';
if (Validate::isModuleName(Tools::getValue('module'))) {
$module_name = Tools::getValue('module');
}
if (!empty($this->page_name)) {
$page_name = $this->page_name;
} elseif (!empty($this->php_self)) {
$page_name = $this->php_self;
} elseif (Tools::getValue('fc') == 'module' && $module_name != '' && (Module::getInstanceByName($module_name) instanceof PaymentModule)) {
$page_name = 'module-payment-submit';
}
// @retrocompatibility Are we in a module ?
elseif (preg_match('#^'.preg_quote($this->context->shop->physical_uri, '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
$page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
} else {
$page_name = Dispatcher::getInstance()->getController();
$page_name = (preg_match('/^[0-9]/', $page_name) ? 'page_'.$page_name : $page_name);
}
$this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
// Init cookie language
// @TODO This method must be moved into switchLanguage
Tools::setCookieLanguage($this->context->cookie);
$this->displayMaintenancePage();
// If current URL use SSL, set it true (used a lot for module redirect)
if (Tools::usingSecureMode()) {
$useSSL = true;
@@ -236,13 +275,8 @@ class FrontControllerCore extends Controller
$this->context->smarty->assign('account_created', 1);
unset($this->context->cookie->account_created);
}
ob_start();
// Init cookie language
// @TODO This method must be moved into switchLanguage
Tools::setCookieLanguage($this->context->cookie);
$protocol_link = (Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode()) ? 'https://' : 'http://';
$useSSL = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
$protocol_content = ($useSSL) ? 'https://' : 'http://';
@@ -370,32 +404,6 @@ class FrontControllerCore extends Controller
$this->context->cart = $cart;
}
/* get page name to display it in body id */
// Are we in a payment module
$module_name = '';
if (Validate::isModuleName(Tools::getValue('module'))) {
$module_name = Tools::getValue('module');
}
if (!empty($this->page_name)) {
$page_name = $this->page_name;
} elseif (!empty($this->php_self)) {
$page_name = $this->php_self;
} elseif (Tools::getValue('fc') == 'module' && $module_name != '' && (Module::getInstanceByName($module_name) instanceof PaymentModule)) {
$page_name = 'module-payment-submit';
}
// @retrocompatibility Are we in a module ?
elseif (preg_match('#^'.preg_quote($this->context->shop->physical_uri, '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) {
$page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
} else {
$page_name = Dispatcher::getInstance()->getController();
$page_name = (preg_match('/^[0-9]/', $page_name) ? 'page_'.$page_name : $page_name);
}
$this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, $page_name));
$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
/* Breadcrumb */
$navigation_pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
$this->context->smarty->assign('navigationPipe', $navigation_pipe);
@@ -404,7 +412,6 @@ class FrontControllerCore extends Controller
if (!empty($this->php_self) && !Tools::getValue('ajax')) {
$this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
}
Product::initPricesComputation();
$display_tax_label = $this->context->country->display_tax_label;
@@ -444,13 +451,11 @@ class FrontControllerCore extends Controller
'force_ssl' => Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'),
'content_dir' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__,
'base_uri' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__.(!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''),
'tpl_dir' => _PS_THEME_DIR_,
'tpl_uri' => _THEME_DIR_,
'modules_dir' => _MODULE_DIR_,
'mail_dir' => _MAIL_DIR_,
'lang_iso' => $this->context->language->iso_code,
'lang_id' => (int)$this->context->language->id,
'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code,
'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))),
'cart_qties' => (int)$cart->nbProducts(),
'currencies' => Currency::getCurrencies(),
@@ -495,7 +500,6 @@ class FrontControllerCore extends Controller
));
$assign_array = array(
'img_ps_dir' => _PS_IMG_,
'img_cat_dir' => _THEME_CAT_DIR_,
'img_lang_dir' => _THEME_LANG_DIR_,
'img_prod_dir' => _THEME_PROD_DIR_,
@@ -505,8 +509,6 @@ class FrontControllerCore extends Controller
'img_store_dir' => _THEME_STORE_DIR_,
'img_col_dir' => _THEME_COL_DIR_,
'img_dir' => _THEME_IMG_DIR_,
'css_dir' => _THEME_CSS_DIR_,
'js_dir' => _THEME_JS_DIR_,
'pic_dir' => _THEME_PROD_PIC_DIR_
);
@@ -539,14 +541,12 @@ class FrontControllerCore extends Controller
self::$link = $link;
$defaultCountry = $this->context->country;
$this->displayMaintenancePage();
if ($this->restrictedCountry) {
$this->displayRestrictedCountryPage();
}
if (Tools::isSubmit('live_edit') && !$this->checkLiveEditAccess()) {
Tools::redirect('index.php?controller=404');
Tools::redirect('index.php');
}
$this->iso = $iso;
@@ -750,22 +750,92 @@ class FrontControllerCore extends Controller
*/
protected function displayMaintenancePage()
{
if ($this->maintenance == true || !(int)Configuration::get('PS_SHOP_ENABLE')) {
$this->maintenance = true;
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) {
header('HTTP/1.1 503 temporarily overloaded');
$this->context->smarty->assign($this->initLogoAndFavicon());
$this->context->smarty->assign(array(
'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()),
));
// If the controller is a module, then getTemplatePath will try to find the template in the modules, so we need to instanciate a real frontcontroller
$front_controller = preg_match('/ModuleFrontController$/', get_class($this)) ? new FrontController() : $this;
$this->smartyOutputContent($front_controller->getTemplatePath($this->getThemeDir().'maintenance.tpl'));
exit;
if (isset(Context::getContext()->cookie->remote_addr)
&& Context::getContext()->cookie->remote_addr != ip2long(Tools::getRemoteAddr())
) {
$cookie = Context::getContext()->cookie;
if (isset($cookie->remote_addr)) {
$cookie->enable_maintenance_view = false;
$cookie->remote_addr = false;
$cookie->write();
}
}
if (Tools::isSubmit('SubmitLogin')
&& Configuration::get('PS_ALLOW_EMP')
&& !Context::getContext()->cookie->enable_maintenance_view
) {
$email = trim(Tools::getValue('email'));
$passwd = trim(Tools::getValue('passwd'));
$this->processLogin($email, $passwd);
}
if (!Context::getContext()->cookie->enable_maintenance_view || !Configuration::get('PS_ALLOW_EMP')) {
Context::getContext()->cookie->__unset('enable_maintenance_view');
Context::getContext()->cookie->write();
if ($this->maintenance == true || !(int)Configuration::get('PS_SHOP_ENABLE')) {
$this->maintenance = true;
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) {
header('HTTP/1.1 503 temporarily overloaded');
$this->context->smarty->assign($this->initLogoAndFavicon());
$this->context->smarty->assign(array(
'HOOK_MAINTENANCE' => Hook::exec('displayMaintenance', array()),
'allowEmployee' => Configuration::get('PS_ALLOW_EMP'),
'maintenance' => $this->context->link->getAdminLink('AdminMaintenance', false),
));
// If the controller is a module, then getTemplatePath will try to find the template in the modules, so we need to instanciate a real frontcontroller
$front_controller = preg_match('/ModuleFrontController$/', get_class($this)) ? new FrontController() : $this;
$this->smartyOutputContent($front_controller->getTemplatePath($this->getThemeDir().'maintenance.tpl'));
exit;
}
}
}
}
protected function processLogin($email, $passwd)
{
$result = false;
/* Check fields validity */
if (empty($email)) {
$this->errors[] = Tools::displayError('Email is empty.');
} elseif (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('Invalid email address.');
}
if (empty($passwd)) {
$this->errors[] = Tools::displayError('The password field is blank.');
} elseif (!Validate::isPasswd($passwd)) {
$this->errors[] = Tools::displayError('Invalid password.');
}
if (!count($this->errors)) {
// Find employee
$this->context->employee = new Employee();
$is_employee_loaded = $this->context->employee->getByEmail($email, $passwd);
$employee_associated_shop = $this->context->employee->getAssociatedShops();
if (!$is_employee_loaded) {
$this->errors[] = Tools::displayError('The Employee does not exist, or the password provided is incorrect.');
$this->context->employee->logout();
} elseif (empty($employee_associated_shop) && !$this->context->employee->isSuperAdmin()) {
$this->errors[] = Tools::displayError('This employee does not manage the shop anymore (Either the shop has been deleted or permissions have been revoked).');
$this->context->employee->logout();
} else {
// Update cookie
$cookie = Context::getContext()->cookie;
$cookie->enable_maintenance_view = $this->context->employee->id;
$cookie->remote_addr = ip2long(Tools::getRemoteAddr());
$cookie->write();
}
if (count($this->errors)) {
$this->context->smarty->assign('errors', $this->errors);
} else {
Tools::redirect('index.php');
}
} else {
$this->context->smarty->assign('errors', $this->errors);
}
return $result;
}
/**

View File

@@ -48,6 +48,14 @@ class AdminMaintenanceControllerCore extends AdminController
'cast' => 'intval',
'type' => 'bool'
),
'PS_ALLOW_EMP' => array(
'title' => $this->l('Allow Employees'),
'desc' => $this->l('Allow the employees to access the site using email and password.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'class' => "hello"
),
'PS_MAINTENANCE_IP' => array(
'title' => $this->l('Maintenance IP'),
'hint' => $this->l('IP addresses allowed to access the front office even if the shop is disabled. Please use a comma to separate them (e.g. 42.24.4.2,127.0.0.1,99.98.97.96)'),
@@ -60,4 +68,10 @@ class AdminMaintenanceControllerCore extends AdminController
),
);
}
public function setMedia()
{
parent::setMedia();
$this->addJS(_PS_JS_DIR_.'maintenance.js');
}
}

BIN
img/maintenance_banner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

21
js/maintenance.js Normal file
View File

@@ -0,0 +1,21 @@
$(document).ready(function(){
if ($("#PS_SHOP_ENABLE_on").is(':checked')) {
$('#conf_id_PS_ALLOW_EMP').hide();
}
if ($("#PS_SHOP_ENABLE_off").is(':checked')) {
$("#conf_id_PS_ALLOW_EMP").show();
}
$(".clicker.blue").on('click', function(){
$('.hiddendiv').show('slow');
});
$("#cancelLogin").on('click', function(){
$('.hiddendiv').hide('slow');
});
$("input[type='radio'][name='PS_SHOP_ENABLE']").change(function() {
$("#conf_id_PS_ALLOW_EMP").toggle('slow');
});
});

View File

@@ -4,18 +4,119 @@
#body {
background-color: #F7F7F7; }
#maintenance {
margin: 50px 0 0 0;
background-color: #fff;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
@media (min-width: 1200px) {
#maintenance {
margin: 126px 0 0 0;
padding: 50px; } }
h1 {
font-size: 50px;
}
p {
font-size: 16px;
color: #666;
}
.blue {
color: #1A7EFF;
text-decoration: none;
}
.containter {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
column-gap: 60px;
}
.left {
text-align: right;
}
.clicker {
outline: none;
cursor: pointer;
}
.hiddendiv {
display: none;
width: 300px;
}
.text-center {
text-align: center;
}
input[type='text'],
input[type='email'],
input[type='password'] {
border: 1px solid #c9c9c9;
width: 90%;
padding: 10px 14px;
font-size: 14px;
margin-bottom: 14px;
border-radius: 4px;
}
button[type='submit'] {
border: 1px solid #1A7EFF;
background-color: #1A7EFF;
padding: 10px 20px;
font-size: 14px;
margin-bottom: 14px;
color: white;
border-radius: 4px;
cursor: pointer;
}
button[type='button'].cancel-login {
border: 1px solid #c5c5c5;
background-color: #fff;
padding: 10px 20px;
font-size: 14px;
margin-bottom: 14px;
color: #333;
border-radius: 4px;
cursor: pointer;
}
@media screen and (max-width: 780px) {
.containter {
flex-direction:column;
}
}
.alert {
padding: 5px;
margin-bottom: 10px;
border: 1px solid transparent;
border-radius: 0px;
font-weight: bold;
}
.alert.alert-danger p {
color: #FFF;
}
.alert.alert-danger li {
font-size: 14px;
}
.alert-danger {
background-color: #FD6E6A;
border-color: #FD6E6A;
color: #fff;
}
.alert.alert-danger {
text-shadow: 1px 1px rgb(0 0 0 / 10%);
}
.alert-danger .alert-link {
font-weight: bold;
font-size: 16px;
color: #FFF;
}
#maintenance .logo {
margin: 0 0 31px 0;
padding: 12px;
text-align: center; }
#maintenance h1 {
font: 24px "Open Sans", sans-serif;

View File

@@ -28,30 +28,74 @@
<head>
<meta charset="utf-8">
<title>{$meta_title|escape:'html':'UTF-8'}</title>
{if isset($meta_description)}
<meta name="description" content="{$meta_description|escape:'html':'UTF-8'}">
{/if}
{if isset($meta_keywords)}
<meta name="keywords" content="{$meta_keywords|escape:'html':'UTF-8'}">
{/if}
{if isset($meta_description)}
<meta name="description" content="{$meta_description|escape:'html':'UTF-8'}">
{/if}
{if isset($meta_keywords)}
<meta name="keywords" content="{$meta_keywords|escape:'html':'UTF-8'}">
{/if}
<meta name="robots" content="{if isset($nobots)}no{/if}index,follow">
<link rel="shortcut icon" href="{$favicon_url}">
<link href="{$css_dir}maintenance.css" rel="stylesheet">
<link href='//fonts.googleapis.com/css?family=Open+Sans:600' rel='stylesheet'>
<link href="{$css_dir}maintenance.css" rel="stylesheet">
<script src="{$base_dir}js/jquery/jquery-1.11.0.min.js"></script>
<script src="{$base_dir}js/maintenance.js"></script>
<link href='//fonts.googleapis.com/css?family=Open+Sans:600' rel='stylesheet'>
</head>
<body>
<div class="container">
<div id="maintenance">
<div class="logo"><img src="{$logo_url}" {if $logo_image_width}width="{$logo_image_width}"{/if} {if $logo_image_height}height="{$logo_image_height}"{/if} alt="logo" /></div>
{$HOOK_MAINTENANCE}
<div id="message">
<h1 class="maintenance-heading">{l s='We\'ll be back soon.'}</h1>
{l s='We are currently updating our site and will be back really soon.'}
<br />
{l s='Thanks for your patience.'}
</div>
</div>
</div>
<div id="maintenance">
<div class="logo">
<img src="{$logo_url}" {if $logo_image_width}width="{$logo_image_width}" {/if} {if $logo_image_height}height="{$logo_image_height}" {/if} alt="logo" />
</div>
<div class="margin-l-r">
{include file="$tpl_dir./errors.tpl"}
</div>
<div class="containter">
<div class="left">
<div class="">
<img class="" src="{$img_ps_dir}maintenance_banner.png"></img>
</div>
</div>
<div class="right">
<h2>{l s='We\'ll be back soon.'}</h2>
<p>{l s='We are currently updating our site and will be back really soon.'}</p>
<p>{l s='Thanks for your patience!'}</p>
{if isset($allowEmployee) && $allowEmployee}
<div>
<p class="clicker blue" tabindex="1">Are you member?</p>
<div class="hiddendiv">
<div class="allow-conatainer">
<form action="index.php" method="post">
<div class="form_content clearfix">
<div class="form-group form-ok">
<label class="" for="email">Email address</label>
<br>
<input class="form-control" placeholder="Email" type="email" id="email"
name="email" value="">
</div>
<div class="form-group form-ok">
<label class="" for="passwd">Password</label>
<br>
<input class="form-control" type="password" placeholder="Password" id="passwd"
name="passwd" value="">
</div>
<button type="submit" id="SubmitLogin" name="SubmitLogin" class="btn btn-primary">
<span>
Log in
</span>
</button>
<button type="button" id="cancelLogin" name="cancelLogin" class="btn btn-primary cancel-login">
<span>
Cancel
</span>
</button>
</div>
</form>
</div>
</div>
</div>
{/if}
</div>
</div>
</div>
</body>
</html>
</html>