2023-01-06 14:57:25 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace User;
|
|
|
|
|
|
|
|
|
|
use Core\Config;
|
|
|
|
|
use Core\Db;
|
|
|
|
|
use Core\Mail;
|
2023-01-11 23:39:26 +00:00
|
|
|
|
use PassGen;
|
2023-01-06 14:57:25 +00:00
|
|
|
|
use UserIp;
|
|
|
|
|
|
|
|
|
|
class Confirmation
|
|
|
|
|
{
|
|
|
|
|
/**
|
2023-01-10 16:29:32 +00:00
|
|
|
|
* Для однотипных писем с подтверждением.
|
|
|
|
|
* @param array $userinfo Данные из (User)->info.
|
|
|
|
|
* @param mixed $value Новое значение
|
|
|
|
|
* @param ?int $code Проверочный код
|
|
|
|
|
* @param string $type Тип меняемого значения. С маленькой буквы, именительный падеж.
|
2023-01-06 14:57:25 +00:00
|
|
|
|
* @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">
|
2023-01-10 16:29:32 +00:00
|
|
|
|
<head><title>Сменить $type</title></head>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
<body>
|
|
|
|
|
$date<br>
|
2023-01-10 16:29:32 +00:00
|
|
|
|
Кто-то с IP: $ip пытается сменить $type к персонажу $fulllogin.<br>
|
|
|
|
|
Т.к. в анкете у этого персонажа указан email: {$userinfo['mail']}, то вы и получили это письмо.<br>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
login: {$userinfo['login']}<br>
|
2023-01-10 16:29:32 +00:00
|
|
|
|
Новый $type: <span style="background-color: wheat; font-family: Consolas, monospace;">$value</span><br><br>
|
|
|
|
|
Для того чтобы сменить $type, перейдите по ссылке:<br>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
$activationLink<br>
|
|
|
|
|
<br>--<br>
|
2023-01-10 16:29:32 +00:00
|
|
|
|
Бойцовский Клуб $https<br>
|
|
|
|
|
Администрация Бойцовского Клуба: $support<br>
|
|
|
|
|
P.S. Данное письмо сгенерировано автоматически, отвечать на него не нужно.
|
2023-01-06 14:57:25 +00:00
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
HTML,
|
2023-01-10 16:29:32 +00:00
|
|
|
|
"Смена $type у персонажа $fulllogin"
|
2023-01-06 14:57:25 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function pass2ByEmailCustom(array $userinfo, string $pass2)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$ip = UserIp::get();
|
|
|
|
|
$fulllogin = $userinfo['login'] . "[{$userinfo['level']}]";
|
|
|
|
|
Mail::send(
|
|
|
|
|
$userinfo['mail'],
|
|
|
|
|
<<<HTML
|
|
|
|
|
<html lang="ru">
|
2023-01-10 16:29:32 +00:00
|
|
|
|
<head><title>Второй пароль от персонажа $fulllogin.</title></head>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
<body>
|
2023-01-10 16:29:32 +00:00
|
|
|
|
Вами, с IP адреса - $ip, был установлен второй пароль в игре Бойцовский Клуб.<br>
|
|
|
|
|
Если это были не Вы, свяжитесь с администрацией сайта.<br><br>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
------------------------------------------------------------------<br>
|
2023-01-10 16:29:32 +00:00
|
|
|
|
Ваш логин | {$userinfo['login']}<br>
|
|
|
|
|
Второй пароль | ' . $pass2 . '<br>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
------------------------------------------------------------------<br>
|
2023-01-10 16:29:32 +00:00
|
|
|
|
<br><br>Желаем Вам приятной игры.<br><br><i>Администрация</i>
|
2023-01-06 14:57:25 +00:00
|
|
|
|
</body>
|
|
|
|
|
HTML,
|
2023-01-10 16:29:32 +00:00
|
|
|
|
"Второй пароль от персонажа $fulllogin"
|
2023-01-06 14:57:25 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 23:39:26 +00:00
|
|
|
|
public static function userRegistrationCodeByEmail(string $email, string $login)
|
|
|
|
|
{
|
|
|
|
|
$code = PassGen::intCode(4);
|
|
|
|
|
Db::sql('insert into secure_code (email, code, time) values (?,?,unix_timestamp())', [$email, $code]);
|
|
|
|
|
Mail::send(
|
|
|
|
|
$email,
|
|
|
|
|
'Секретный Код: ' . $code,
|
|
|
|
|
'Код подтверждения регистрации персонажа ' . $login
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:57:25 +00:00
|
|
|
|
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']) {
|
2023-01-10 16:29:32 +00:00
|
|
|
|
$status = 'Ссылка устарела!';
|
2023-01-06 14:57:25 +00:00
|
|
|
|
} elseif ($codes['active'] === 1) {
|
|
|
|
|
Db::sql(
|
|
|
|
|
'update users set emailconfirmation = 1, securetime = unix_timestamp() + 259200 where id = ?',
|
|
|
|
|
[$codes['id']]
|
|
|
|
|
);
|
2023-01-10 16:29:32 +00:00
|
|
|
|
$status = "Подтверждение смены пароля/email через почту включено";
|
2023-01-06 14:57:25 +00:00
|
|
|
|
} 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']]
|
|
|
|
|
);
|
2023-01-10 16:29:32 +00:00
|
|
|
|
$status = "Удачно сменили пароль<";
|
2023-01-06 14:57:25 +00:00
|
|
|
|
} 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']]
|
|
|
|
|
);
|
2023-01-10 16:29:32 +00:00
|
|
|
|
$status = "Удачно сменили email";
|
2023-01-06 14:57:25 +00:00
|
|
|
|
}
|
|
|
|
|
Db::sql('delete from emailconfirmation where id = ? and code = ?', [$_GET['id'], $_GET['code']]);
|
|
|
|
|
if ($status) {
|
|
|
|
|
$status = "<h3>$status</h3>";
|
|
|
|
|
}
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
2023-01-11 23:39:26 +00:00
|
|
|
|
}
|