|
|
@@ -1,7 +1,5 @@
|
|
|
import 'dart:async';
|
|
|
-import 'dart:io';
|
|
|
|
|
|
-import 'package:flutter/services.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:injectable/injectable.dart';
|
|
|
import 'package:keyboard/data/api/atmob_api.dart';
|
|
|
@@ -10,7 +8,6 @@ import 'package:keyboard/data/api/request/wechat_login_request.dart';
|
|
|
import 'package:keyboard/data/api/response/wechat_login_response.dart';
|
|
|
import 'package:keyboard/data/bean/member_info.dart';
|
|
|
import 'package:keyboard/data/repository/keyboard_repository.dart';
|
|
|
-import 'package:keyboard/utils/method_chanel_ios_util.dart';
|
|
|
|
|
|
import '../../base/app_base_request.dart';
|
|
|
import '../../di/get_it.dart';
|
|
|
@@ -43,11 +40,13 @@ class AccountRepository {
|
|
|
RxnString loginPhoneNum = RxnString();
|
|
|
final RxBool isLogin = false.obs;
|
|
|
|
|
|
+ final RxBool isRequest =false.obs;
|
|
|
+
|
|
|
Rxn<MemberInfo> memberStatusInfo = Rxn<MemberInfo>();
|
|
|
|
|
|
bool get isVipUser =>
|
|
|
memberStatusInfo.value != null &&
|
|
|
- memberStatusInfo.value!.isMember;
|
|
|
+ memberStatusInfo.value!.isMember;
|
|
|
|
|
|
int? _lastRequestCodeTime;
|
|
|
int _errorCodeTimes = 0;
|
|
|
@@ -59,7 +58,7 @@ class AccountRepository {
|
|
|
|
|
|
RxnString get tokenRxn => RxnString(token);
|
|
|
final KeyboardRepository keyboardRepository =
|
|
|
- KeyboardRepository.getInstance();
|
|
|
+ KeyboardRepository.getInstance();
|
|
|
|
|
|
AccountRepository(this.atmobApi) {
|
|
|
AtmobLog.d(tag, '$tag....init $hashCode');
|
|
|
@@ -78,15 +77,15 @@ class AccountRepository {
|
|
|
.loginSendCode(SendCodeRequest(phoneNum))
|
|
|
.then(HttpHandler.handle(true))
|
|
|
.then((value) {
|
|
|
- _lastRequestCodeTime = currentTime;
|
|
|
- _errorCodeTimes = 0;
|
|
|
- });
|
|
|
+ _lastRequestCodeTime = currentTime;
|
|
|
+ _errorCodeTimes = 0;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
Future<LoginResponse> loginUserLogin(
|
|
|
- String phoneNum,
|
|
|
- String verificationCode,
|
|
|
- ) {
|
|
|
+ String phoneNum,
|
|
|
+ String verificationCode,
|
|
|
+ ) {
|
|
|
if (_errorCodeTimes >= 5) {
|
|
|
throw LoginTooOftenException();
|
|
|
}
|
|
|
@@ -94,17 +93,17 @@ class AccountRepository {
|
|
|
.loginUserLogin(LoginRequest(phoneNum, verificationCode))
|
|
|
.then(HttpHandler.handle(true))
|
|
|
.then((response) {
|
|
|
- _errorCodeTimes = 0;
|
|
|
- onLoginSuccess(phoneNum, response.authToken);
|
|
|
- return response;
|
|
|
- })
|
|
|
+ _errorCodeTimes = 0;
|
|
|
+ onLoginSuccess(phoneNum, response.authToken);
|
|
|
+ return response;
|
|
|
+ })
|
|
|
.catchError((error) {
|
|
|
- if (error is ServerErrorException &&
|
|
|
- error.code == ErrorCode.verificationCodeError) {
|
|
|
- _errorCodeTimes++;
|
|
|
- }
|
|
|
- throw error;
|
|
|
- });
|
|
|
+ if (error is ServerErrorException &&
|
|
|
+ error.code == ErrorCode.verificationCodeError) {
|
|
|
+ _errorCodeTimes++;
|
|
|
+ }
|
|
|
+ throw error;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
Future<WechatLoginResponse> wechatLogin(String code) {
|
|
|
@@ -115,17 +114,17 @@ class AccountRepository {
|
|
|
.loginUserWechatLogin(WechatLoginRequest(code))
|
|
|
.then(HttpHandler.handle(true))
|
|
|
.then((response) {
|
|
|
- _errorCodeTimes = 0;
|
|
|
- onWechatLoginSuccess(response.authToken);
|
|
|
- return response;
|
|
|
- })
|
|
|
+ _errorCodeTimes = 0;
|
|
|
+ onWechatLoginSuccess(response.authToken);
|
|
|
+ return response;
|
|
|
+ })
|
|
|
.catchError((error) {
|
|
|
- if (error is ServerErrorException &&
|
|
|
- error.code == ErrorCode.verificationCodeError) {
|
|
|
- _errorCodeTimes++;
|
|
|
- }
|
|
|
- throw error;
|
|
|
- });
|
|
|
+ if (error is ServerErrorException &&
|
|
|
+ error.code == ErrorCode.verificationCodeError) {
|
|
|
+ _errorCodeTimes++;
|
|
|
+ }
|
|
|
+ throw error;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
Future<void> deprecateAccount() {
|
|
|
@@ -135,7 +134,7 @@ class AccountRepository {
|
|
|
void refreshUserInfo() {
|
|
|
userInfoFuture?.cancel();
|
|
|
userInfoFuture = AsyncUtil.retryWithExponentialBackoff(
|
|
|
- () => getUserInfo(),
|
|
|
+ () => getUserInfo(),
|
|
|
10,
|
|
|
predicate: (error) {
|
|
|
if (error is ServerErrorException) {
|
|
|
@@ -146,11 +145,11 @@ class AccountRepository {
|
|
|
);
|
|
|
userInfoFuture
|
|
|
?.then((userInfo) {
|
|
|
- AtmobLog.d(tag, "refreshUserInfo success: ${memberStatusInfo.value}");
|
|
|
- })
|
|
|
+ AtmobLog.d(tag, "refreshUserInfo success: ${memberStatusInfo.value}");
|
|
|
+ })
|
|
|
.catchError((error) {
|
|
|
- AtmobLog.e(tag, "refreshUserInfo error: $error");
|
|
|
- });
|
|
|
+ AtmobLog.e(tag, "refreshUserInfo error: $error");
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
Future<UserInfoResponse> getUserInfo() {
|
|
|
@@ -158,27 +157,31 @@ class AccountRepository {
|
|
|
.getUserInfo(AppBaseRequest())
|
|
|
.then(HttpHandler.handle(true))
|
|
|
.then((response) {
|
|
|
- _userInfo.value = response;
|
|
|
- if (response.loginStatus != null) {
|
|
|
- if (response.loginStatus == 1) {
|
|
|
- print("loginStatus == 1");
|
|
|
- isLogin.value = true;
|
|
|
- KVUtil.putBool(Constants.keyIsLogin, true);
|
|
|
- }
|
|
|
- if (response.loginStatus == 0) {
|
|
|
- print("loginStatus == 0");
|
|
|
- isLogin.value = false;
|
|
|
- }
|
|
|
- }
|
|
|
- memberStatusInfo.value = response.memberInfo;
|
|
|
- if (response.memberInfo != null) {
|
|
|
- KVUtil.putBool(
|
|
|
- Constants.keyIsMember,
|
|
|
- response.memberInfo!.isMember,
|
|
|
- );
|
|
|
- }
|
|
|
- return response;
|
|
|
- });
|
|
|
+ _userInfo.value = response;
|
|
|
+
|
|
|
+ if (response.loginStatus != null) {
|
|
|
+ if (response.loginStatus == 1) {
|
|
|
+ print("loginStatus == 1");
|
|
|
+ isLogin.value = true;
|
|
|
+ KVUtil.putBool(Constants.keyIsLogin, true);
|
|
|
+ }
|
|
|
+ if (response.loginStatus == 0) {
|
|
|
+ print("loginStatus == 0");
|
|
|
+ isLogin.value = false;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ memberStatusInfo.value = response.memberInfo;
|
|
|
+ if (response.memberInfo != null) {
|
|
|
+ KVUtil.putBool(
|
|
|
+ Constants.keyIsMember,
|
|
|
+ response.memberInfo!.isMember,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ isRequest.value = true;
|
|
|
+ return response;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
Future<void> setUserInfo({
|
|
|
@@ -191,22 +194,21 @@ class AccountRepository {
|
|
|
}) {
|
|
|
return atmobApi
|
|
|
.setUserInfo(
|
|
|
- UserInfoSettingRequest(
|
|
|
- name: name,
|
|
|
- birthday: birthday,
|
|
|
- gender: gender,
|
|
|
- imageUrl: imageUrl,
|
|
|
- hobbies: hobbies,
|
|
|
- characters: characters,
|
|
|
- ),
|
|
|
- )
|
|
|
+ UserInfoSettingRequest(
|
|
|
+ name: name,
|
|
|
+ birthday: birthday,
|
|
|
+ gender: gender,
|
|
|
+ imageUrl: imageUrl,
|
|
|
+ hobbies: hobbies,
|
|
|
+ characters: characters,
|
|
|
+ ),
|
|
|
+ )
|
|
|
.then(HttpHandler.handle(true));
|
|
|
}
|
|
|
|
|
|
void onLoginSuccess(String phoneNum, String authToken) {
|
|
|
GravityHelper.onLogin();
|
|
|
AccountRepository.token = authToken;
|
|
|
- MethodChanelIOSUtil.saveAuthToken(authToken);
|
|
|
loginPhoneNum.value = phoneNum;
|
|
|
refreshUserInfo();
|
|
|
KVUtil.putString(keyAccountLoginPhoneNum, phoneNum);
|
|
|
@@ -220,18 +222,17 @@ class AccountRepository {
|
|
|
|
|
|
void onWechatLoginSuccess(String authToken) {
|
|
|
AccountRepository.token = authToken;
|
|
|
- MethodChanelIOSUtil.saveAuthToken(authToken);
|
|
|
GravityHelper.onLogin();
|
|
|
refreshUserInfo();
|
|
|
KVUtil.putString(keyAccountLoginToken, authToken);
|
|
|
keyboardRepository.refreshData();
|
|
|
// 微信登录,通知键盘刷新数据
|
|
|
_notifyKeyboardPluginRefreshData();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void logout() {
|
|
|
token = null;
|
|
|
- MethodChanelIOSUtil.clearAuthToken();
|
|
|
KVUtil.putString(keyAccountLoginPhoneNum, null);
|
|
|
KVUtil.putString(keyAccountLoginToken, null);
|
|
|
memberStatusInfo.value = null;
|
|
|
@@ -245,6 +246,7 @@ class AccountRepository {
|
|
|
DailyLimiterUtil.clearDailyLimitData("SurpriseDialog");
|
|
|
// 退出登录,通知键盘刷新数据
|
|
|
_notifyKeyboardPluginRefreshData();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// 通知键盘刷新数据
|