<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include_once ($_SERVER['DOCUMENT_ROOT'] . '/_config/functions.php');
spl_autoload_register('my_autoload');
include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . '/Auth/chk.auth.php');

$headline                           = '<h3>Passwort ändern</h3>';
$site                               = $_SERVER["HTTP_REFERER"];
$sitePrevious                       = $_SERVER["HTTP_REFERER"];
$user                               = new user();


if($_SERVER["REQUEST_METHOD"]       == "POST") {
  $passwordRules                    = $user->checkPasswdComplexity($_POST['password'], 1, 8);
  
  if ($passwordRules                === false) {
    $errMsg                         = 'Das Passwort entspricht nicht den vogegebenen Regeln!';
    echo '<meta http-equiv="refresh" content="0; URL=' . HOME_DIR_HTML . TEMPLATE_DIR . '/users/error.php?err=' . urlencode($errMsg) . '">';
    exit();
  }
  
  $user->updateUserPw($_POST);
  echo '<meta http-equiv="refresh" content="0; URL=main.php">';
  //echo var_dump($_POST);
} else {
  
  $row                              = $user->getUserDataByUUID($_SESSION[ALLOW]);
  include($_SERVER['DOCUMENT_ROOT'] . HOME_DIR . TEMPLATE_DIR . '/Auth/change-pw.php');
}
