2016-09-06 14:25:02 +00:00
|
|
|
<?php
|
|
|
|
|
2016-10-13 15:07:48 +00:00
|
|
|
use Vn\Web;
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
class RecoverPassword extends Vn\Web\JsonRequest {
|
2017-04-24 08:06:50 +00:00
|
|
|
const PARAMS = ['recoverUser'];
|
2016-09-06 14:25:02 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function run($db) {
|
2021-03-31 10:18:25 +00:00
|
|
|
$recoverUser = $_REQUEST['recoverUser'];
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$user = $db->getRow(
|
2017-05-22 07:49:05 +00:00
|
|
|
'SELECT email, active FROM account.user WHERE name = #',
|
2021-03-31 10:18:25 +00:00
|
|
|
[$recoverUser]
|
2016-10-13 15:07:48 +00:00
|
|
|
);
|
|
|
|
|
2017-05-22 07:49:05 +00:00
|
|
|
if (!($user['active'] && $user['email']))
|
2016-10-13 15:07:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2021-03-31 10:18:25 +00:00
|
|
|
$verificationToken = bin2hex(random_bytes(16));
|
|
|
|
$db->query(
|
|
|
|
'UPDATE account.user SET verificationToken = #
|
|
|
|
WHERE name = #',
|
|
|
|
[$verificationToken, $recoverUser]
|
|
|
|
);
|
|
|
|
|
2016-10-13 15:07:48 +00:00
|
|
|
$service = $this->service;
|
2021-03-31 10:18:25 +00:00
|
|
|
$token = $service->createToken($recoverUser);
|
|
|
|
$url = $service->getUrl() ."#!form=account/conf&verificationToken=$verificationToken&token=$token";
|
2016-10-13 15:07:48 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$report = new Vn\Web\Report($db, 'recover-password', ['url' => $url]);
|
|
|
|
$report->sendMail($user['email']);
|
2016-10-13 15:07:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-09-06 14:25:02 +00:00
|
|
|
}
|
|
|
|
|