2007-06-02 01:53:54 +00:00
|
|
|
<?php
|
2012-09-02 07:27:06 +00:00
|
|
|
/* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
2012-12-30 14:11:07 +00:00
|
|
|
* Copyright (C) 2008-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
2012-09-02 07:27:06 +00:00
|
|
|
* Copyright (C) 2008-2011 Juanjo Menent <jmenent@2byte.es>
|
2007-06-02 01:53:54 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-06-02 01:53:54 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-07-31 23:19:04 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-06-02 01:53:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2009-03-13 13:12:43 +00:00
|
|
|
/**
|
|
|
|
|
* \file htdocs/user/passwordforgotten.php
|
2011-07-08 15:50:28 +00:00
|
|
|
* \brief Page to ask a new password
|
2009-03-13 13:12:43 +00:00
|
|
|
*/
|
2007-06-02 01:53:54 +00:00
|
|
|
|
2009-12-29 18:10:48 +00:00
|
|
|
define("NOLOGIN",1); // This means this output page does not require to be logged.
|
2008-01-20 21:53:43 +00:00
|
|
|
|
2012-08-22 21:24:21 +00:00
|
|
|
require '../main.inc.php';
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
|
2012-09-02 07:27:06 +00:00
|
|
|
if (! empty($conf->ldap->enabled))
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
|
2007-12-29 17:06:53 +00:00
|
|
|
|
2011-10-29 21:52:05 +00:00
|
|
|
$langs->load("errors");
|
2007-06-02 01:53:54 +00:00
|
|
|
$langs->load("users");
|
|
|
|
|
$langs->load("companies");
|
|
|
|
|
$langs->load("ldap");
|
2011-12-28 00:57:47 +00:00
|
|
|
$langs->load("other");
|
2007-06-02 01:53:54 +00:00
|
|
|
|
2009-12-29 18:10:48 +00:00
|
|
|
// Security check
|
2012-09-15 08:01:35 +00:00
|
|
|
if (! empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
|
2010-10-22 19:42:04 +00:00
|
|
|
{
|
2011-07-08 18:49:16 +00:00
|
|
|
header("Location: ".DOL_URL_ROOT.'/');
|
|
|
|
|
exit;
|
2010-10-22 19:42:04 +00:00
|
|
|
}
|
2009-12-29 11:30:41 +00:00
|
|
|
|
2012-09-02 07:27:06 +00:00
|
|
|
$action=GETPOST('action', 'alpha');
|
2007-06-02 01:53:54 +00:00
|
|
|
$mode=$dolibarr_main_authentication;
|
|
|
|
|
if (! $mode) $mode='http';
|
|
|
|
|
|
2011-04-26 20:11:18 +00:00
|
|
|
$username = GETPOST('username');
|
|
|
|
|
$passwordmd5 = GETPOST('passwordmd5');
|
2011-09-20 09:40:27 +00:00
|
|
|
$conf->entity = (GETPOST('entity') ? GETPOST('entity') : 1);
|
2007-06-02 01:53:54 +00:00
|
|
|
|
2012-09-07 15:23:16 +00:00
|
|
|
// Instantiate hooks of thirdparty module only if not already define
|
2012-09-02 07:27:06 +00:00
|
|
|
$hookmanager->initHooks(array('passwordforgottenpage'));
|
|
|
|
|
|
2013-04-05 16:09:05 +00:00
|
|
|
|
2013-06-05 14:12:07 +00:00
|
|
|
if (GETPOST('dol_hide_leftmenu') || ! empty($_SESSION['dol_hide_leftmenu'])) $conf->dol_hide_leftmenu=1;
|
|
|
|
|
if (GETPOST('dol_hide_topmenu') || ! empty($_SESSION['dol_hide_topmenu'])) $conf->dol_hide_topmenu=1;
|
|
|
|
|
if (GETPOST('dol_optimize_smallscreen') || ! empty($_SESSION['dol_optimize_smallscreen'])) $conf->dol_optimize_smallscreen=1;
|
|
|
|
|
if (GETPOST('dol_no_mouse_hover') || ! empty($_SESSION['dol_no_mouse_hover'])) $conf->dol_no_mouse_hover=1;
|
|
|
|
|
if (GETPOST('dol_use_jmobile') || ! empty($_SESSION['dol_use_jmobile'])) $conf->dol_use_jmobile=1;
|
2013-04-05 16:09:05 +00:00
|
|
|
|
2007-10-21 20:40:24 +00:00
|
|
|
|
2007-06-02 01:53:54 +00:00
|
|
|
/**
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2011-07-08 15:50:28 +00:00
|
|
|
// Validate new password
|
2011-04-26 20:11:18 +00:00
|
|
|
if ($action == 'validatenewpassword' && $username && $passwordmd5)
|
2007-06-02 01:53:54 +00:00
|
|
|
{
|
|
|
|
|
$edituser = new User($db);
|
2010-04-28 07:31:34 +00:00
|
|
|
$result=$edituser->fetch('',$_GET["username"]);
|
2011-07-08 18:49:16 +00:00
|
|
|
if ($result < 0)
|
|
|
|
|
{
|
2011-04-26 20:11:18 +00:00
|
|
|
$message = '<div class="error">'.$langs->trans("ErrorLoginDoesNotExists",$username).'</div>';
|
2011-07-08 18:49:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-09-06 06:53:52 +00:00
|
|
|
if (dol_hash($edituser->pass_temp) == $passwordmd5)
|
2011-07-08 18:49:16 +00:00
|
|
|
{
|
|
|
|
|
$newpassword=$edituser->setPassword($user,$edituser->pass_temp,0);
|
|
|
|
|
dol_syslog("passwordforgotten.php new password for user->id=".$edituser->id." validated in database");
|
|
|
|
|
header("Location: ".DOL_URL_ROOT.'/');
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-12-17 14:47:01 +00:00
|
|
|
$langs->load("errors");
|
|
|
|
|
$message = '<div class="error">'.$langs->trans("ErrorFailedToValidatePasswordReset").'</div>';
|
2011-07-08 18:49:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-06-02 01:53:54 +00:00
|
|
|
}
|
|
|
|
|
// Action modif mot de passe
|
2011-04-26 20:11:18 +00:00
|
|
|
if ($action == 'buildnewpassword' && $username)
|
2007-06-02 01:53:54 +00:00
|
|
|
{
|
2012-01-07 22:31:25 +00:00
|
|
|
$sessionkey = 'dol_antispam_value';
|
2012-01-07 20:32:35 +00:00
|
|
|
$ok=(array_key_exists($sessionkey, $_SESSION) === TRUE && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
|
2011-07-08 18:49:16 +00:00
|
|
|
|
|
|
|
|
// Verify code
|
2012-01-07 20:32:35 +00:00
|
|
|
if (! $ok)
|
2011-07-08 18:49:16 +00:00
|
|
|
{
|
|
|
|
|
$message = '<div class="error">'.$langs->trans("ErrorBadValueForCode").'</div>';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$edituser = new User($db);
|
|
|
|
|
$result=$edituser->fetch('',$username,'',1);
|
|
|
|
|
if ($result <= 0 && $edituser->error == 'USERNOTFOUND')
|
|
|
|
|
{
|
|
|
|
|
$message = '<div class="error">'.$langs->trans("ErrorLoginDoesNotExists",$username).'</div>';
|
|
|
|
|
$username='';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (! $edituser->email)
|
|
|
|
|
{
|
|
|
|
|
$message = '<div class="error">'.$langs->trans("ErrorLoginHasNoEmail").'</div>';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$newpassword=$edituser->setPassword($user,'',1);
|
|
|
|
|
if ($newpassword < 0)
|
|
|
|
|
{
|
|
|
|
|
// Failed
|
|
|
|
|
$message = '<div class="error">'.$langs->trans("ErrorFailedToChangePassword").'</div>';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Success
|
|
|
|
|
if ($edituser->send_password($user,$newpassword,1) > 0)
|
|
|
|
|
{
|
|
|
|
|
$message = '<div class="ok">'.$langs->trans("PasswordChangeRequestSent",$edituser->login,$edituser->email).'</div>';
|
|
|
|
|
//$message.=$newpassword;
|
|
|
|
|
$username='';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//$message = '<div class="ok">'.$langs->trans("PasswordChangedTo",$newpassword).'</div>';
|
|
|
|
|
$message.= '<div class="error">'.$edituser->error.'</div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-02 01:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-07-08 15:50:28 +00:00
|
|
|
/**
|
|
|
|
|
* View
|
2007-06-02 01:53:54 +00:00
|
|
|
*/
|
2011-07-08 15:50:28 +00:00
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
$php_self = $_SERVER['PHP_SELF'];
|
|
|
|
|
$php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:'';
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
$dol_url_root = DOL_URL_ROOT;
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2010-09-22 08:52:48 +00:00
|
|
|
// Title
|
|
|
|
|
$title='Dolibarr '.DOL_VERSION;
|
|
|
|
|
if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;
|
|
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
// Select templates
|
2013-04-03 13:20:56 +00:00
|
|
|
if (file_exists(DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/tpl/passwordforgotten.tpl.php"))
|
2010-04-12 18:56:53 +00:00
|
|
|
{
|
2013-04-03 13:20:56 +00:00
|
|
|
$template_dir = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/tpl/";
|
2010-04-12 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-04-03 13:20:56 +00:00
|
|
|
$template_dir = DOL_DOCUMENT_ROOT."/core/tpl/";
|
2010-04-12 18:56:53 +00:00
|
|
|
}
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2013-01-10 07:27:12 +00:00
|
|
|
// Note: $conf->css looks like '/theme/eldy/style.css.php'
|
|
|
|
|
$conf->css = "/theme/".(GETPOST('theme')?GETPOST('theme','alpha'):$conf->theme)."/style.css.php";
|
2013-08-07 18:56:10 +00:00
|
|
|
//$themepath=dol_buildpath((empty($conf->global->MAIN_FORCETHEMEDIR)?'':$conf->global->MAIN_FORCETHEMEDIR).$conf->css,1);
|
|
|
|
|
$themepath=dol_buildpath($conf->css,1);
|
2013-01-10 07:27:12 +00:00
|
|
|
if (! empty($conf->modules_parts['theme'])) // This slow down
|
|
|
|
|
{
|
|
|
|
|
foreach($conf->modules_parts['theme'] as $reldir)
|
|
|
|
|
{
|
|
|
|
|
if (file_exists(dol_buildpath($reldir.$conf->css, 0)))
|
|
|
|
|
{
|
|
|
|
|
$themepath=dol_buildpath($reldir.$conf->css, 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$conf_css = $themepath."?lang=".$langs->defaultlang;
|
2010-04-22 19:45:59 +00:00
|
|
|
|
2012-09-07 15:23:16 +00:00
|
|
|
$jquerytheme = 'smoothness';
|
2012-09-02 09:36:42 +00:00
|
|
|
if (! empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
|
|
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_background.png'))
|
|
|
|
|
{
|
2011-07-08 18:49:16 +00:00
|
|
|
$login_background = DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_background.png';
|
2007-06-02 01:53:54 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-07-08 18:49:16 +00:00
|
|
|
$login_background = DOL_URL_ROOT.'/theme/login_background.png';
|
2010-04-12 18:56:53 +00:00
|
|
|
}
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2011-04-26 20:11:18 +00:00
|
|
|
if (! $username) $focus_element = 'username';
|
2010-04-12 18:56:53 +00:00
|
|
|
else $focus_element = 'password';
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
// Send password button enabled ?
|
|
|
|
|
$disabled='disabled';
|
2011-03-30 07:55:22 +00:00
|
|
|
if (preg_match('/dolibarr/i',$mode)) $disabled='';
|
2012-09-15 08:01:35 +00:00
|
|
|
if (! empty($conf->global->MAIN_SECURITY_ENABLE_SENDPASSWORD)) $disabled=''; // To force button enabled
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
// Show logo (search in order: small company logo, large company logo, theme logo, common logo)
|
|
|
|
|
$width=0;
|
|
|
|
|
$rowspan=2;
|
|
|
|
|
$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
|
|
|
|
|
if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small))
|
|
|
|
|
{
|
2012-09-02 09:36:42 +00:00
|
|
|
$urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=companylogo&file='.urlencode('thumbs/'.$mysoc->logo_small);
|
2010-04-12 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
elseif (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo))
|
|
|
|
|
{
|
2012-09-02 09:36:42 +00:00
|
|
|
$urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=companylogo&file='.urlencode($mysoc->logo);
|
|
|
|
|
$width=128;
|
|
|
|
|
}
|
|
|
|
|
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/dolibarr_logo.png'))
|
|
|
|
|
{
|
|
|
|
|
$urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/dolibarr_logo.png';
|
|
|
|
|
}
|
|
|
|
|
elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.png'))
|
|
|
|
|
{
|
|
|
|
|
$urllogo=DOL_URL_ROOT.'/theme/dolibarr_logo.png';
|
2010-04-12 18:56:53 +00:00
|
|
|
}
|
2010-01-04 19:39:16 +00:00
|
|
|
|
2010-04-12 18:56:53 +00:00
|
|
|
// Security graphical code
|
|
|
|
|
if (function_exists("imagecreatefrompng") && ! $disabled)
|
|
|
|
|
{
|
2012-09-02 09:36:42 +00:00
|
|
|
$captcha = 1;
|
|
|
|
|
$captcha_refresh = img_picto($langs->trans("Refresh"),'refresh','id="captcha_refresh_img"');
|
2010-04-12 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:23:16 +00:00
|
|
|
// Execute hook getPasswordForgottenPageOptions
|
|
|
|
|
// Should be an array with differents options in $hookmanager->resArray
|
|
|
|
|
$parameters=array('entity' => GETPOST('entity','int'));
|
2012-09-02 07:27:06 +00:00
|
|
|
$hookmanager->executeHooks('getPasswordForgottenPageOptions',$parameters); // Note that $action and $object may have been modified by some hooks
|
|
|
|
|
|
2012-08-23 00:04:35 +00:00
|
|
|
include $template_dir.'passwordforgotten.tpl.php'; // To use native PHP
|
2010-04-12 18:56:53 +00:00
|
|
|
|
2013-01-16 14:45:17 +00:00
|
|
|
?>
|