PageRenderTime 57ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/user/passwordforgotten.php

https://bitbucket.org/speedealing/speedealing
PHP | 230 lines | 159 code | 28 blank | 43 comment | 38 complexity | 4a0b62ff650bc1193ee562e592e9cec2 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2008-2011 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/user/passwordforgotten.php
  21. * \brief Page to ask a new password
  22. */
  23. define("NOLOGIN",1); // This means this output page does not require to be logged.
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  27. if (! empty($conf->ldap->enabled))
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  29. $langs->load("errors");
  30. $langs->load("users");
  31. $langs->load("companies");
  32. $langs->load("ldap");
  33. $langs->load("other");
  34. // Security check
  35. if (! empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
  36. {
  37. header("Location: ".DOL_URL_ROOT.'/');
  38. exit;
  39. }
  40. $action=GETPOST('action', 'alpha');
  41. $mode=$dolibarr_main_authentication;
  42. if (! $mode) $mode='http';
  43. $username = GETPOST('username');
  44. $passwordmd5 = GETPOST('passwordmd5');
  45. $conf->entity = (GETPOST('entity') ? GETPOST('entity') : 1);
  46. // Instantiate hooks of thirdparty module only if not already define
  47. $hookmanager->initHooks(array('passwordforgottenpage'));
  48. /**
  49. * Actions
  50. */
  51. // Validate new password
  52. if ($action == 'validatenewpassword' && $username && $passwordmd5)
  53. {
  54. $edituser = new User($db);
  55. $result=$edituser->fetch('',$_GET["username"]);
  56. if ($result < 0)
  57. {
  58. $message = '<div class="error">'.$langs->trans("ErrorLoginDoesNotExists",$username).'</div>';
  59. }
  60. else
  61. {
  62. if (dol_hash($edituser->pass_temp) == $passwordmd5)
  63. {
  64. $newpassword=$edituser->setPassword($user,$edituser->pass_temp,0);
  65. dol_syslog("passwordforgotten.php new password for user->id=".$edituser->id." validated in database");
  66. header("Location: ".DOL_URL_ROOT.'/');
  67. exit;
  68. }
  69. else
  70. {
  71. $message = '<div class="error">'.$langs->trans("ErrorFailedToValidatePassword").'</div>';
  72. }
  73. }
  74. }
  75. // Action modif mot de passe
  76. if ($action == 'buildnewpassword' && $username)
  77. {
  78. $sessionkey = 'dol_antispam_value';
  79. $ok=(array_key_exists($sessionkey, $_SESSION) === TRUE && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
  80. // Verify code
  81. if (! $ok)
  82. {
  83. $message = '<div class="error">'.$langs->trans("ErrorBadValueForCode").'</div>';
  84. }
  85. else
  86. {
  87. $edituser = new User($db);
  88. $result=$edituser->fetch('',$username,'',1);
  89. if ($result <= 0 && $edituser->error == 'USERNOTFOUND')
  90. {
  91. $message = '<div class="error">'.$langs->trans("ErrorLoginDoesNotExists",$username).'</div>';
  92. $username='';
  93. }
  94. else
  95. {
  96. if (! $edituser->email)
  97. {
  98. $message = '<div class="error">'.$langs->trans("ErrorLoginHasNoEmail").'</div>';
  99. }
  100. else
  101. {
  102. $newpassword=$edituser->setPassword($user,'',1);
  103. if ($newpassword < 0)
  104. {
  105. // Failed
  106. $message = '<div class="error">'.$langs->trans("ErrorFailedToChangePassword").'</div>';
  107. }
  108. else
  109. {
  110. // Success
  111. if ($edituser->send_password($user,$newpassword,1) > 0)
  112. {
  113. $message = '<div class="ok">'.$langs->trans("PasswordChangeRequestSent",$edituser->login,$edituser->email).'</div>';
  114. //$message.=$newpassword;
  115. $username='';
  116. }
  117. else
  118. {
  119. //$message = '<div class="ok">'.$langs->trans("PasswordChangedTo",$newpassword).'</div>';
  120. $message.= '<div class="error">'.$edituser->error.'</div>';
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. /**
  128. * View
  129. */
  130. $php_self = $_SERVER['PHP_SELF'];
  131. $php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:'';
  132. $dol_url_root = DOL_URL_ROOT;
  133. // Title
  134. $title='Dolibarr '.DOL_VERSION;
  135. if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;
  136. // Select templates
  137. if (preg_match('/^smartphone/',$conf->smart_menu) && ! empty($conf->browser->phone))
  138. {
  139. $template_dir = DOL_DOCUMENT_ROOT.'/theme/phones/smartphone/tpl/';
  140. }
  141. else
  142. {
  143. if (file_exists(DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/tpl/passwordforgotten.tpl.php"))
  144. {
  145. $template_dir = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/tpl/";
  146. }
  147. else
  148. {
  149. $template_dir = DOL_DOCUMENT_ROOT."/core/tpl/";
  150. }
  151. }
  152. $conf->css = "/theme/".$conf->theme."/style.css.php?lang=".$langs->defaultlang;
  153. $conf_css = DOL_URL_ROOT.$conf->css;
  154. $jquerytheme = 'smoothness';
  155. if (! empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
  156. if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_background.png'))
  157. {
  158. $login_background = DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_background.png';
  159. }
  160. else
  161. {
  162. $login_background = DOL_URL_ROOT.'/theme/login_background.png';
  163. }
  164. if (! $username) $focus_element = 'username';
  165. else $focus_element = 'password';
  166. // Send password button enabled ?
  167. $disabled='disabled';
  168. if (preg_match('/dolibarr/i',$mode)) $disabled='';
  169. if (! empty($conf->global->MAIN_SECURITY_ENABLE_SENDPASSWORD)) $disabled=''; // To force button enabled
  170. // Show logo (search in order: small company logo, large company logo, theme logo, common logo)
  171. $width=0;
  172. $rowspan=2;
  173. $urllogo=DOL_URL_ROOT.'/theme/login_logo.png';
  174. if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small))
  175. {
  176. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode('thumbs/'.$mysoc->logo_small);
  177. }
  178. elseif (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo))
  179. {
  180. $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode($mysoc->logo);
  181. $width=128;
  182. }
  183. elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/dolibarr_logo.png'))
  184. {
  185. $urllogo=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/dolibarr_logo.png';
  186. }
  187. elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.png'))
  188. {
  189. $urllogo=DOL_URL_ROOT.'/theme/dolibarr_logo.png';
  190. }
  191. // Security graphical code
  192. if (function_exists("imagecreatefrompng") && ! $disabled)
  193. {
  194. $captcha = 1;
  195. $captcha_refresh = img_picto($langs->trans("Refresh"),'refresh','id="captcha_refresh_img"');
  196. }
  197. // Execute hook getPasswordForgottenPageOptions
  198. // Should be an array with differents options in $hookmanager->resArray
  199. $parameters=array('entity' => GETPOST('entity','int'));
  200. $hookmanager->executeHooks('getPasswordForgottenPageOptions',$parameters); // Note that $action and $object may have been modified by some hooks
  201. include $template_dir.'passwordforgotten.tpl.php'; // To use native PHP
  202. ?>