40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace kernel\modules\secure\services;
|
|
|
|
use kernel\FormModel;
|
|
use kernel\helpers\Debug;
|
|
use kernel\modules\secure\models\SecretCode;
|
|
use kernel\modules\user\models\User;
|
|
use kernel\modules\user\service\UserService;
|
|
|
|
class SecureService
|
|
{
|
|
|
|
public static function createSecretCode(User $user): void
|
|
{
|
|
$secretCode = new SecretCode();
|
|
$secretCode->user_id = $user->id;
|
|
$secretCode->code = mt_rand(100000, 999999);
|
|
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
|
$secretCode->save();
|
|
}
|
|
|
|
public static function updateSecretCode(User $user): void
|
|
{
|
|
$secretCode = SecretCode::where('user_id', $user->id)->first();
|
|
$secretCode->code = mt_rand(100000, 999999);
|
|
$secretCode->save();
|
|
}
|
|
|
|
public static function getCodeByUserId(int $user_id)
|
|
{
|
|
return SecretCode::where('user_id', $user_id)->one()->code;
|
|
}
|
|
|
|
public static function getByField(string $field, mixed $value)
|
|
{
|
|
return SecretCode::where($field, $value)->first();
|
|
}
|
|
|
|
} |