Files
plan_flutter/lib/api/endpoints/user_api.dart
zhutao 0231dcfe1a 1
2025-09-04 17:57:35 +08:00

79 lines
1.9 KiB
Dart

import 'package:dio/dio.dart';
import '../../data/models/other_login_type.dart';
import '../dto/login_dto.dart';
import '../network/request.dart';
///检查是否注册
Future<bool> checkRegisterApi(String email) async {
var res = await Request().post("/auth/email_check", {
"email": email,
});
if (res["next"] == "login") {
return true;
}
return false;
}
///邮箱密码登陆
Future<LoginDto> loginApi(String email, String password) async {
var res = await Request().post("/auth/login/account", {
"email": email,
"password": password,
});
return LoginDto.fromJson(res);
}
///注册处
Future<LoginDto> registerApi(String email, String password, String code) async {
var res = await Request().post("/auth/register", {
"email": email,
"password": password,
"email_code": code,
});
return LoginDto.fromJson(res);
}
///发送邮箱验证码
Future<void> sendEmailCodeApi(String email) async {
return Request().post("/send_email_code", {
"email": email,
});
}
///三方登录
Future<LoginDto> thirdLoginApi(String token, OtherLoginType type) async {
var res = await Request().post("/auth/login/oauth", {
"login_token": token,
"login_type": type.value,
});
return LoginDto.fromJson(res);
}
///删除账号
Future<void> deleteAccountApi() async {
return Request().get("/delete_account");
}
///修改用户资料
Future<UserInfo> updateUserInfoApi({
String? name,
List<int>? avatar,
String? description,
}) async {
FormData formData = FormData.fromMap({
"avatar": avatar != null
? MultipartFile.fromBytes(
avatar,
filename: "upload.jpg",
contentType: DioMediaType("image", "jpeg"),
)
: null,
"description": description,
"name": name,
});
//请求
var res = await Request().post("/user/update_profile", formData);
return UserInfo.fromJson(res);
}