|
...
|
...
|
@@ -13,6 +13,7 @@ import 'package:doublefeel_flutter/data/models/local/user_preferences.dart'; |
|
|
|
import 'package:doublefeel_flutter/l10n/gen/app_localizations.dart';
|
|
|
|
import 'package:doublefeel_flutter/l10n/l10n_extensions.dart';
|
|
|
|
import 'package:doublefeel_flutter/pigeon/platform_api.g.dart';
|
|
|
|
import 'package:doublefeel_flutter/pigeon/wechat_api.g.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
...
|
...
|
@@ -190,6 +191,26 @@ class LoginController extends GetxController { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onWechatLoginPressed() async {
|
|
|
|
if (!termsChecked.value &&
|
|
|
|
environmentConfig.region.value == AppRegion.china) {
|
|
|
|
AppToast.show(AppLocalizations.of(Get.context!)!.loginAgreeToTermsToast);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
final code = await LoadingService.instance.run(
|
|
|
|
() => WeChatHostApi().requestAuthorizationCode(),
|
|
|
|
type: LoadingType.circular,
|
|
|
|
);
|
|
|
|
if (code.isEmpty) return;
|
|
|
|
await _loginWithWechat(code);
|
|
|
|
} on PlatformException catch (e) {
|
|
|
|
AppToast.show(e.message?.isNotEmpty == true ? e.message! : '微信登录失败');
|
|
|
|
} catch (e) {
|
|
|
|
AppToast.show(e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDebugPressed() {
|
|
|
|
Get.toNamed(AppRoutes.debugEnvironment);
|
|
|
|
}
|
|
...
|
...
|
@@ -465,6 +486,22 @@ class LoginController extends GetxController { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loginWithWechat(String code) async {
|
|
|
|
isLoggingIn.value = true;
|
|
|
|
try {
|
|
|
|
await LoadingService.instance.run(() async {
|
|
|
|
final loginRes = await _userApi.loginWithWechat(code);
|
|
|
|
if (loginRes is AppSuccess<LoginResponse>) {
|
|
|
|
await _handleLoginSuccess(loginRes.data, wechatCode: code);
|
|
|
|
await Get.find<LocalStorage>().setLastLoginMethod('wechat');
|
|
|
|
await environmentConfig.updateHideChooseRegion(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
isLoggingIn.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loginWithGoogle(GoogleSignInModel googleModel) async {
|
|
|
|
isLoggingIn.value = true;
|
|
|
|
try {
|
|
...
|
...
|
@@ -486,10 +523,12 @@ class LoginController extends GetxController { |
|
|
|
Future<void> _handleLoginSuccess(LoginResponse loginData,
|
|
|
|
{AppleSignInModel? appleModel,
|
|
|
|
GoogleSignInModel? googleModel,
|
|
|
|
String? emailPassword}) async {
|
|
|
|
String? emailPassword,
|
|
|
|
String? wechatCode}) async {
|
|
|
|
bool isApple = appleModel != null;
|
|
|
|
bool isGoogle = googleModel != null;
|
|
|
|
bool isEmail = emailPassword != null;
|
|
|
|
bool isWechat = wechatCode != null;
|
|
|
|
final isRegister = loginData.isNewUser == true;
|
|
|
|
String accessToken = loginData.accessToken;
|
|
|
|
|
|
...
|
...
|
@@ -513,6 +552,11 @@ class LoginController extends GetxController { |
|
|
|
'email': emailInput.value.trim(),
|
|
|
|
'password': emailPassword,
|
|
|
|
};
|
|
|
|
} else if (isWechat) {
|
|
|
|
registerData = {
|
|
|
|
'login_type': 'wechat',
|
|
|
|
'wechat_code': wechatCode,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
registerData = {
|
|
|
|
'login_type': 'verification_code',
|
...
|
...
|
|