注册问题修复
This commit is contained in:
parent
6a95763436
commit
fa516a94e1
@ -15,8 +15,10 @@ import 'package:yumi/app/constants/sc_screen.dart';
|
||||
import 'package:yumi/app/routes/sc_routes.dart';
|
||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||
import 'package:yumi/shared/tools/sc_date_utils.dart';
|
||||
import 'package:yumi/shared/tools/sc_google_auth_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||
import 'package:yumi/shared/data_sources/models/enum/sc_auth_type.dart';
|
||||
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
||||
import 'package:yumi/services/general/sc_app_general_manager.dart';
|
||||
import 'package:yumi/services/auth/user_profile_manager.dart';
|
||||
@ -612,16 +614,42 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
userProvider?.updateBornDay(birthdayDate.day);
|
||||
num age = DateTime.now().year - birthdayDate.year;
|
||||
userProvider?.updateAge(age.abs());
|
||||
String authType =
|
||||
Provider.of<SocialChatAuthenticationManager>(
|
||||
context,
|
||||
listen: false,
|
||||
).authType;
|
||||
String idToken =
|
||||
Provider.of<SocialChatAuthenticationManager>(
|
||||
context,
|
||||
listen: false,
|
||||
).uid;
|
||||
final authProvider = Provider.of<SocialChatAuthenticationManager>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
String authType = authProvider.authType.trim();
|
||||
String idToken = authProvider.uid.trim();
|
||||
if (authType.isEmpty || idToken.isEmpty) {
|
||||
final cachedAuthType = DataPersistence.getPendingChannelAuthType().trim();
|
||||
final cachedOpenId = DataPersistence.getPendingChannelAuthOpenId().trim();
|
||||
if (authType.isEmpty) {
|
||||
authType = cachedAuthType;
|
||||
}
|
||||
if (idToken.isEmpty) {
|
||||
idToken = cachedOpenId;
|
||||
}
|
||||
}
|
||||
if (authType.isEmpty || idToken.isEmpty) {
|
||||
try {
|
||||
final googleUser =
|
||||
SCGoogleAuthService.currentUser ??
|
||||
await SCGoogleAuthService.signInSilently();
|
||||
final googleUid = googleUser?.uid.trim() ?? "";
|
||||
if (googleUid.isNotEmpty) {
|
||||
authType = SCAuthType.GOOGLE.name;
|
||||
idToken = googleUid;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('resolve register auth failed: $e');
|
||||
}
|
||||
}
|
||||
if (authType.isEmpty || idToken.isEmpty) {
|
||||
SCLoadingManager.hide();
|
||||
SCTts.show("Please sign in again.");
|
||||
return;
|
||||
}
|
||||
await DataPersistence.setPendingChannelAuth(authType, idToken);
|
||||
final invitationCode = invitationCodeController.text.trim();
|
||||
SocialChatLoginRes user = await SCAccountRepository().regist(
|
||||
authType,
|
||||
@ -683,6 +711,7 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
return;
|
||||
}
|
||||
AccountStorage().setCurrentUser(user);
|
||||
await DataPersistence.clearPendingChannelAuth();
|
||||
userProvider?.syncCurrentUserProfile(user.userProfile);
|
||||
await DataPersistence.clearPendingRegisterRewardDialog();
|
||||
await DataPersistence.setAwaitRegisterRewardSocket(true);
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
@ -11,7 +10,6 @@ import 'package:provider/provider.dart';
|
||||
import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart';
|
||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||
import 'package:yumi/ui_kit/components/custom_cached_image.dart';
|
||||
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
|
||||
import 'package:yumi/shared/business_logic/models/res/country_res.dart';
|
||||
import 'package:yumi/services/general/sc_app_general_manager.dart';
|
||||
import 'package:yumi/services/auth/user_profile_manager.dart';
|
||||
@ -21,19 +19,17 @@ import '../../app/config/business_logic_strategy.dart';
|
||||
|
||||
///国家
|
||||
class CountryPage extends StatefulWidget {
|
||||
bool isDialog = false;
|
||||
final bool isDialog;
|
||||
|
||||
CountryPage({this.isDialog = false});
|
||||
const CountryPage({super.key, this.isDialog = false});
|
||||
|
||||
@override
|
||||
_CountryPageState createState() => _CountryPageState(isDialog);
|
||||
State<CountryPage> createState() => _CountryPageState();
|
||||
}
|
||||
|
||||
class _CountryPageState extends State<CountryPage> {
|
||||
bool isDialog = false;
|
||||
Country? selectCountryInfo;
|
||||
|
||||
_CountryPageState(this.isDialog);
|
||||
bool _didConfirmSelection = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -43,10 +39,12 @@ class _CountryPageState extends State<CountryPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Provider.of<SCAppGeneralManager>(
|
||||
context,
|
||||
listen: false,
|
||||
).clearCountrySelection();
|
||||
if (!_didConfirmSelection) {
|
||||
Provider.of<SCAppGeneralManager>(
|
||||
context,
|
||||
listen: false,
|
||||
).clearCountrySelection();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -98,6 +96,7 @@ class _CountryPageState extends State<CountryPage> {
|
||||
provider.updateCurrentCountry(
|
||||
selectCountryInfo,
|
||||
);
|
||||
_didConfirmSelection = true;
|
||||
SCNavigatorUtils.goBack(context);
|
||||
}
|
||||
},
|
||||
@ -159,6 +158,7 @@ class _CountryPageState extends State<CountryPage> {
|
||||
provider.updateCurrentCountry(
|
||||
selectCountryInfo,
|
||||
);
|
||||
_didConfirmSelection = true;
|
||||
SmartDialog.dismiss(tag: "showCountryPage");
|
||||
}
|
||||
},
|
||||
|
||||
@ -9,6 +9,7 @@ import 'package:yumi/app_localizations.dart';
|
||||
import 'package:yumi/shared/tools/sc_version_utils.dart';
|
||||
import 'package:yumi/shared/tools/sc_google_auth_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/models/enum/sc_auth_type.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
||||
@ -485,11 +486,13 @@ class _SplashPageState extends State<SplashPage> {
|
||||
if (uid.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
await DataPersistence.setPendingChannelAuth(SCAuthType.GOOGLE.name, uid);
|
||||
final user = await SCAccountRepository().loginForChannel(
|
||||
SCAuthType.GOOGLE.name,
|
||||
uid,
|
||||
);
|
||||
AccountStorage().setCurrentUser(user);
|
||||
await DataPersistence.clearPendingChannelAuth();
|
||||
return user;
|
||||
} catch (e) {
|
||||
debugPrint('restore login session failed: $e');
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
|
||||
import 'package:yumi/app/routes/sc_routes.dart';
|
||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||
import 'package:yumi/shared/tools/sc_google_auth_utils.dart';
|
||||
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
||||
import 'package:yumi/shared/tools/sc_version_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
||||
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
||||
@ -39,6 +39,11 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
|
||||
Future<void> _verifyExistingSession() async {
|
||||
final user = await SCGoogleAuthService.signInSilently();
|
||||
_user = user;
|
||||
if (user != null) {
|
||||
authType = SCAuthType.GOOGLE.name;
|
||||
uid = user.uid;
|
||||
await DataPersistence.setPendingChannelAuth(authType, uid);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@ -53,6 +58,7 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
|
||||
uid = _user!.uid;
|
||||
SCLoadingManager.show();
|
||||
if (uid.isNotEmpty) {
|
||||
await DataPersistence.setPendingChannelAuth(authType, uid);
|
||||
final res = await Future.wait([
|
||||
SCAccountRepository().loginForChannel(authType, uid),
|
||||
SCVersionUtils.checkReview(),
|
||||
@ -74,6 +80,10 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
AccountStorage().setCurrentUser(user);
|
||||
await DataPersistence.clearPendingChannelAuth();
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
SCLoadingManager.hide();
|
||||
notifyListeners();
|
||||
SCNavigatorUtils.push(context, SCRoutes.home, replace: true);
|
||||
@ -93,6 +103,7 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
|
||||
uid = appleCredential.userIdentifier ?? "";
|
||||
SCLoadingManager.show();
|
||||
if (uid.isNotEmpty) {
|
||||
await DataPersistence.setPendingChannelAuth(authType, uid);
|
||||
final res = await Future.wait([
|
||||
SCAccountRepository().loginForChannel(authType, uid),
|
||||
SCVersionUtils.checkReview(),
|
||||
@ -114,6 +125,10 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
AccountStorage().setCurrentUser(user);
|
||||
await DataPersistence.clearPendingChannelAuth();
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
SCLoadingManager.hide();
|
||||
notifyListeners();
|
||||
SCNavigatorUtils.push(context, SCRoutes.home, replace: true);
|
||||
@ -127,6 +142,7 @@ class SocialChatAuthenticationManager extends ChangeNotifier {
|
||||
|
||||
Future<void> logoutUser() async {
|
||||
await SCGoogleAuthService.signOut();
|
||||
await DataPersistence.clearPendingChannelAuth();
|
||||
_user = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@ -10,6 +10,9 @@ class DataPersistence {
|
||||
"await_register_reward_socket";
|
||||
static const String _pendingRegisterRewardDialogKey =
|
||||
"pending_register_reward_dialog";
|
||||
static const String _pendingChannelAuthTypeKey = "pending_channel_auth_type";
|
||||
static const String _pendingChannelAuthOpenIdKey =
|
||||
"pending_channel_auth_open_id";
|
||||
static SharedPreferences? _prefs;
|
||||
static bool _isInitialized = false;
|
||||
static Completer<void>? _initializationCompleter;
|
||||
@ -215,6 +218,31 @@ class DataPersistence {
|
||||
return await remove(_awaitRegisterRewardSocketKey);
|
||||
}
|
||||
|
||||
static Future<void> setPendingChannelAuth(
|
||||
String authType,
|
||||
String openId,
|
||||
) async {
|
||||
await Future.wait([
|
||||
setString(_pendingChannelAuthTypeKey, authType),
|
||||
setString(_pendingChannelAuthOpenIdKey, openId),
|
||||
]);
|
||||
}
|
||||
|
||||
static String getPendingChannelAuthType() {
|
||||
return getString(_pendingChannelAuthTypeKey);
|
||||
}
|
||||
|
||||
static String getPendingChannelAuthOpenId() {
|
||||
return getString(_pendingChannelAuthOpenIdKey);
|
||||
}
|
||||
|
||||
static Future<void> clearPendingChannelAuth() async {
|
||||
await Future.wait([
|
||||
remove(_pendingChannelAuthTypeKey),
|
||||
remove(_pendingChannelAuthOpenIdKey),
|
||||
]);
|
||||
}
|
||||
|
||||
///获取用户已经添加的房间音乐
|
||||
static String getUserRoomMusic() {
|
||||
final currentUser = AccountStorage().getCurrentUser()?.userProfile?.account;
|
||||
|
||||
@ -161,6 +161,7 @@ class AccountStorage {
|
||||
_currentUser = null;
|
||||
DataPersistence.setToken("");
|
||||
DataPersistence.setCurrentUser("");
|
||||
unawaited(DataPersistence.clearPendingChannelAuth());
|
||||
unawaited(DurableAuthStorage.clearSession());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user