[+] добавлено логирование
This commit is contained in:
1 parent
d8370ae1f0
commit
1cc23d4eab
2 files changed
+27
-10
No files matched your search
@@ -22,6 +22,7 @@
|
|||||||
namespace Core\Helpers;
|
namespace Core\Helpers;
|
||||||
|
|
||||||
use Core\Models\User;
|
use Core\Models\User;
|
||||||
|
use Core\Helpers\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Класс для отправки E-mail
|
* Класс для отправки E-mail
|
||||||
@@ -188,6 +189,7 @@
|
|||||||
$res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
|
$res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::logToFile('Отправлено письмо', 'Mail.log', ['to' => $this->toEmail, 'subject' => $subject, 'body' => implode(' ', $message)]);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,9 +126,9 @@
|
|||||||
|
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,6 +191,16 @@
|
|||||||
return $this->getAllUserData() ? $this->getAllUserData()['id'] : null;
|
return $this->getAllUserData() ? $this->getAllUserData()['id'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получение кода верификации
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getVerificationCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->getAllUserData() ? $this->getAllUserData()['verification_code'] : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Получение всех пользователей панели
|
* Получение всех пользователей панели
|
||||||
*
|
*
|
||||||
@@ -222,7 +232,7 @@
|
|||||||
{
|
{
|
||||||
$newToken = self::generateGUID();
|
$newToken = self::generateGUID();
|
||||||
(DB::getInstance())->update(self::TABLE, ['id' => $this->id], ['token' => $newToken]);
|
(DB::getInstance())->update(self::TABLE, ['id' => $this->id], ['token' => $newToken]);
|
||||||
Log::logToFile('Создан токен ' . $newToken, 'User.log', ['userId' => $this->id]);
|
Log::logToFile('Создан токен', 'User.log', ['userId' => $this->id, 'token' => $newToken]);
|
||||||
return $newToken;
|
return $newToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +246,7 @@
|
|||||||
{
|
{
|
||||||
$uid = dechex(microtime(true) * 1000) . bin2hex(random_bytes(8));
|
$uid = dechex(microtime(true) * 1000) . bin2hex(random_bytes(8));
|
||||||
$guid = vsprintf('RG%s-1000-%s-8%.3s-%s%s%s0', str_split($uid, 4));
|
$guid = vsprintf('RG%s-1000-%s-8%.3s-%s%s%s0', str_split($uid, 4));
|
||||||
|
Log::logToFile('Сгенерирован GUID', 'User.log', ['GUID' => $guid]);
|
||||||
return strtoupper($guid);
|
return strtoupper($guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +390,7 @@
|
|||||||
Log::logToFile('Ошибка отправки кода верификации пользователю', 'User.log', func_get_args());
|
Log::logToFile('Ошибка отправки кода верификации пользователю', 'User.log', func_get_args());
|
||||||
throw new CoreException('Ошибка отправки кода верификации пользователю', CoreException::ERROR_SEND_VERIFICATION_CODE);
|
throw new CoreException('Ошибка отправки кода верификации пользователю', CoreException::ERROR_SEND_VERIFICATION_CODE);
|
||||||
}
|
}
|
||||||
|
Log::logToFile('Пользователь успешно создан', 'User.log', ['userId' => $userId]);
|
||||||
|
|
||||||
return $userId;
|
return $userId;
|
||||||
}
|
}
|
||||||
@@ -392,9 +404,9 @@
|
|||||||
/** @var $DB DB */
|
/** @var $DB DB */
|
||||||
$DB = DB::getInstance();
|
$DB = DB::getInstance();
|
||||||
Log::logToFile(
|
Log::logToFile(
|
||||||
'Изменение данных пользователя c ID ' . $this->id,
|
'Данные пользователя изменены',
|
||||||
'User.log',
|
'User.log',
|
||||||
['before' => $this->getAllUserData(), 'after' => func_get_args()]
|
['userId' => $this->id, 'before' => $this->getAllUserData(), 'after' => func_get_args()]
|
||||||
);
|
);
|
||||||
Cache::delete($cacheId);
|
Cache::delete($cacheId);
|
||||||
return $DB->update(self::TABLE, ['id' => $this->id], $fields);
|
return $DB->update(self::TABLE, ['id' => $this->id], $fields);
|
||||||
@@ -421,9 +433,9 @@
|
|||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -445,9 +457,9 @@
|
|||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return count($result);
|
return count($result);
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -677,8 +689,10 @@
|
|||||||
$res = $DB->getItem(self::TABLE, ['verification_code' => $verificationCode]);
|
$res = $DB->getItem(self::TABLE, ['verification_code' => $verificationCode]);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
(new self($res['id']))->update(['email_confirmed' => CODE_VALUE_Y]);
|
(new self($res['id']))->update(['email_confirmed' => CODE_VALUE_Y]);
|
||||||
|
Log::logToFile('E-Mail успешно верифицирован', 'User.log', ['userId' => $res['id'], 'code' => $verificationCode]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Log::logToFile('Ошибка верификации E-Mail', 'User.log', ['code' => $verificationCode]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,9 +703,10 @@
|
|||||||
*/
|
*/
|
||||||
public function sendVerificationCode(): void
|
public function sendVerificationCode(): void
|
||||||
{
|
{
|
||||||
|
Log::logToFile('Выслан код верификаци', 'User.log', ['userId' => $this->id, 'code' => $this->getAllUserData()['verification_code']]);
|
||||||
$this->getMailObject()
|
$this->getMailObject()
|
||||||
->setSubject('Подтверждение E-Mail')
|
->setSubject('Подтверждение E-Mail')
|
||||||
->setBody('Для подтверждения E-Mail перейдите по ссылке: ' . SITE_URL_CORE . '/verification.php?code=' . $this->getAllUserData()['verification_code'])
|
->setBody('Для подтверждения E-Mail перейдите по ссылке: ' . SITE_URL_CORE . '/verification.php?code=' . $this->getVerificationCode())
|
||||||
->send();
|
->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user