MicroFrameWork/kernel/modules/secure/controllers/SecureRestController.php

37 lines
944 B
PHP
Raw Normal View History

2024-10-17 16:47:04 +03:00
<?php
namespace kernel\modules\secure\controllers;
use JetBrains\PhpStorm\NoReturn;
use kernel\helpers\Debug;
use kernel\modules\user\models\User;
use kernel\Request;
use kernel\RestController;
class SecureRestController extends RestController
{
public function __construct()
{
$this->model = new User();
}
#[NoReturn] public function actionAuth(): void
{
$request = new Request();
$data = $request->post();
$model = $this->model->where(['username', $data['username']])->first();
$access_token = 123124312313;
$access_token_expires_at = time() + 3600;
$model->{'access_token'} = $access_token;
$model->{'access_token_expires_at'} = $access_token_expires_at;
foreach ($model->getFillable() as $item){
$model->{$item} = $data[$item] ?? null;
}
$model->save();
$this->renderApi($this->model->toArray());
}
}