changepassword.php 870 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. use App\MyUser;
  3. if (!isset($_SESSION['login'])){
  4. header('Location: signin');
  5. exit();
  6. }
  7. if (!isset($_POST['passwd'], $_POST['passwdconf'])) {
  8. header('Location: signin');
  9. exit();
  10. }
  11. if (empty($_POST['passwd']) || empty($_POST['passwdconf'])) {
  12. header('Location: signin');
  13. exit();
  14. }
  15. $passwd = htmlspecialchars($_POST['passwd']);
  16. $passwdconf = htmlspecialchars($_POST['passwdconf']);
  17. if ($passwd != $passwdconf) {
  18. header('Location: signin');
  19. exit();
  20. }
  21. try {
  22. $user = new MyUser($_SESSION['login'], $passwd);
  23. $user->changePassword();
  24. header('Location: welcome');
  25. exit();
  26. }
  27. catch (Exception $e) {
  28. $_SESSION['message'] = $e->getMessage();
  29. header('Location: signin');
  30. exit();
  31. }