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

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10608 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
vAugagneur
2011-11-23 21:32:11 +00:00
parent b03a1730f6
commit 66b1f844e4
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>