hedera-web/rest/user/recover-password.php

37 lines
829 B
PHP
Raw Permalink Normal View History

2016-09-06 14:25:02 +00:00
<?php
use Vn\Web;
2018-05-23 10:14:20 +00:00
class RecoverPassword extends Vn\Web\JsonRequest {
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]
);
2017-05-22 07:49:05 +00:00
if (!($user['active'] && $user['email']))
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]
);
$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";
2018-05-23 10:14:20 +00:00
$report = new Vn\Web\Report($db, 'recover-password', ['url' => $url]);
$report->sendMail($user['email']);
return TRUE;
}
2016-09-06 14:25:02 +00:00
}