2017-08-28 14:30:30 +02:00
|
|
|
<?php
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
|
|
exit;
|
|
|
|
|
2017-10-24 10:27:38 +02:00
|
|
|
if (defined('PS_ADMIN_DIR'))
|
|
|
|
{
|
|
|
|
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
|
|
|
} else {
|
|
|
|
require_once(realpath(dirname(__FILE__) .'/../../').'/adm/helpers/HelperFormBootstrap.php');
|
|
|
|
}
|
2017-08-28 14:30:30 +02:00
|
|
|
|
|
|
|
class Ant_Resetbopassword extends Module
|
|
|
|
{
|
|
|
|
public $_html = '';
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->name = 'ant_resetbopassword';
|
|
|
|
$this->tab = 'administration';
|
|
|
|
$this->author = 'Antadis';
|
|
|
|
$this->version = '1.0';
|
|
|
|
$this->need_instance = 0;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->displayName = $this->l('Sécurité BO');
|
|
|
|
$this->description = $this->l('Envoi, tous les X mois, une demande de changement de mot de passe aux employés');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function install()
|
|
|
|
{
|
|
|
|
if(!(parent::install())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-21 15:37:41 +02:00
|
|
|
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'employee` ADD `date_passwd_upd` DATETIME DEFAULT "'.pSQL(date("Y-m-d H:i:s")).'"');
|
2017-08-28 14:30:30 +02:00
|
|
|
# Set default configuration values
|
|
|
|
Configuration::updateValue('ANT_RESETBOPASSWORD_FREQ', 3); // month
|
|
|
|
Configuration::updateValue('ANT_RESETBOPASSWORD_LIMIT', 7); // day
|
|
|
|
Configuration::updateValue('ANT_RESETBOPASSWORD_DATE', date('Y-m-d H:i:s')); // last date of updating
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstall()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(parent::uninstall() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Configuration::deleteByName('ANT_RESETBOPASSWORD_FREQ');
|
|
|
|
Configuration::deleteByName('ANT_RESETBOPASSWORD_LIMIT');
|
|
|
|
Configuration::deleteByName('ANT_RESETBOPASSWORD_DATE');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getContent()
|
|
|
|
{
|
|
|
|
global $cookie, $currentIndex;
|
|
|
|
|
|
|
|
if(Tools::isSubmit('submitUpdate')) {
|
|
|
|
Configuration::updateValue('ANT_RESETBOPASSWORD_FREQ', Tools::getValue('frequency'));
|
|
|
|
Configuration::updateValue('ANT_RESETBOPASSWORD_LIMIT', Tools::getValue('limit'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$helper = new HelperFormBootstrap();
|
|
|
|
$this->_html .= $helper->renderStyle();
|
|
|
|
$this->_html .= '
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<div class="panel">
|
|
|
|
<div class="panel-title">
|
|
|
|
<h2 style="font-size:24px;"><span class="anticon anticon-cog text-rose" style="font-size:24px;"></span> '.$this->l('Reset Bo Password - Configurations').'</h2>
|
|
|
|
<div class="clearfix"></div>
|
|
|
|
</div>
|
|
|
|
<div class="panel-content">
|
|
|
|
<form method="POST" action="">
|
|
|
|
<div class="col-sm-3 col-sm-offset-4">';
|
|
|
|
$input = array(
|
|
|
|
'type' => 'textAddon',
|
|
|
|
'label' => $this->l('Frequency :'),
|
|
|
|
'lang' => true,
|
|
|
|
'name' => 'frequency',
|
|
|
|
'id' => 'frequency',
|
|
|
|
'required' => true,
|
|
|
|
'after' => $this->l('Months'),
|
|
|
|
'help' => $this->l('Mail sending frequency'),
|
|
|
|
'default' => Configuration::get('ANT_RESETBOPASSWORD_FREQ')
|
|
|
|
);
|
|
|
|
$this->_html .= $helper->generateInput($input);
|
|
|
|
$this->_html .= '<div class="clearfix"></div>';
|
|
|
|
|
|
|
|
$input = array(
|
|
|
|
'type' => 'textAddon',
|
|
|
|
'label' => $this->l('Limit :'),
|
|
|
|
'lang' => true,
|
|
|
|
'name' => 'limit',
|
|
|
|
'id' => 'limit',
|
|
|
|
'required' => true,
|
|
|
|
'after' => $this->l('Days'),
|
|
|
|
'help' => $this->l('Nb of day limited to change the password'),
|
|
|
|
'default' => Configuration::get('ANT_RESETBOPASSWORD_LIMIT')
|
|
|
|
);
|
|
|
|
$this->_html .= $helper->generateInput($input);
|
|
|
|
$this->_html .= '<div class="clearfix"></div>';
|
|
|
|
|
|
|
|
$this->_html .='
|
|
|
|
</div>
|
|
|
|
<div class="clear"></div>
|
|
|
|
<div class="ln_solid-small"></div>
|
|
|
|
<div class="text-right">
|
|
|
|
<input type="submit" class="btn btn-primary" name="submitUpdate" value="'.$this->l('Save').'" />
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
$this->_html .= $helper->renderScript();
|
|
|
|
return $this->_html;
|
|
|
|
}
|
|
|
|
|
2017-09-18 11:00:12 +02:00
|
|
|
public function hookAnt_Initadmin($params)
|
2017-08-28 14:30:30 +02:00
|
|
|
{
|
2017-09-18 11:00:12 +02:00
|
|
|
$now = new Datetime("now");
|
|
|
|
$date_passwd_upd = new Datetime($params['employee']->date_passwd_upd);
|
|
|
|
$updated_date_send = new Datetime(Configuration::get('ANT_RESETBOPASSWORD_DATE'));
|
|
|
|
$limit = (int)Configuration::get('ANT_RESETBOPASSWORD_LIMIT');
|
|
|
|
$limit_day = $day_limit = $limit>1?$limit.' days':'1 day';
|
|
|
|
$date_send = $updated_date_send;
|
|
|
|
$date_send->modify("+".$limit_day."");
|
|
|
|
$now->modify("-".$limit_day."");
|
|
|
|
if($now > $date_send && $date_passwd_upd < $updated_date_send){
|
|
|
|
$destination = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'])) + 1);
|
|
|
|
Tools::redirectAdmin('resetpasswd.php'.(empty($destination) || ($destination == 'index.php?logout') ? '' : '?redirect='.$destination));
|
|
|
|
}
|
|
|
|
return true;
|
2017-08-28 14:30:30 +02:00
|
|
|
}
|
|
|
|
}
|