You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB
Dart

import 'package:isekai_wiki/api/response/userinfo.dart';
import '../response/mugenapp.dart';
import 'mw_api.dart';
class MWApiUser {
static Future<MWResponse<MugenAppStartAuthInfo>> startAuth() async {
var query = {
"method": "startauth",
};
2 years ago
var mwRes = await MWApi.get("mugenapp", params: query);
var data = MugenAppStartAuthResponse.fromJson(mwRes.data);
return mwRes.replaceData(data.startauth);
}
2 years ago
static Future<MWResponse<MugenAppAttemptAuthInfo>> attemptAuth(String loginRequestKey) async {
var query = {
"method": "attemptauth",
"requestkey": loginRequestKey,
};
2 years ago
var mwRes = await MWApi.get("mugenapp", params: query);
var data = MugenAppAttemptAuthResponse.fromJson(mwRes.data);
return mwRes.replaceData(data.attemptauth);
}
static Future<MWResponse<MetaUserInfoResponse>> getCurrentUserInfo() async {
var query = {
"meta": "userinfo|useravatar",
"uiprop": "blockinfo|groups|rights|options|email|realname|latestcontrib",
};
2 years ago
var mwRes = await MWApi.get("query", params: query);
var data = MetaUserInfoResponse.fromJson(mwRes.data);
return mwRes.replaceData(data);
}
2 years ago
static Future<void> logout() async {
try {
await MWApi.post("logout", withToken: "csrf");
} on MWApiEmptyBodyException catch (_) {
// 因为必定是空返回,忽略这个错误
}
}
}