877fd278c2
统一门户 JSON 契约:新增 GET /templates/{id},模板/云文件/保存/打开走虚拟 key;
layer 保存弹层替代 prompt,本地 .soon 已登录后台 POST 登记;修复保存静默失败与 design2 全宽布局。
Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.2 KiB
PHP
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'])));
|
|
}
|
|
}
|