2023-01-06 14:57:25 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace User;
|
|
|
|
|
|
|
|
|
|
use Core\Config;
|
|
|
|
|
use Core\Db;
|
2023-08-14 15:45:12 +00:00
|
|
|
|
use Helper\Mail;
|
2023-01-11 23:39:26 +00:00
|
|
|
|
use PassGen;
|
2023-01-06 14:57:25 +00:00
|
|
|
|
|
|
|
|
|
class Confirmation
|
|
|
|
|
{
|
|
|
|
|
/**
|
2023-01-10 16:29:32 +00:00
|
|
|
|
* Для однотипных писем с подтверждением.
|
2023-08-14 15:45:12 +00:00
|
|
|
|
* @param array $userinfo Данные из (User)->info.
|
2024-05-09 16:19:14 +00:00
|
|
|
|
* @param string $value Новое значение
|
2023-08-14 15:45:12 +00:00
|
|
|
|
* @param ?int $code Проверочный код
|
|
|
|
|
* @param string $type Тип меняемого значения. С маленькой буквы, именительный падеж.
|
2023-01-06 14:57:25 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2024-05-09 16:19:14 +00:00
|
|
|
|
public static function byEmail(array $userinfo, string $type, string $value, ?int $code = null): void
|
2023-01-06 14:57:25 +00:00
|
|
|
|
{
|
|
|
|
|
$ip = UserIp::get();
|
|
|
|
|
$date = date('d.m.y H:i');
|
|
|
|
|
$https = Config::get('https');
|
|
|
|
|
$support = Config::get('support');
|
2024-05-09 16:19:14 +00:00
|
|
|
|
$activationLink = Config::get('https') . "/confirm.php?id={$userinfo['id']}&code=$code";
|
2023-01-06 14:57:25 +00:00
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 16:19:14 +00:00
|
|
|
|
public static function userRegistrationCodeByEmail(string $email, string $login): void
|
2023-01-11 23:39:26 +00:00
|
|
|
|
{
|
|
|
|
|
$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
|
|
|
|
}
|