import 'package:isekai_wiki/api/response/userinfo.dart'; import '../response/mugenapp.dart'; import 'mw_api.dart'; class MWApiUser { static Future> 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> 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> 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 logout() async { try { await MWApi.post("logout", withToken: "csrf"); } on MWApiEmptyBodyException catch (_) { // 因为必定是空返回,忽略这个错误 } } }