120 lines
4.4 KiB
PHP
120 lines
4.4 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace User;
|
|||
|
|
|||
|
use Core\Config;
|
|||
|
use Core\Db;
|
|||
|
use Core\Mail;
|
|||
|
use UserIp;
|
|||
|
|
|||
|
class Confirmation
|
|||
|
{
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* @param array $userinfo <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> (User)->info.
|
|||
|
* @param mixed $value <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param ?int $code <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param string $type <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public static function byEmail(array $userinfo, string $type, $value, ?int $code = null)
|
|||
|
{
|
|||
|
if ($type === 'pass2' && is_null($code)) {
|
|||
|
self::pass2ByEmailCustom($userinfo, $value);
|
|||
|
return;
|
|||
|
}
|
|||
|
$ip = UserIp::get();
|
|||
|
$date = date('d.m.y H:i');
|
|||
|
$https = Config::get('https');
|
|||
|
$support = Config::get('support');
|
|||
|
$activationLink = 'https://' . $userinfo['city'] . Config::get('host') .
|
|||
|
"/confirm.php?id={$userinfo['id']}&code=$code";
|
|||
|
$fulllogin = $userinfo['login'] . "[{$userinfo['level']}]";
|
|||
|
Mail::send(
|
|||
|
$userinfo['mail'],
|
|||
|
<<<HTML
|
|||
|
<html lang="ru">
|
|||
|
<head><title><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $type</title></head>
|
|||
|
<body>
|
|||
|
$date<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>-<EFBFBD><EFBFBD> <EFBFBD> IP: $ip <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $type <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $fulllogin.<br>
|
|||
|
<EFBFBD>.<EFBFBD>. <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> email: {$userinfo['mail']}, <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<br>
|
|||
|
login: {$userinfo['login']}<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $type: <span style="background-color: wheat; font-family: Consolas, monospace;">$value</span><br><br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $type, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<br>
|
|||
|
$activationLink<br>
|
|||
|
<br>--<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> $https<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: $support<br>
|
|||
|
P.S. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
</body>
|
|||
|
</html>
|
|||
|
HTML,
|
|||
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $type <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $fulllogin"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
private static function pass2ByEmailCustom(array $userinfo, string $pass2)
|
|||
|
{
|
|||
|
|
|||
|
$ip = UserIp::get();
|
|||
|
$fulllogin = $userinfo['login'] . "[{$userinfo['level']}]";
|
|||
|
Mail::send(
|
|||
|
$userinfo['mail'],
|
|||
|
<<<HTML
|
|||
|
<html lang="ru">
|
|||
|
<head><title><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $fulllogin.</title></head>
|
|||
|
<body>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD> IP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - $ip, <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<br><br>
|
|||
|
------------------------------------------------------------------<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | {$userinfo['login']}<br>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ' . $pass2 . '<br>
|
|||
|
------------------------------------------------------------------<br>
|
|||
|
<br><br><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<br><br><i><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></i>
|
|||
|
</body>
|
|||
|
HTML,
|
|||
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> $fulllogin"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
public static function byCode(int $uid, int $code): string
|
|||
|
{
|
|||
|
$status = '';
|
|||
|
|
|||
|
if ($uid <= 0 || $code <= 0) {
|
|||
|
return $status;
|
|||
|
}
|
|||
|
|
|||
|
$codes = Db::getRow(
|
|||
|
'select * from emailconfirmation where id = ? and code = ? and (active = 1 or pass = 1 or email = 1)',
|
|||
|
[$uid, $code]
|
|||
|
);
|
|||
|
if (!$codes['id']) {
|
|||
|
$status = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!';
|
|||
|
} elseif ($codes['active'] === 1) {
|
|||
|
Db::sql(
|
|||
|
'update users set emailconfirmation = 1, securetime = unix_timestamp() + 259200 where id = ?',
|
|||
|
[$codes['id']]
|
|||
|
);
|
|||
|
$status = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/email <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
} elseif ($codes['pass'] === 1) {
|
|||
|
Db::sql(
|
|||
|
'update users as u inner join emailconfirmation as e on u.id = e.id set u.pass = e.pa_em, u.securetime = unix_timestamp() + 259200 where u.id = ?',
|
|||
|
[$codes['id']]
|
|||
|
);
|
|||
|
$status = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><";
|
|||
|
} elseif ($codes['email'] === 1) {
|
|||
|
Db::sql(
|
|||
|
'update users as u inner join emailconfirmation as e on u.id = e.id set u.mail = e.pa_em, u.securetime = unix_timestamp() + 259200 where u.id = ?',
|
|||
|
[$codes['id']]
|
|||
|
);
|
|||
|
$status = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> email";
|
|||
|
}
|
|||
|
Db::sql('delete from emailconfirmation where id = ? and code = ?', [$_GET['id'], $_GET['code']]);
|
|||
|
if ($status) {
|
|||
|
$status = "<h3>$status</h3>";
|
|||
|
}
|
|||
|
return $status;
|
|||
|
}
|
|||
|
}
|