完成基础的登录流程
parent
e4c942862e
commit
28d9d832c3
@ -0,0 +1,73 @@
|
|||||||
|
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", query: query);
|
||||||
|
|
||||||
|
if (!mwRes.ok) {
|
||||||
|
return MWResponse(errorList: mwRes.errorList);
|
||||||
|
}
|
||||||
|
if (mwRes.data != null) {
|
||||||
|
var authRes = MugenAppStartAuthResponse.fromJson(mwRes.data!);
|
||||||
|
|
||||||
|
return MWResponse(
|
||||||
|
ok: true, data: authRes.startauth, continueInfo: mwRes.continueInfo);
|
||||||
|
} else {
|
||||||
|
return MWResponse(
|
||||||
|
errorList: [MWError(code: 'response_data_empty', info: '加载的数据为空')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<MWResponse<MugenAppAttemptAuthInfo>> attemptAuth(
|
||||||
|
String loginRequestKey) async {
|
||||||
|
var query = {
|
||||||
|
"method": "attemptauth",
|
||||||
|
"requestkey": loginRequestKey,
|
||||||
|
};
|
||||||
|
|
||||||
|
var mwRes = await MWApi.get("mugenapp", query: query);
|
||||||
|
|
||||||
|
if (!mwRes.ok) {
|
||||||
|
return MWResponse(errorList: mwRes.errorList);
|
||||||
|
}
|
||||||
|
if (mwRes.data != null) {
|
||||||
|
var authRes = MugenAppAttemptAuthResponse.fromJson(mwRes.data!);
|
||||||
|
|
||||||
|
return MWResponse(
|
||||||
|
ok: true,
|
||||||
|
data: authRes.attemptauth,
|
||||||
|
continueInfo: mwRes.continueInfo);
|
||||||
|
} else {
|
||||||
|
return MWResponse(
|
||||||
|
errorList: [MWError(code: 'response_data_empty', info: '加载的数据为空')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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", query: query);
|
||||||
|
|
||||||
|
if (!mwRes.ok) {
|
||||||
|
return MWResponse(errorList: mwRes.errorList);
|
||||||
|
}
|
||||||
|
if (mwRes.data != null) {
|
||||||
|
var userInfoRes = MetaUserInfoResponse.fromJson(mwRes.data!);
|
||||||
|
|
||||||
|
return MWResponse(ok: true, data: userInfoRes);
|
||||||
|
} else {
|
||||||
|
return MWResponse(
|
||||||
|
errorList: [MWError(code: 'response_data_empty', info: '加载的数据为空')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'mugenapp.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MugenAppStartAuthInfo {
|
||||||
|
String loginUrl;
|
||||||
|
String loginRequestKey;
|
||||||
|
int ttl;
|
||||||
|
|
||||||
|
MugenAppStartAuthInfo({
|
||||||
|
required this.loginUrl,
|
||||||
|
required this.loginRequestKey,
|
||||||
|
this.ttl = 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MugenAppStartAuthInfo.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$MugenAppStartAuthInfoFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$MugenAppStartAuthInfoToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MugenAppStartAuthResponse {
|
||||||
|
MugenAppStartAuthInfo startauth;
|
||||||
|
|
||||||
|
MugenAppStartAuthResponse({required this.startauth});
|
||||||
|
|
||||||
|
factory MugenAppStartAuthResponse.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$MugenAppStartAuthResponseFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$MugenAppStartAuthResponseToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MugenAppAttemptAuthInfo {
|
||||||
|
String status;
|
||||||
|
int? userid;
|
||||||
|
String? username;
|
||||||
|
|
||||||
|
MugenAppAttemptAuthInfo({
|
||||||
|
required this.status,
|
||||||
|
this.userid,
|
||||||
|
this.username,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MugenAppAttemptAuthInfo.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$MugenAppAttemptAuthInfoFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$MugenAppAttemptAuthInfoToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MugenAppAttemptAuthResponse {
|
||||||
|
MugenAppAttemptAuthInfo attemptauth;
|
||||||
|
|
||||||
|
MugenAppAttemptAuthResponse({
|
||||||
|
required this.attemptauth,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MugenAppAttemptAuthResponse.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$MugenAppAttemptAuthResponseFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$MugenAppAttemptAuthResponseToJson(this);
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'mugenapp.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
MugenAppStartAuthInfo _$MugenAppStartAuthInfoFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
MugenAppStartAuthInfo(
|
||||||
|
loginUrl: json['loginUrl'] as String,
|
||||||
|
loginRequestKey: json['loginRequestKey'] as String,
|
||||||
|
ttl: json['ttl'] as int? ?? 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$MugenAppStartAuthInfoToJson(
|
||||||
|
MugenAppStartAuthInfo instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'loginUrl': instance.loginUrl,
|
||||||
|
'loginRequestKey': instance.loginRequestKey,
|
||||||
|
'ttl': instance.ttl,
|
||||||
|
};
|
||||||
|
|
||||||
|
MugenAppStartAuthResponse _$MugenAppStartAuthResponseFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
MugenAppStartAuthResponse(
|
||||||
|
startauth: MugenAppStartAuthInfo.fromJson(
|
||||||
|
json['startauth'] as Map<String, dynamic>),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$MugenAppStartAuthResponseToJson(
|
||||||
|
MugenAppStartAuthResponse instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'startauth': instance.startauth,
|
||||||
|
};
|
||||||
|
|
||||||
|
MugenAppAttemptAuthInfo _$MugenAppAttemptAuthInfoFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
MugenAppAttemptAuthInfo(
|
||||||
|
status: json['status'] as String,
|
||||||
|
userid: json['userid'] as int?,
|
||||||
|
username: json['username'] as String?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$MugenAppAttemptAuthInfoToJson(
|
||||||
|
MugenAppAttemptAuthInfo instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'status': instance.status,
|
||||||
|
'userid': instance.userid,
|
||||||
|
'username': instance.username,
|
||||||
|
};
|
||||||
|
|
||||||
|
MugenAppAttemptAuthResponse _$MugenAppAttemptAuthResponseFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
MugenAppAttemptAuthResponse(
|
||||||
|
attemptauth: MugenAppAttemptAuthInfo.fromJson(
|
||||||
|
json['attemptauth'] as Map<String, dynamic>),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$MugenAppAttemptAuthResponseToJson(
|
||||||
|
MugenAppAttemptAuthResponse instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'attemptauth': instance.attemptauth,
|
||||||
|
};
|
@ -0,0 +1,101 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'userinfo.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class UserGroupMembership {
|
||||||
|
String group;
|
||||||
|
String expiry;
|
||||||
|
|
||||||
|
UserGroupMembership({
|
||||||
|
required this.group,
|
||||||
|
required this.expiry,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory UserGroupMembership.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$UserGroupMembershipFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$UserGroupMembershipToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class UserAcceptLang {
|
||||||
|
double q;
|
||||||
|
|
||||||
|
@JsonKey(name: '*')
|
||||||
|
String langCode;
|
||||||
|
|
||||||
|
UserAcceptLang({
|
||||||
|
required this.q,
|
||||||
|
required this.langCode,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory UserAcceptLang.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$UserAcceptLangFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$UserAcceptLangToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MetaUserInfo {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
List<String>? groups;
|
||||||
|
List<UserGroupMembership>? groupmemberships;
|
||||||
|
List<String>? implicitgroups;
|
||||||
|
List<String>? rights;
|
||||||
|
Map<String, List<String>>? changeablegroups;
|
||||||
|
Map<String, dynamic>? options;
|
||||||
|
int? editcount;
|
||||||
|
String? realname;
|
||||||
|
String? email;
|
||||||
|
DateTime? emailauthenticated;
|
||||||
|
DateTime? registrationdate;
|
||||||
|
List<UserAcceptLang>? acceptlang;
|
||||||
|
int? unreadcount;
|
||||||
|
Map<String, int>? centralids;
|
||||||
|
Map<String, String>? attachedlocal;
|
||||||
|
DateTime? latestcontrib;
|
||||||
|
|
||||||
|
MetaUserInfo({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
this.groups,
|
||||||
|
this.groupmemberships,
|
||||||
|
this.implicitgroups,
|
||||||
|
this.rights,
|
||||||
|
this.changeablegroups,
|
||||||
|
this.options,
|
||||||
|
this.editcount,
|
||||||
|
this.realname,
|
||||||
|
this.email,
|
||||||
|
this.emailauthenticated,
|
||||||
|
this.registrationdate,
|
||||||
|
this.acceptlang,
|
||||||
|
this.unreadcount,
|
||||||
|
this.centralids,
|
||||||
|
this.attachedlocal,
|
||||||
|
this.latestcontrib,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MetaUserInfo.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$MetaUserInfoFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$MetaUserInfoToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MetaUserInfoResponse {
|
||||||
|
MetaUserInfo userinfo;
|
||||||
|
Map<int, String>? useravatar;
|
||||||
|
|
||||||
|
MetaUserInfoResponse({
|
||||||
|
required this.userinfo,
|
||||||
|
this.useravatar,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MetaUserInfoResponse.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$MetaUserInfoResponseFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$MetaUserInfoResponseToJson(this);
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'userinfo.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
UserGroupMembership _$UserGroupMembershipFromJson(Map<String, dynamic> json) =>
|
||||||
|
UserGroupMembership(
|
||||||
|
group: json['group'] as String,
|
||||||
|
expiry: json['expiry'] as String,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$UserGroupMembershipToJson(
|
||||||
|
UserGroupMembership instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'group': instance.group,
|
||||||
|
'expiry': instance.expiry,
|
||||||
|
};
|
||||||
|
|
||||||
|
UserAcceptLang _$UserAcceptLangFromJson(Map<String, dynamic> json) =>
|
||||||
|
UserAcceptLang(
|
||||||
|
q: (json['q'] as num).toDouble(),
|
||||||
|
langCode: json['*'] as String,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$UserAcceptLangToJson(UserAcceptLang instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'q': instance.q,
|
||||||
|
'*': instance.langCode,
|
||||||
|
};
|
||||||
|
|
||||||
|
MetaUserInfo _$MetaUserInfoFromJson(Map<String, dynamic> json) => MetaUserInfo(
|
||||||
|
id: json['id'] as int,
|
||||||
|
name: json['name'] as String,
|
||||||
|
groups:
|
||||||
|
(json['groups'] as List<dynamic>?)?.map((e) => e as String).toList(),
|
||||||
|
groupmemberships: (json['groupmemberships'] as List<dynamic>?)
|
||||||
|
?.map((e) => UserGroupMembership.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
implicitgroups: (json['implicitgroups'] as List<dynamic>?)
|
||||||
|
?.map((e) => e as String)
|
||||||
|
.toList(),
|
||||||
|
rights:
|
||||||
|
(json['rights'] as List<dynamic>?)?.map((e) => e as String).toList(),
|
||||||
|
changeablegroups:
|
||||||
|
(json['changeablegroups'] as Map<String, dynamic>?)?.map(
|
||||||
|
(k, e) =>
|
||||||
|
MapEntry(k, (e as List<dynamic>).map((e) => e as String).toList()),
|
||||||
|
),
|
||||||
|
options: json['options'] as Map<String, dynamic>?,
|
||||||
|
editcount: json['editcount'] as int?,
|
||||||
|
realname: json['realname'] as String?,
|
||||||
|
email: json['email'] as String?,
|
||||||
|
emailauthenticated: json['emailauthenticated'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['emailauthenticated'] as String),
|
||||||
|
registrationdate: json['registrationdate'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['registrationdate'] as String),
|
||||||
|
acceptlang: (json['acceptlang'] as List<dynamic>?)
|
||||||
|
?.map((e) => UserAcceptLang.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
unreadcount: json['unreadcount'] as int?,
|
||||||
|
centralids: (json['centralids'] as Map<String, dynamic>?)?.map(
|
||||||
|
(k, e) => MapEntry(k, e as int),
|
||||||
|
),
|
||||||
|
attachedlocal: (json['attachedlocal'] as Map<String, dynamic>?)?.map(
|
||||||
|
(k, e) => MapEntry(k, e as String),
|
||||||
|
),
|
||||||
|
latestcontrib: json['latestcontrib'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['latestcontrib'] as String),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$MetaUserInfoToJson(MetaUserInfo instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'id': instance.id,
|
||||||
|
'name': instance.name,
|
||||||
|
'groups': instance.groups,
|
||||||
|
'groupmemberships': instance.groupmemberships,
|
||||||
|
'implicitgroups': instance.implicitgroups,
|
||||||
|
'rights': instance.rights,
|
||||||
|
'changeablegroups': instance.changeablegroups,
|
||||||
|
'options': instance.options,
|
||||||
|
'editcount': instance.editcount,
|
||||||
|
'realname': instance.realname,
|
||||||
|
'email': instance.email,
|
||||||
|
'emailauthenticated': instance.emailauthenticated?.toIso8601String(),
|
||||||
|
'registrationdate': instance.registrationdate?.toIso8601String(),
|
||||||
|
'acceptlang': instance.acceptlang,
|
||||||
|
'unreadcount': instance.unreadcount,
|
||||||
|
'centralids': instance.centralids,
|
||||||
|
'attachedlocal': instance.attachedlocal,
|
||||||
|
'latestcontrib': instance.latestcontrib?.toIso8601String(),
|
||||||
|
};
|
||||||
|
|
||||||
|
MetaUserInfoResponse _$MetaUserInfoResponseFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
MetaUserInfoResponse(
|
||||||
|
userinfo: MetaUserInfo.fromJson(json['userinfo'] as Map<String, dynamic>),
|
||||||
|
useravatar: (json['useravatar'] as Map<String, dynamic>?)?.map(
|
||||||
|
(k, e) => MapEntry(int.parse(k), e as String),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$MetaUserInfoResponseToJson(
|
||||||
|
MetaUserInfoResponse instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'userinfo': instance.userinfo,
|
||||||
|
'useravatar':
|
||||||
|
instance.useravatar?.map((k, e) => MapEntry(k.toString(), e)),
|
||||||
|
};
|
Loading…
Reference in New Issue