mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-30 01:41:05 +01:00
More cleanup on the auth screen
This commit is contained in:
@@ -155,7 +155,7 @@ class MainApp extends ConsumerWidget {
|
||||
switch (auth.status) {
|
||||
case AuthStatus.loggedIn:
|
||||
return const HomeTabsScreen();
|
||||
case AuthStatus.updateRequired:
|
||||
case AuthStatus.appUpdateRequired:
|
||||
return const UpdateAppScreen();
|
||||
case AuthStatus.serverUpdateRequired:
|
||||
return const UpdateServerScreen();
|
||||
|
||||
@@ -310,7 +310,7 @@ class AuthNotifier extends _$AuthNotifier {
|
||||
}
|
||||
|
||||
return switch (newState.status) {
|
||||
AuthStatus.serverUpdateRequired || AuthStatus.updateRequired => LoginActions.update,
|
||||
AuthStatus.serverUpdateRequired || AuthStatus.appUpdateRequired => LoginActions.update,
|
||||
_ => LoginActions.proceed,
|
||||
};
|
||||
}
|
||||
@@ -651,7 +651,7 @@ class AuthNotifier extends _$AuthNotifier {
|
||||
_logger.info('revalidation: app update required');
|
||||
state = AsyncData(
|
||||
current.copyWith(
|
||||
status: AuthStatus.updateRequired,
|
||||
status: AuthStatus.appUpdateRequired,
|
||||
serverVersion: serverVersion,
|
||||
),
|
||||
);
|
||||
@@ -750,7 +750,7 @@ class AuthNotifier extends _$AuthNotifier {
|
||||
}
|
||||
|
||||
if (await _applicationUpdateRequired(serverUrl, appVersion.version)) {
|
||||
return withStatus(AuthStatus.updateRequired, serverVersion);
|
||||
return withStatus(AuthStatus.appUpdateRequired, serverVersion);
|
||||
}
|
||||
|
||||
if (!await _isPowerSyncReachable(serverUrl, token, tokenType)) {
|
||||
|
||||
@@ -26,7 +26,7 @@ enum AuthStatus {
|
||||
loggedIn,
|
||||
|
||||
// The app used to connect to a wger instance is too old and must be updated
|
||||
updateRequired,
|
||||
appUpdateRequired,
|
||||
|
||||
// The wger server the app is configured to connect to is too old and must be updated
|
||||
serverUpdateRequired,
|
||||
|
||||
@@ -31,8 +31,6 @@ import 'package:wger/providers/auth_notifier.dart';
|
||||
import 'package:wger/providers/auth_state.dart';
|
||||
import 'package:wger/providers/network_provider.dart';
|
||||
import 'package:wger/screens/mfa_challenge_screen.dart';
|
||||
import 'package:wger/screens/update_app_screen.dart';
|
||||
import 'package:wger/screens/update_server_screen.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
import 'package:wger/widgets/auth/confirm_password_field.dart';
|
||||
import 'package:wger/widgets/auth/email_field.dart';
|
||||
@@ -116,8 +114,8 @@ class AuthCard extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
bool isObscure = true;
|
||||
Widget errorMessage = const SizedBox.shrink();
|
||||
WgerHttpException? _httpError;
|
||||
bool _showNetworkError = false;
|
||||
|
||||
final GlobalKey<FormState> _formKey = GlobalKey();
|
||||
AuthMode _authMode = AuthMode.login;
|
||||
@@ -190,7 +188,7 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
_refreshTokenController.clear();
|
||||
}
|
||||
|
||||
void _submit(BuildContext context) async {
|
||||
Future<void> _submit(BuildContext context) async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
@@ -226,22 +224,8 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
);
|
||||
}
|
||||
|
||||
// Navigate to the appropriate "update required" screen.
|
||||
if (res == LoginActions.update && mounted) {
|
||||
final status = ref.read(authProvider).value?.status;
|
||||
if (status == AuthStatus.updateRequired) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const UpdateAppScreen()),
|
||||
);
|
||||
return;
|
||||
} else if (status == AuthStatus.serverUpdateRequired) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const UpdateServerScreen()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// The "update required" screens are handled reactively by main.dart's
|
||||
// _getHomeScreen, which swaps the home screen on the auth status.
|
||||
if (context.mounted && res == LoginActions.proceed) {
|
||||
final showWarning = ref.read(authProvider).value?.serverConfigWarning ?? false;
|
||||
if (showWarning && context.mounted) {
|
||||
@@ -249,12 +233,6 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
ref.read(authProvider.notifier).clearServerConfigWarning();
|
||||
}
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} on MfaRequiredException catch (e) {
|
||||
if (context.mounted) {
|
||||
await Navigator.of(context).push(
|
||||
@@ -270,7 +248,8 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
} on WgerHttpException catch (error) {
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
errorMessage = FormHttpErrorsWidget(error);
|
||||
_httpError = error;
|
||||
_showNetworkError = false;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -278,14 +257,8 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
// friendly message instead of crashing to the red error screen.
|
||||
if (isNetworkError(error) && context.mounted) {
|
||||
setState(() {
|
||||
errorMessage = Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).errorCouldNotConnectToServer,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
);
|
||||
_showNetworkError = true;
|
||||
_httpError = null;
|
||||
});
|
||||
} else {
|
||||
rethrow;
|
||||
@@ -320,6 +293,20 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
// there is no connectivity.
|
||||
final isOnline = ref.watch(networkStatusProvider);
|
||||
|
||||
Widget errorMessage = const SizedBox.shrink();
|
||||
if (_httpError != null) {
|
||||
errorMessage = FormHttpErrorsWidget(_httpError!);
|
||||
} else if (_showNetworkError) {
|
||||
errorMessage = Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(
|
||||
i18n.errorCouldNotConnectToServer,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
@@ -385,7 +372,7 @@ class _AuthCardState extends ConsumerState<AuthCard> {
|
||||
onPressed: isOnline
|
||||
? () {
|
||||
if (!_isLoading) {
|
||||
return _submit(context);
|
||||
_submit(context);
|
||||
}
|
||||
}
|
||||
: null,
|
||||
|
||||
@@ -85,7 +85,7 @@ class _MfaChallengeScreenState extends ConsumerState<MfaChallengeScreen> {
|
||||
|
||||
if (res == LoginActions.update && mounted) {
|
||||
final status = ref.read(authProvider).value?.status;
|
||||
if (status == AuthStatus.updateRequired) {
|
||||
if (status == AuthStatus.appUpdateRequired) {
|
||||
await Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const UpdateAppScreen()),
|
||||
);
|
||||
|
||||
@@ -45,7 +45,7 @@ class EmailField extends StatelessWidget {
|
||||
return null;
|
||||
},
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s\b|\b\s')),
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s')),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class UsernameField extends StatelessWidget {
|
||||
return null;
|
||||
},
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s\b|\b\s')),
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s')),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user