Files
SoonDesign/backend-web/src/Controllers/AuthController.php
T
24kycj 877fd278c2 Web 端数据交互与 design2 布局修复
统一门户 JSON 契约:新增 GET /templates/{id},模板/云文件/保存/打开走虚拟 key;
layer 保存弹层替代 prompt,本地 .soon 已登录后台 POST 登记;修复保存静默失败与 design2 全宽布局。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 01:20:34 +08:00

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Soon\Api\Controllers;
use Soon\Api\Core\Json;
use Soon\Api\Middleware\Auth;
use Soon\Api\Services\AuthService;
use Soon\Api\Services\MembershipService;
final class AuthController
{
public function register(): void
{
$body = Json::readBody();
$email = (string)($body['email'] ?? '');
$password = (string)($body['password'] ?? '');
Json::ok(AuthService::register($email, $password));
}
public function login(): void
{
$body = Json::readBody();
$email = (string)($body['email'] ?? '');
$password = (string)($body['password'] ?? '');
Json::ok(AuthService::login($email, $password));
}
public function refresh(): void
{
$body = Json::readBody();
$token = (string)($body['refresh_token'] ?? '');
if ($token === '') {
Json::fail('bad_request', '缺少 refresh_token', 400);
}
Json::ok(AuthService::refresh($token));
}
public function me(): void
{
$user = Auth::require();
Json::ok(array_merge($user, MembershipService::membershipSummary((int)$user['id'])));
}
}