model = new User(); } /** * @throws RandomException */ #[NoReturn] public function actionAuth(): void { $request = new Request(); $data = $request->post(); $model = $this->model->where('username', $data['username'])->first(); $res = []; if ($model) { if (password_verify($data["password"], $model->password_hash)) { $model->access_token_expires_at = date("Y-m-d H:i:s", strtotime(App::$secure['token_expired_time'])); $model->access_token = match (App::$secure['token_type']) { "JWT" => TokenService::JWT($_ENV['SECRET_KEY'], 'HS256'), "md5" => TokenService::md5(), "crypt" => TokenService::crypt(), "hash" => TokenService::hash('sha256'), default => TokenService::random_bytes(20), }; $res = [ "access_token" => $model->access_token, "access_token_expires_at" => $model->access_token_expires_at, ]; } $model->save(); } $this->renderApi($res); } // #[NoReturn] public function actionEmailAuth(): void // { // $request = new Request(); // $data = $request->post(); // $model = $this->model->where('email', $data['email'])->first(); // $res = []; // if ($model) { // if (password_verify($data["password"], $model->password_hash)) { // $model->access_token_expires_at = date("Y-m-d H:i:s", strtotime(App::$secure['token_expired_time'])); // $model->access_token = match (App::$secure['token_type']) { // "JWT" => TokenService::JWT($_ENV['SECRET_KEY'], 'HS256'), // "md5" => TokenService::md5(), // "crypt" => TokenService::crypt(), // "hash" => TokenService::hash('sha256'), // default => TokenService::random_bytes(20), // }; // // $res = [ // "access_token" => $model->access_token, // "access_token_expires_at" => $model->access_token_expires_at, // ]; // } // $model->save(); // } // // $this->renderApi($res); // } }