e4e995854d
- 新增忘记密码页面与重置密码确认流程(前端+后端) - 修复注册验证码页登录跳转路由 - 新增用户搜索API(按邮箱查询) - 简化infra脚本,统一为app.sh - 补充密码重置与用户API测试覆盖 - 更新runtime文档与AGENTS配置
69 lines
1.9 KiB
Dart
69 lines
1.9 KiB
Dart
import 'package:social_app/core/api/api_client.dart';
|
|
import 'models/signup_request.dart';
|
|
import 'models/login_request.dart';
|
|
import 'models/auth_response.dart';
|
|
|
|
class AuthApi {
|
|
final ApiClient _client;
|
|
static const _prefix = '/api/v1/auth';
|
|
|
|
AuthApi(this._client);
|
|
|
|
Future<VerificationCreateResponse> createVerification(
|
|
SignupStartRequest request,
|
|
) async {
|
|
final response = await _client.post(
|
|
'$_prefix/verifications',
|
|
data: request.toJson(),
|
|
);
|
|
return VerificationCreateResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<AuthResponse> verifyVerification(SignupVerifyRequest request) async {
|
|
final response = await _client.post(
|
|
'$_prefix/verifications/verify',
|
|
data: request.toJson(),
|
|
);
|
|
return AuthResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<void> resendVerification(SignupResendRequest request) async {
|
|
await _client.post('$_prefix/verifications/resend', data: request.toJson());
|
|
}
|
|
|
|
Future<AuthResponse> createSession(LoginRequest request) async {
|
|
final response = await _client.post(
|
|
'$_prefix/sessions',
|
|
data: request.toJson(),
|
|
);
|
|
return AuthResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<AuthResponse> refreshSession(RefreshRequest request) async {
|
|
final response = await _client.post(
|
|
'$_prefix/sessions/refresh',
|
|
data: request.toJson(),
|
|
);
|
|
return AuthResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<void> deleteSession(LogoutRequest request) async {
|
|
await _client.delete('$_prefix/sessions', data: request.toJson());
|
|
}
|
|
|
|
Future<void> requestPasswordReset(String email) async {
|
|
await _client.post('$_prefix/password-reset', data: {'email': email});
|
|
}
|
|
|
|
Future<void> confirmPasswordReset({
|
|
required String email,
|
|
required String token,
|
|
required String newPassword,
|
|
}) async {
|
|
await _client.post(
|
|
'$_prefix/password-reset/confirm',
|
|
data: {'email': email, 'token': token, 'new_password': newPassword},
|
|
);
|
|
}
|
|
}
|