[+] BO : login and lost password is now in ajax and convert in AdminController

This commit is contained in:
vAugagneur
2011-11-23 21:32:11 +00:00
parent 87616cdafc
commit cb1d4ba6b8
11 changed files with 765 additions and 263 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
if (!Context::getContext()->employee->isLoggedBack())
Tools::redirectAdmin('login.php');
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminLogin'));
$tabAccess = Profile::getProfileAccess(Context::getContext()->employee->id_profile, Tab::getIdFromClassName('AdminBackup'));
+1 -1
View File
@@ -37,7 +37,7 @@ if (isset($_GET['logout']))
$context->employee->logout();
if (!isset($context->employee) || !$context->employee->isLoggedBack())
Tools::redirectAdmin('login.php?redirect='.$_SERVER['REQUEST_URI']);
Tools::redirectAdmin('index.php?controller=AdminLogin&redirect='.$_SERVER['REQUEST_URI']);
// Set current index
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller: '');
+1 -158
View File
@@ -24,162 +24,5 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
ob_start();
define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
include(_PS_ADMIN_DIR_.'/functions.php');
$clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'),explode(',', Configuration::get('PS_MAINTENANCE_IP'))));
$errors = array();
if ((empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off')
AND Configuration::get('PS_SSL_ENABLED'))
{
// You can uncomment theses lines if you want to force https even from localhost and automatically redirect
// header('HTTP/1.1 301 Moved Permanently');
// header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
// exit();
// If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP
if ($clientIsMaintenanceOrLocal)
$errors[] = translate('SSL is activated. However, your IP is allowed to use unsecure mode (Maintenance or local IP).').'<br/>';
else
$warningSslMessage = translate('SSL is activated. Please connect using the following url to log in in secure mode (https).')
.'<br/><br/><a href="https://'.Tools::getServerName().Tools::safeOutput($_SERVER['REQUEST_URI']).'">https://'.Tools::getServerName().Tools::safeOutput($_SERVER['REQUEST_URI']).'</a>';
}
$iso = strtolower(Context::getContext()->language->iso_code);
include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php');
include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
/* Cookie creation and redirection */
if (Tools::isSubmit('Submit'))
{
/* Check fields validity */
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
if (empty($email))
$errors[] = Tools::displayError('E-mail is empty');
elseif (!Validate::isEmail($email))
$errors[] = Tools::displayError('Invalid e-mail address');
elseif (empty($passwd))
$errors[] = Tools::displayError('Password is blank');
elseif (!Validate::isPasswd($passwd))
$errors[] = Tools::displayError('Invalid password');
else
{
/* Seeking for employee */
$employee = new Employee();
if (!$employee->getByemail($email, $passwd))
{
$errors[] = Tools::displayError('Employee does not exist or password is incorrect.');
$employee->logout();
}
else
{
$employee->remote_addr = ip2long(Tools::getRemoteAddr());
/* Creating cookie */
$cookie = Context::getContext()->cookie;
$cookie->id_employee = $employee->id;
$cookie->email = $employee->email;
$cookie->profile = $employee->id_profile;
$cookie->passwd = $employee->passwd;
$cookie->remote_addr = $employee->remote_addr;
$cookie->write();
/* Redirect to admin panel */
if (isset($_GET['redirect']))
$url = strval($_GET['redirect'].(isset($_GET['token']) ? ('&token='.$_GET['token']) : ''));
else
$url = 'index.php';
if (!Validate::isCleanHtml($url))
die(Tools::displayError());
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$iso.'" lang="'.$iso.'">
<meta http-equiv="Refresh" content="0;URL='.str_replace('&amp;', '&', Tools::safeOutput($url, true)).'">
<head>
<script language="javascript" type="text/javascript">
window.location.replace("'.str_replace('&amp;', '&', Tools::safeOutput($url, true)).'");
</script>
<div style="text-align:center; margin-top:250px;"><a href="'.str_replace('&amp;', '&', Tools::safeOutput($url, true)).'">'.translate('Click here to launch Administration panel').'</a></div>
</head>
</html>';
exit ;
}
}
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$iso.'" lang="'.$iso.'">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="../css/login.css" />
<title>PrestaShop&trade; - '.translate('Administration panel').'</title>';
echo '
</head>
<body>
<div id="container">';
if ($nbErrors = sizeof($errors))
{
echo '
<div id="error">
<h3>'.($nbErrors > 1 ? translate('There are') : translate('There is')).' '.$nbErrors.' '.($nbErrors > 1 ? translate('errors') : translate('error')).'</h3>
<ol style="margin: 0 0 0 20px;">';
foreach ($errors AS $error)
echo '<li>'.$error.'</li>';
echo '
</ol>
</div>
<br />';
}
echo '
<div id="login">
<h1>'.Tools::htmlentitiesUTF8(Configuration::get('PS_SHOP_NAME')).'</h1>
<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">';
$randomNb = rand(100, 999);
if(file_exists(_PS_ADMIN_DIR_.'/../install') OR file_exists(_PS_ADMIN_DIR_.'/../admin'))
{
echo ' <span>'.translate('For security reasons, you cannot connect to the Back Office until after you have:').'<br /><br />
- '.translate('delete the /install folder').'<br />
- '.translate('renamed the /admin folder (eg. ').'/admin'.$randomNb.')<br />
<br />'.translate('Please then access this page by the new url (eg. http://www.domain.tld/admin').$randomNb.')</span>';
}
else
{
// If https enabled, we force it except if you try to log in from maintenance or local ip
if ( (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off')
AND ( Configuration::get('PS_SSL_ENABLED') AND !$clientIsMaintenanceOrLocal)
)
echo '<div class="error">'.$warningSslMessage.'</div>';
else
echo '<label for="email">'.translate('E-mail address:').'</label><br />
<input type="text" id="email" name="email" value="'.Tools::safeOutput(Tools::getValue('email')).'" class="input"/>
<div style="margin: 1.8em 0 0 0;">
<label for="passwd">'.translate('Password:').'</label><br />
<input id="passwd" type="password" name="passwd" class="input" value=""/>
</div>
<div>
<div id="submit"><input type="submit" name="Submit" value="'.translate('Log in').'" class="button" /></div>
<div id="lost"><a href="password.php">'.translate('Lost password?').'</a></div>
</div>
';
}
?>
<script type="text/javascript">
//<![CDATA[
if (document.getElementById('email')) document.getElementById('email').focus();
//]]>
</script>
<?php
echo '
</form>
</div>
<h2><a href="http://www.prestashop.com">&copy; Copyright by PrestaShop. all rights reserved.</a></h2>
</div>
</body>
</html>';
header('Location: index.php?controller=AdminLogin');
+1 -93
View File
@@ -24,96 +24,4 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
include(_PS_ADMIN_DIR_.'/functions.php');
$errors = array();
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$iso = strtolower(Language::getIsoById((int)$id_lang));
include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php');
/* PrestaShop demo mode */
if (_PS_MODE_DEMO_)
{
$errors[] = Tools::displayError('This functionnality has been disabled.');
}
/* PrestaShop demo mode*/
else if (isset($_POST['Submit']))
{
$errors = array();
if (empty($_POST['email']))
$errors[] = Tools::displayError('E-mail is empty');
elseif (!Validate::isEmail($_POST['email']))
$errors[] = Tools::displayError('Invalid e-mail address');
else
{
$employee = new Employee();
if (!$employee->getByemail($_POST['email']) OR !$employee)
$errors[] = Tools::displayError('This account does not exist');
else
{
if ((strtotime($employee->last_passwd_gen.'+'.Configuration::get('PS_PASSWD_TIME_BACK').' minutes') - time()) > 0 )
$errors[] = Tools::displayError('You can regenerate your password only every').' '.Configuration::get('PS_PASSWD_TIME_BACK').' '.Tools::displayError('minute(s)');
else
{
$pwd = Tools::passwdGen();
$employee->passwd = md5(pSQL(_COOKIE_KEY_.$pwd));
$employee->last_passwd_gen = date('Y-m-d H:i:s', time());
$result = $employee->update();
if (!$result)
$errors[] = Tools::displayError('An error occurred during your password change.');
else
{
if(Mail::Send((int)$id_lang, 'password', Mail::l('Your new admin password'), array('{email}' => $employee->email, '{lastname}' => $employee->lastname, '{firstname}' => $employee->firstname, '{passwd}' => $pwd), $employee->email, $employee->firstname.' '.$employee->lastname))
$confirmation = 'ok';
}
}
}
}
}
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$iso.'" lang="'.$iso.'">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="../css/login.css" />
<title>PrestaShop&trade; - '.translate('Administration panel').'</title>
</head>
<body><div id="container">';
if (sizeof($errors))
{
echo '<div id="error">
<h3>'.translate('There is 1 error').'</h3>
<ol>';
foreach ($errors AS $error)
echo '<li>'.$error.'</li>';
echo '</ol>
</div>';
}
echo '
<div id="login">
<h1>'.Configuration::get('PS_SHOP_NAME').'</h1>
<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
<div class="page-title center">'.translate('Forgot your password?').'</div><br />';
if (isset($confirmation))
echo ' <br />
<div style="font-weight: bold;">'.translate('Your password has been e-mailed to you').'.</div>
<div style="margin: 2em 0 0 0; text-align: right;"><a href="login.php?email='.Tools::safeOutput(Tools::getValue('email')).'">> '.translate('back to login home').'</a></div>';
else
echo ' <span style="font-weight: bold;">'.translate('Please, enter your e-mail address').' </span>
'.translate('(the one you wrote during your registration) in order to receive your access codes by e-mail').'.<br />
<input type="text" name="email" class="input" />
<div>
<div id="submit"><input type="submit" name="Submit" value="'.translate('Send').'" class="button" /></div>
<div id="lost">&nbsp;</div>
</div>
</form>
</div>
<h2><a href="http://www.prestashop.com">&copy; Copyright by PrestaShop. all rights reserved.</a></h2>
</div></body></html>';
header('Location: index.php?controller=AdminLogin');
+1 -1
View File
@@ -30,7 +30,7 @@ define('_PS_ADMIN_DIR_', getcwd());
include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
if (!Context::getContext()->employee->id)
Tools::redirectAdmin('login.php');
Tools::redirectAdmin('index.php?controller=AdminLogin');
$functionArray = array(
'pdf' => 'generateInvoicePDF',
+103
View File
@@ -0,0 +1,103 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 8858 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript">
var there_are = '{l s='There are'}';
var there_is = '{l s='There is'}';
var label_errors = '{l s='errors'}';
var label_error = '{l s='error'}';
</script>
<div id="container">
<div id="error" style="{if !isset($errors)}display:none;{/if}">
{if isset($errors)}
<h3>{if $nbErrors > 1}{l s='There are'}{else}{l s='There is'}{/if} {$nbErrors}{if $nbErrors > 1} {l s='errors'}{else} {l s='error'}{/if}</h3>
<ol style="margin: 0 0 0 20px;">
{foreach from=$errors item="error"}
<li>{$error}</li>
{/foreach}
</ol>
{/if}
</div>
<br />
{if isset($warningSslMessage)}
<div class="warn">
{$warningSslMessage}
</div>
{/if}
<div id="login">
{if !isset($wrong_folder_name)}
<h1>{$shop_name}</h1>
<form action="" method="post" id="login_form" onsubmit="doAjaxLogin();return false;">
<label for="email">{l s='E-mail address:'}</label><br />
<input type="text" id="email" name="email" class="input" value="{if isset($email)}{$email}{/if}" />
<div style="margin: 1.8em 0 0 0;">
<label for="passwd">{l s='Password:'}</label><br />
<input id="passwd" type="password" name="passwd" class="input" value="{if isset($password)}{$password}{/if}"/>
</div>
<div>
<div id="submit">
<input type="submit" name="submitLogin" value="Log in" class="button" style="float:left"/>
<span style="float:left;width:30px">
<img id="ajax-loader" src="../img/loader.gif" style="float:left;margin:2px 0 0 5px;display:none">
</span>
</div>
<div id="lost">
<a href="#" onclick="displayForgotPassword();return false;">{l s='Lost password?'}</a>
</div>
</div>
<script type="text/javascript">
//TODO FOCUS ON EMAIL
</script>
</form>
{else}
<h1>{$shop_name}</h1>
<div style="margin:30px;">
<p><span>{l s='For security reasons, you cannot connect to the Back Office until after you have:'}<br /><br />
<ul>
<li>{l s='delete the /install folder'}</li>
<li>{l s='renamed the /admin folder (eg.) /admin'}{$randomNb}</li>
</ul>
<br />{l s='Please then access this page by the new url (eg.) http://www.domain.tld/admin'}{$randomNb}</span></p>
</div>
{/if}
</div>
<div id="forgot_password" style="display:none">
<h1>{$shop_name}</h1>
<form action="" method="post" onsubmit="doAjaxForgot();return false;">
<div class="page-title center">{l s='Forgot your password?'}</div><br />
<span style="font-weight: bold;">{l s='Please, enter your e-mail address the one you wrote during your registration in order to receive your access codes by e-mail'}</span><br />
<input style="margin-top:20px" type="text" name="email_forgot" id="email_forgot" class="input" />
<div id="submit">
<input type="submit" name="Submit" value="{l s='Send'}" class="button" style="float:left" />
<span style="float:left;width:30px">
<img id="ajax-loader" src="../img/loader.gif" style="float:left;margin:2px 0 0 5px;display:none">
</span>
</div>
<div id="lost"><a href="#" onclick="$('#error').hide();$('#login').revertFlip();return false;">{l s='Back to login'}</a></div>
</form>
</div>
<h2><a href="http://www.prestashop.com">&copy; Copyright by PrestaShop. all rights reserved.</a></h2>
</div>
+9 -8
View File
@@ -1611,14 +1611,19 @@ class AdminControllerCore extends Controller
// ob_start();
if (Tools::getValue('ajax'))
$this->ajax = '1';
/* Server Params */
$protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$protocol_content = (isset($useSSL) && $useSSL && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$this->context->link = new Link($protocol_link, $protocol_content);
$this->timerStart = microtime(true);
if (isset($_GET['logout']))
$this->context->employee->logout();
if (!isset($this->context->employee) || !$this->context->employee->isLoggedBack())
$this->redirect_after = 'login.php'.(!isset($_GET['logout']) ? '?redirect='.$_SERVER['REQUEST_URI'] : '');
if (get_class($this) != 'AdminLoginController' && (!isset($this->context->employee) || !$this->context->employee->isLoggedBack()))
$this->redirect_after = $this->context->link->getAdminLink('AdminLogin').(!isset($_GET['logout']) ? '?redirect='.$_SERVER['REQUEST_URI'] : '');
// Set current index
$current_index = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller : '');
@@ -1627,11 +1632,7 @@ class AdminControllerCore extends Controller
$current_index .= '&back='.urlencode($back);
self::$currentIndex = $current_index;
/* Server Params */
$protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$protocol_content = (isset($useSSL) && $useSSL && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content);
$this->context->link = $link;
// @todo : put the definitions in Controller class
if (!defined('_PS_BASE_URL_'))
define('_PS_BASE_URL_', Tools::getShopDomain(true));
+206
View File
@@ -0,0 +1,206 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminLoginController extends AdminController
{
public function __construct()
{
$this->errors = array();
$this->context = Context::getContext();
$this->display_header = false;
$this->display_footer = false;
parent::__construct();
}
public function setMedia()
{
$this->addJquery();
$this->addJqueryPlugin('flip');
$this->addCSS(_PS_CSS_DIR_.'login.css');
$this->addJS(_PS_JS_DIR_.'login.js');
$this->addJqueryUI('ui.widget');
$this->addJqueryUI('effects.core');
}
public function initContent()
{
if ((empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off') AND Configuration::get('PS_SSL_ENABLED'))
{
// You can uncomment theses lines if you want to force https even from localhost and automatically redirect
// header('HTTP/1.1 301 Moved Permanently');
// header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
// exit();
$clientIsMaintenanceOrLocal = in_array(Tools::getRemoteAddr(), array_merge(array('127.0.0.1'),explode(',', Configuration::get('PS_MAINTENANCE_IP'))));
// If ssl is enabled, https protocol is required. Exception for maintenance and local (127.0.0.1) IP
if ($clientIsMaintenanceOrLocal)
$this->errors = Tools::displayError('SSL is activated. However, your IP is allowed to use unsecure mode (Maintenance or local IP).');
else
{
$warningSslMessage = Tools::displayError('SSL is activated. Please connect using the following url to log in in secure mode (https).');
$warningSslMessage .= '<a href="https://'.Tools::getServerName().Tools::safeOutput($_SERVER['REQUEST_URI']).'">https://'.Tools::getServerName().Tools::safeOutput($_SERVER['REQUEST_URI']).'</a>';
$this->context->smarty->assign(array('warningSslMessage' => $warningSslMessage));
}
}
if(file_exists(_PS_ADMIN_DIR_.'/../install') OR file_exists(_PS_ADMIN_DIR_.'/../admin'))
$this->context->smarty->assign(
array(
'randomNb' => rand(100, 999),
'wrong_folder_name' => true)
);
if ($nbErrors = sizeof($this->errors))
$this->context->smarty->assign(
array(
'errors' => $this->errors,
'nbErrors' => $nbErrors,
'shop_name' => Tools::safeOutput(Configuration::get('PS_SHOP_NAME'))
)
);
$this->setMedia();
$this->initHeader();
parent::initContent();
$this->initFooter();
}
public function checkToken()
{
return true;
}
public function postProcess()
{
if (Tools::isSubmit('submitLogin'))
$this->processLogin();
elseif (Tools::isSubmit('submitForgot'))
$this->processForgot();
}
public function processLogin()
{
/* Check fields validity */
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
if (empty($email))
$this->errors[] = Tools::displayError('E-mail is empty');
elseif (!Validate::isEmail($email))
$this->errors[] = Tools::displayError('Invalid e-mail address');
if (empty($passwd))
$this->errors[] = Tools::displayError('Password is blank');
else if (!Validate::isPasswd($passwd))
$this->errors[] = Tools::displayError('Invalid password');
if (!sizeof($this->errors))
{
/* Seeking for employee */
$employee = new Employee();
if (!$employee->getByemail($email, $passwd))
{
$this->errors[] = Tools::displayError('Employee does not exist or password is incorrect.');
$employee->logout();
}
else
{
$employee->remote_addr = ip2long(Tools::getRemoteAddr());
/* Creating cookie */
$cookie = Context::getContext()->cookie;
$cookie->id_employee = $employee->id;
$cookie->email = $employee->email;
$cookie->profile = $employee->id_profile;
$cookie->passwd = $employee->passwd;
$cookie->remote_addr = $employee->remote_addr;
$cookie->write();
/* Redirect to admin panel */
if (isset($_GET['redirect']))
$url = strval($_GET['redirect'].(isset($_GET['token']) ? ('&token='.$_GET['token']) : ''));
else
$url = 'index.php';
if (!Validate::isCleanHtml($url))
die(Tools::displayError());
if (Tools::isSubmit('ajax'))
die(Tools::jsonEncode(array('hasErrors' => false, 'redirect' => $this->context->link->getAdminLink('AdminHome'))));
else
$this->redirect_after = $this->context->link->getAdminLink('AdminHome');
}
}
if (Tools::isSubmit('ajax'))
die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors)));
}
public function processForgot()
{
$email = trim(Tools::getValue('email_forgot'));
if (empty($email))
$this->errors[] = Tools::displayError('E-mail is empty');
elseif (!Validate::isEmail($email))
$this->errors[] = Tools::displayError('Invalid e-mail address');
else
{
$employee = new Employee();
if (!$employee->getByemail($email) OR !$employee)
$this->errors[] = Tools::displayError('This account does not exist');
else if ((strtotime($employee->last_passwd_gen.'+'.Configuration::get('PS_PASSWD_TIME_BACK').' minutes') - time()) > 0 )
$this->errors[] = Tools::displayError('You can regenerate your password only every').' '.Configuration::get('PS_PASSWD_TIME_BACK').' '.Tools::displayError('minute(s)');
}
if (_PS_MODE_DEMO_)
$errors[] = Tools::displayError('This functionnality has been disabled.');
if(!sizeof($this->errors))
{
$pwd = Tools::passwdGen();
$employee->passwd = md5(pSQL(_COOKIE_KEY_.$pwd));
$employee->last_passwd_gen = date('Y-m-d H:i:s', time());
$result = $employee->update();
if (!$result)
$this->errors[] = Tools::displayError('An error occurred during your password change.');
else
{
$params = array(
'{email}' => $employee->email,
'{lastname}' => $employee->lastname,
'{firstname}' => $employee->firstname,
'{passwd}' => $pwd
);
if (Mail::Send((int)Configuration::get('PS_LANG_DEFAULT'), 'password', Mail::l('Your new admin password'), $params, $employee->email, $employee->firstname.' '.$employee->lastname))
die(Tools::jsonEncode(array('hasErrors' => false, 'confirm' => $this->l('Your password has been e-mailed to you'))));
else
die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => Tools::displayError('An error occurred during your password change.'))));
}
}
else if (Tools::isSubmit('ajax'))
die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors)));
}
}
+1 -1
View File
@@ -959,7 +959,7 @@ INSERT INTO `PREFIX_tab` (`id_tab`, `class_name`, `id_parent`, `position`) VALUE
(103, 'AdminAccountingManagement', 102, 1),
(104, 'AdminAccountingExport', 102, 2),
(105, 'AdminCmsCategories', -1, 0),
(106, 'AdminCms', -1, 0);
(106, 'AdminCms', -1, 0), (107, 'AdminLogin', -1 , 0);
INSERT INTO `PREFIX_access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) (SELECT 1, id_tab, 1, 1, 1, 1 FROM `PREFIX_tab`);
+337
View File
@@ -0,0 +1,337 @@
/*
* Flip! jQuery Plugin (http://lab.smashup.it/flip/)
* @author Luca Manno (luca@smashup.it) [http://i.smashup.it]
* [Original idea by Nicola Rizzo (thanks!)]
*
* @version 0.9.9 [Nov. 2009]
*
* @changelog
* v 0.9.9 -> Fix transparency over non-colored background. Added dontChangeColor option.
* Added $clone and $this parameters to on.. callback functions.
* Force hexadecimal color values. Made safe for noConflict use.
* Some refactoring. [Henrik Hjelte, Jul. 10, 2009]
* Added revert options, fixes and improvements on color management.
* Released in Nov 2009
* v 0.5 -> Added patch to make it work with Opera (thanks to Peter Siewert), Added callbacks [Feb. 1, 2008]
* v 0.4.1 -> Fixed a regression in Chrome and Safari caused by getTransparent [Oct. 1, 2008]
* v 0.4 -> Fixed some bugs with transparent color. Now Flip! works on non-white backgrounds | Update: jquery.color.js plugin or jqueryUI still needed :( [Sept. 29, 2008]
* v 0.3 -> Now is possibile to define the content after the animation.
* (jQuery object or text/html is allowed) [Sept. 25, 2008]
* v 0.2 -> Fixed chainability and buggy innertext rendering (xNephilimx thanks!)
* v 0.1 -> Starting release [Sept. 11, 2008]
*
*/
(function($) {
function int_prop(fx){
fx.elem.style[ fx.prop ] = parseInt(fx.now,10) + fx.unit;
}
var throwError=function(message) {
throw({name:"jquery.flip.js plugin error",message:message});
};
var isIE6orOlder=function() {
// User agent sniffing is clearly out of fashion and $.browser will be be deprectad.
// Now, I can't think of a way to feature detect that IE6 doesn't show transparent
// borders in the correct way.
// Until then, this function will do, and be partly political correct, allowing
// 0.01 percent of the internet users to tweak with their UserAgent string.
//
// Not leadingWhiteSpace is to separate IE family from, well who knows?
// Maybe some version of Opera?
// The second guess behind this is that IE7+ will keep supporting maxHeight in the future.
// First guess changed to dean edwards ie sniffing http://dean.edwards.name/weblog/2007/03/sniff/
return (/*@cc_on!@*/false && (typeof document.body.style.maxHeight === "undefined"));
};
// Some named colors to work with
// From Interface by Stefan Petre
// http://interface.eyecon.ro/
var colors = {
aqua:[0,255,255],
azure:[240,255,255],
beige:[245,245,220],
black:[0,0,0],
blue:[0,0,255],
brown:[165,42,42],
cyan:[0,255,255],
darkblue:[0,0,139],
darkcyan:[0,139,139],
darkgrey:[169,169,169],
darkgreen:[0,100,0],
darkkhaki:[189,183,107],
darkmagenta:[139,0,139],
darkolivegreen:[85,107,47],
darkorange:[255,140,0],
darkorchid:[153,50,204],
darkred:[139,0,0],
darksalmon:[233,150,122],
darkviolet:[148,0,211],
fuchsia:[255,0,255],
gold:[255,215,0],
green:[0,128,0],
indigo:[75,0,130],
khaki:[240,230,140],
lightblue:[173,216,230],
lightcyan:[224,255,255],
lightgreen:[144,238,144],
lightgrey:[211,211,211],
lightpink:[255,182,193],
lightyellow:[255,255,224],
lime:[0,255,0],
magenta:[255,0,255],
maroon:[128,0,0],
navy:[0,0,128],
olive:[128,128,0],
orange:[255,165,0],
pink:[255,192,203],
purple:[128,0,128],
violet:[128,0,128],
red:[255,0,0],
silver:[192,192,192],
white:[255,255,255],
yellow:[255,255,0],
transparent: [255,255,255]
};
var acceptHexColor=function(color) {
if(color && color.indexOf("#")==-1 && color.indexOf("(")==-1){
return "rgb("+colors[color].toString()+")";
} else {
return color;
}
};
$.extend( $.fx.step, {
borderTopWidth : int_prop,
borderBottomWidth : int_prop,
borderLeftWidth: int_prop,
borderRightWidth: int_prop
});
$.fn.revertFlip = function(){
return this.each( function(){
var $this = $(this);
$this.flip($this.data('flipRevertedSettings'));
});
};
$.fn.flip = function(settings){
return this.each( function() {
var $this=$(this), flipObj, $clone, dirOption, dirOptions, newContent, ie6=isIE6orOlder();
if($this.data('flipLock')){
return false;
}
var revertedSettings = {
direction: (function(direction){
switch(direction)
{
case "tb":
return "bt";
case "bt":
return "tb";
case "lr":
return "rl";
case "rl":
return "lr";
default:
return "bt";
}
})(settings.direction),
bgColor: acceptHexColor(settings.color) || "#999",
color: acceptHexColor(settings.bgColor) || $this.css("background-color"),
content: $this.html(),
speed: settings.speed || 500,
onBefore: settings.onBefore || function(){},
onEnd: settings.onEnd || function(){},
onAnimation: settings.onAnimation || function(){}
};
$this
.data('flipRevertedSettings',revertedSettings)
.data('flipLock',1)
.data('flipSettings',revertedSettings);
flipObj = {
width: $this.width(),
height: $this.height(),
bgColor: acceptHexColor(settings.bgColor) || $this.css("background-color"),
fontSize: $this.css("font-size") || "12px",
direction: settings.direction || "tb",
toColor: acceptHexColor(settings.color) || "#999",
speed: settings.speed || 500,
top: $this.offset().top,
left: $this.offset().left,
target: settings.content || null,
transparent: "transparent",
dontChangeColor: settings.dontChangeColor || false,
onBefore: settings.onBefore || function(){},
onEnd: settings.onEnd || function(){},
onAnimation: settings.onAnimation || function(){}
};
// This is the first part of a trick to support
// transparent borders using chroma filter for IE6
// The color below is arbitrary, lets just hope it is not used in the animation
ie6 && (flipObj.transparent="#123456");
$clone= $this.css("visibility","hidden")
.clone(true)
.data('flipLock',1)
.appendTo("body")
.html("")
.css({visibility:"visible",position:"absolute",left:flipObj.left,top:flipObj.top,margin:0,zIndex:9999,"-webkit-box-shadow":"0px 0px 0px #000","-moz-box-shadow":"0px 0px 0px #000"});
var defaultStart=function() {
return {
backgroundColor: flipObj.transparent,
fontSize:0,
lineHeight:0,
borderTopWidth:0,
borderLeftWidth:0,
borderRightWidth:0,
borderBottomWidth:0,
borderTopColor:flipObj.transparent,
borderBottomColor:flipObj.transparent,
borderLeftColor:flipObj.transparent,
borderRightColor:flipObj.transparent,
background: "none",
borderStyle:'solid',
height:0,
width:0
};
};
var defaultHorizontal=function() {
var waist=(flipObj.height/100)*25;
var start=defaultStart();
start.width=flipObj.width;
return {
"start": start,
"first": {
borderTopWidth: 0,
borderLeftWidth: waist,
borderRightWidth: waist,
borderBottomWidth: 0,
borderTopColor: '#999',
borderBottomColor: '#999',
top: (flipObj.top+(flipObj.height/2)),
left: (flipObj.left-waist)},
"second": {
borderBottomWidth: 0,
borderTopWidth: 0,
borderLeftWidth: 0,
borderRightWidth: 0,
borderTopColor: flipObj.transparent,
borderBottomColor: flipObj.transparent,
top: flipObj.top,
left: flipObj.left}
};
};
var defaultVertical=function() {
var waist=(flipObj.height/100)*25;
var start=defaultStart();
start.height=flipObj.height;
return {
"start": start,
"first": {
borderTopWidth: waist,
borderLeftWidth: 0,
borderRightWidth: 0,
borderBottomWidth: waist,
borderLeftColor: '#999',
borderRightColor: '#999',
top: flipObj.top-waist,
left: flipObj.left+(flipObj.width/2)},
"second": {
borderTopWidth: 0,
borderLeftWidth: 0,
borderRightWidth: 0,
borderBottomWidth: 0,
borderLeftColor: flipObj.transparent,
borderRightColor: flipObj.transparent,
top: flipObj.top,
left: flipObj.left}
};
};
dirOptions = {
"tb": function () {
var d=defaultHorizontal();
d.start.borderTopWidth=flipObj.height;
d.start.borderTopColor=flipObj.bgColor;
d.second.borderBottomWidth= flipObj.height;
d.second.borderBottomColor= flipObj.toColor;
return d;
},
"bt": function () {
var d=defaultHorizontal();
d.start.borderBottomWidth=flipObj.height;
d.start.borderBottomColor= flipObj.bgColor;
d.second.borderTopWidth= flipObj.height;
d.second.borderTopColor= flipObj.toColor;
return d;
},
"lr": function () {
var d=defaultVertical();
d.start.borderLeftWidth=flipObj.width;
d.start.borderLeftColor=flipObj.bgColor;
d.second.borderRightWidth= flipObj.width;
d.second.borderRightColor= flipObj.toColor;
return d;
},
"rl": function () {
var d=defaultVertical();
d.start.borderRightWidth=flipObj.width;
d.start.borderRightColor=flipObj.bgColor;
d.second.borderLeftWidth= flipObj.width;
d.second.borderLeftColor= flipObj.toColor;
return d;
}
};
dirOption=dirOptions[flipObj.direction]();
// Second part of IE6 transparency trick.
ie6 && (dirOption.start.filter="chroma(color="+flipObj.transparent+")");
newContent = function(){
var target = flipObj.target;
return target && target.jquery ? target.html() : target;
};
$clone.queue(function(){
flipObj.onBefore($clone,$this);
$clone.html('').css(dirOption.start);
$clone.dequeue();
});
$clone.animate(dirOption.first,flipObj.speed);
$clone.queue(function(){
flipObj.onAnimation($clone,$this);
$clone.dequeue();
});
$clone.animate(dirOption.second,flipObj.speed);
$clone.queue(function(){
if (!flipObj.dontChangeColor) {
$this.css({backgroundColor: flipObj.toColor});
}
$this.css({visibility: "visible"});
var nC = newContent();
if(nC){$this.html(nC);}
$clone.remove();
flipObj.onEnd($clone,$this);
$this.removeData('flipLock');
$clone.dequeue();
});
});
};
})(jQuery);
+104
View File
@@ -0,0 +1,104 @@
$(document).ready(function(){
if (document.getElementById('email'))
document.getElementById('email').focus();
});
function displayForgotPassword()
{
$('#error').hide();
$("#login").flip({
direction:'tb',
color : '#FFF',
content: $('#forgot_password')
})
}
function doAjaxLogin()
{
$('#error').hide();
$('#ajax-loader').fadeIn('slow', function () {
$.ajax({
type:"POST",
url: "ajax-tab.php",
async: true,
dataType: "json",
data : {
ajax: "1",
token: "",
controller: "AdminLogin",
submitLogin: "1",
passwd : $('#passwd').val(),
email : $('#email').val()
},
success : function(jsonData)
{
if (jsonData.hasErrors)
{
displayErrors(jsonData.errors);
$('#login').effect("shake", { times:3 }, 300);
}
else
{
window.location.href = jsonData.redirect;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#error').html('<h3>TECHNICAL ERROR:</h3><p>Details: Error thrown: ' + XMLHttpRequest + '</p><p>Text status: ' + textStatus + '</p>');
$('#error').fadeIn();
$('#ajax-loader').fadeOut('slow');
}
});
});
}
function doAjaxForgot()
{
$('#error').hide();
$('#ajax-loader').fadeIn('slow', function () {
$.ajax({
type:"POST",
url: "ajax-tab.php",
async: true,
dataType: "json",
data : {
ajax: "1",
token: "",
controller: "AdminLogin",
submitForgot: "1",
email_forgot: $('#email_forgot').val()
},
success : function(jsonData)
{
if (jsonData.hasErrors)
{
displayErrors(jsonData.errors);
$('#login').effect("shake", { times:3 }, 300);
}
else
{
window.location.href = jsonData.redirect;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#error').html('<h3>TECHNICAL ERROR:</h3><p>Details: Error thrown: ' + XMLHttpRequest + '</p><p>Text status: ' + textStatus + '</p>');
$('#error').fadeIn();
$('#ajax-loader').fadeOut('slow');
}
});
});
}
function displayErrors(errors)
{
str_errors = '<h3>'+(errors.length > 1 ? there_are : there_is )+' '+errors.length+' '+(errors.length > 1 ? label_errors : label_error )+'</h3><ol>';
for(error in errors)
//IE6 bug fix
if(error != 'indexOf')
str_errors += '<li>'+errors[error] + '</li>';
$('#ajax-loader').fadeOut('slow');
$('#error').html(str_errors+'</ol>');
$('#error').fadeIn();
}