1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Oinktube/objects/userRecoverPassSave.json.php
2022-03-17 11:43:59 -03:00

30 lines
1.1 KiB
PHP

<?php
header('Content-Type: application/json');
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/user.php';
$obj = new stdClass();
if (empty($_POST['user']) || empty($_POST['recoverPassword']) || empty($_POST['newPassword']) || empty($_POST['newPasswordConfirm'])) {
$obj->error = __("There is missing data to recover your password");
die(json_encode($obj));
}
$user = new User(0, $_POST['user'], false);
if (empty($user)) {
$obj->error = __("User not found");
die(json_encode($obj));
} elseif ($user->getRecoverPass() !== $_POST['recoverPassword']) {
$obj->error = __("Recover password does not match");
die(json_encode($obj));
} elseif ($_POST['newPassword'] !== $_POST['newPasswordConfirm']) {
$obj->error = __("Confirmation password does not match");
die(json_encode($obj));
} else {
$user->setPassword($_POST['newPassword']);
$user->setRecoverPass(true);
if ($user->save()) {
$obj->success = __("Your Password has been set");
die(json_encode($obj));
}
}