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) {
|
|
|
|
$user = $db->getRow(
|
2017-05-22 07:49:05 +00:00
|
|
|
'SELECT email, active FROM account.user WHERE name = #',
|
2017-04-24 08:06:50 +00:00
|
|
|
[$_REQUEST['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;
|
|
|
|
|
|
|
|
$service = $this->service;
|
2018-05-23 10:14:20 +00:00
|
|
|
$token = $service->createToken($_REQUEST['recoverUser'], FALSE, TRUE);
|
|
|
|
$url = $service->getUrl() ."#!form=account/conf&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
|
|
|
|
2019-10-29 13:02:09 +00:00
|
|
|
return \Vn\Lib\Locale::get();
|
2016-10-13 15:07:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-09-06 14:25:02 +00:00
|
|
|
const LOWERS = 'abcdefghijklmnopqrstuvwxyz';
|
|
|
|
const UPPERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
const DIGITS = '1234567890';
|
|
|
|
const SYMBOLS = '!$%&()=.';
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function genPassword($db) {
|
|
|
|
$restrictions = $db->getRow(
|
2016-09-23 22:47:34 +00:00
|
|
|
'SELECT length, nUpper, nDigits, nPunct FROM account.userPassword');
|
2016-09-06 14:25:02 +00:00
|
|
|
|
|
|
|
$pass = [];
|
|
|
|
$newPass = '';
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$nAlpha = $restrictions['length'] -(
|
2016-09-23 22:47:34 +00:00
|
|
|
$restrictions['nUpper'] +
|
|
|
|
$restrictions['nDigits'] +
|
|
|
|
$restrictions['nPunct']);
|
2016-09-06 14:25:02 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$this->genRands($pass, self::LOWERS, $nAlpha);
|
|
|
|
$this->genRands($pass, self::UPPERS, $restrictions['nUpper']);
|
|
|
|
$this->genRands($pass, self::DIGITS, $restrictions['nDigits']);
|
|
|
|
$this->genRands($pass, self::SYMBOLS, $restrictions['nPunct']);
|
2016-09-06 14:25:02 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
for ($i = count($pass) - 1; $i >= 0; $i--) {
|
|
|
|
$rand = rand(0, $i);
|
2016-09-06 14:25:02 +00:00
|
|
|
$newPass .= $pass[$rand];
|
2018-05-23 10:14:20 +00:00
|
|
|
array_splice($pass, $rand, 1);
|
2016-09-06 14:25:02 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 15:07:48 +00:00
|
|
|
return $newPass;
|
2016-09-06 14:25:02 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function genRands(&$pass, $chars, $max) {
|
|
|
|
$len = strlen($chars) - 1;
|
2016-09-06 14:25:02 +00:00
|
|
|
|
|
|
|
for ($i = 0; $i < $max; $i++)
|
2018-05-23 10:14:20 +00:00
|
|
|
$pass[] = $chars[rand(0, $len)];
|
2016-09-06 14:25:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|