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.
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
|
|
|
var mwRes = await MWApi.get("mugenapp", params: query);
|
|
|
|
|
|
|
|
var data = MugenAppStartAuthResponse.fromJson(mwRes.data);
|
|
|
|
|
|
|
|
return mwRes.replaceData(data.startauth);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<MWResponse<MugenAppAttemptAuthInfo>> attemptAuth(String loginRequestKey) async {
|
|
|
|
var query = {
|
|
|
|
"method": "attemptauth",
|
|
|
|
"requestkey": loginRequestKey,
|
|
|
|
};
|
|
|
|
|
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
|
|
|
var mwRes = await MWApi.get("query", params: query);
|
|
|
|
|
|
|
|
var data = MetaUserInfoResponse.fromJson(mwRes.data);
|
|
|
|
|
|
|
|
return mwRes.replaceData(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> logout() async {
|
|
|
|
try {
|
|
|
|
await MWApi.post("logout", withToken: "csrf");
|
|
|
|
} on MWApiEmptyBodyException catch (_) {
|
|
|
|
// 因为必定是空返回,忽略这个错误
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|