password.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at http://postfixadmin.sf.net
  10. *
  11. * @version $Id: password.php 1662 2014-04-27 19:18:14Z christian_boltz $
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: password.php
  15. * Used by users to change their mailbox (and login) password.
  16. * Template File: password.tpl
  17. *
  18. * Template Variables:
  19. *
  20. * none
  21. *
  22. * Form POST \ GET Variables:
  23. *
  24. * fPassword_current
  25. * fPassword
  26. * fPassword2
  27. */
  28. $rel_path = '../';
  29. require_once('../common.php');
  30. authentication_require_role('user');
  31. $username = authentication_get_username();
  32. $pPassword_password_text = "";
  33. $pPassword_password_current_text = "";
  34. if ($_SERVER['REQUEST_METHOD'] == "POST")
  35. {
  36. if(isset($_POST['fCancel'])) {
  37. header("Location: main.php");
  38. exit(0);
  39. }
  40. $fPassword_current = $_POST['fPassword_current'];
  41. $fPassword = $_POST['fPassword'];
  42. $fPassword2 = $_POST['fPassword2'];
  43. $error = 0;
  44. $validpass = validate_password($fPassword);
  45. if(count($validpass) > 0) {
  46. flash_error($validpass[0]); # TODO: honor all error messages, not only the first one
  47. $error += 1;
  48. }
  49. $mh = new MailboxHandler;
  50. if(!$mh->login($username, $fPassword_current)) {
  51. $error += 1;
  52. $pPassword_password_current_text = $PALANG['pPassword_password_current_text_error'];
  53. }
  54. if (empty ($fPassword) or ($fPassword != $fPassword2))
  55. {
  56. $error += 1;
  57. $pPassword_password_text = $PALANG['pPassword_password_text_error'];
  58. }
  59. if ($error == 0)
  60. {
  61. $mh->init($username); # TODO: error handling
  62. if($mh->change_pw($fPassword, $fPassword_current) ) {
  63. flash_info(Config::Lang_f('pPassword_result_success', $username));
  64. header("Location: main.php");
  65. exit(0);
  66. }
  67. else
  68. {
  69. flash_error(Config::Lang_f('pPassword_result_error', $username));
  70. }
  71. }
  72. }
  73. $smarty->assign ('SESSID_USERNAME', $username);
  74. $smarty->assign ('pPassword_password_current_text', $pPassword_password_current_text, false);
  75. $smarty->assign ('pPassword_password_text', $pPassword_password_text, false);
  76. $smarty->assign ('smarty_template', 'password');
  77. $smarty->display ('index.tpl');
  78. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  79. ?>