From 16183791f3a5f7d389e8fe1da24085fdf4790b1c Mon Sep 17 00:00:00 2001 From: martyfuhry Date: Sun, 5 Feb 2023 09:07:02 -0500 Subject: [PATCH] feat(mobile): Removed stay logged in checkbox and made it enabled by default (#1550) * removed stay logged in checkbox and made it enabled by default * adds padding to login button * removed all isSaveLogin * fix: logout would re-login with previous credential upon app restart --------- Co-authored-by: Alex --- .../models/hive_saved_login_info.model.dart | 4 -- .../models/hive_saved_login_info.model.g.dart | Bin 1504 -> 1386 bytes .../providers/authentication.provider.dart | 43 +++++------------- mobile/lib/modules/login/ui/login_form.dart | 36 +-------------- mobile/lib/shared/views/splash_screen.dart | 3 +- 5 files changed, 13 insertions(+), 73 deletions(-) diff --git a/mobile/lib/modules/login/models/hive_saved_login_info.model.dart b/mobile/lib/modules/login/models/hive_saved_login_info.model.dart index e807fc4780..456dbadbf2 100644 --- a/mobile/lib/modules/login/models/hive_saved_login_info.model.dart +++ b/mobile/lib/modules/login/models/hive_saved_login_info.model.dart @@ -13,9 +13,6 @@ class HiveSavedLoginInfo { @HiveField(2) String serverUrl; - @HiveField(3, defaultValue: false) - bool isSaveLogin; - @HiveField(4, defaultValue: "") String accessToken; @@ -23,7 +20,6 @@ class HiveSavedLoginInfo { required this.email, required this.password, required this.serverUrl, - required this.isSaveLogin, required this.accessToken, }); } diff --git a/mobile/lib/modules/login/models/hive_saved_login_info.model.g.dart b/mobile/lib/modules/login/models/hive_saved_login_info.model.g.dart index 27c1d19672a7a6555ae8945b7533ba4713dc1bb9..c86ccdfa4d251dcfb26e323b808e4bfc3e1230ff 100644 GIT binary patch delta 24 gcmaFB{fcYDJEqA7%xflZV-cAAhI!iNZ7f=h0EmzY{{R30 delta 99 zcmaFG^?-ZBJ0`2l;^4%xRG<9x%seZFw9M3;l;UXPSOr^Kg}l<790hxYw8Wg^R0U+Y k#A1b{{QR8B&zQC_noge0yp+*+vLlNKH { String email, String password, String serverUrl, - bool isSavedLoginInfo, ) async { try { // Resolve API server endpoint from user provided serverUrl @@ -83,7 +82,6 @@ class AuthenticationNotifier extends StateNotifier { return setSuccessLoginInfo( accessToken: loginResponse.accessToken, serverUrl: serverUrl, - isSavedLoginInfo: isSavedLoginInfo, ); } catch (e) { HapticFeedback.vibrate(); @@ -100,21 +98,9 @@ class AuthenticationNotifier extends StateNotifier { _assetCacheService.invalidate(), _albumCacheService.invalidate(), _sharedAlbumCacheService.invalidate(), + Hive.box(hiveLoginInfoBox).delete(savedLoginInfoKey) ]); - // Remove login info from local storage - var loginInfo = - Hive.box(hiveLoginInfoBox).get(savedLoginInfoKey); - if (loginInfo != null) { - loginInfo.email = ""; - loginInfo.password = ""; - loginInfo.isSaveLogin = false; - - await Hive.box(hiveLoginInfoBox).put( - savedLoginInfoKey, - loginInfo, - ); - } return true; } @@ -156,7 +142,6 @@ class AuthenticationNotifier extends StateNotifier { Future setSuccessLoginInfo({ required String accessToken, required String serverUrl, - required bool isSavedLoginInfo, }) async { _apiService.setAccessToken(accessToken); var userResponseDto = await _apiService.userApi.getMyUserInfo(); @@ -181,22 +166,16 @@ class AuthenticationNotifier extends StateNotifier { deviceType: deviceInfo["deviceType"], ); - if (isSavedLoginInfo) { - // Save login info to local storage - Hive.box(hiveLoginInfoBox).put( - savedLoginInfoKey, - HiveSavedLoginInfo( - email: "", - password: "", - isSaveLogin: true, - serverUrl: serverUrl, - accessToken: accessToken, - ), - ); - } else { - Hive.box(hiveLoginInfoBox) - .delete(savedLoginInfoKey); - } + // Save login info to local storage + Hive.box(hiveLoginInfoBox).put( + savedLoginInfoKey, + HiveSavedLoginInfo( + email: "", + password: "", + serverUrl: serverUrl, + accessToken: accessToken, + ), + ); } // Register device info diff --git a/mobile/lib/modules/login/ui/login_form.dart b/mobile/lib/modules/login/ui/login_form.dart index b47e64bd0d..c834fc1543 100644 --- a/mobile/lib/modules/login/ui/login_form.dart +++ b/mobile/lib/modules/login/ui/login_form.dart @@ -29,7 +29,6 @@ class LoginForm extends HookConsumerWidget { useTextEditingController.fromValue(TextEditingValue.empty); final apiService = ref.watch(apiServiceProvider); final serverEndpointFocusNode = useFocusNode(); - final isSaveLoginInfo = useState(false); final isLoading = useState(false); final isOauthEnable = useState(false); final oAuthButtonLabel = useState('OAuth'); @@ -75,7 +74,6 @@ class LoginForm extends HookConsumerWidget { usernameController.text = loginInfo.email; passwordController.text = loginInfo.password; serverEndpointController.text = loginInfo.serverUrl; - isSaveLoginInfo.value = loginInfo.isSaveLogin; } getServeLoginConfig(); @@ -88,7 +86,6 @@ class LoginForm extends HookConsumerWidget { usernameController.text = 'testuser@email.com'; passwordController.text = 'password'; serverEndpointController.text = 'http://10.1.15.216:2283/api'; - isSaveLoginInfo.value = true; } return Center( @@ -124,30 +121,6 @@ class LoginForm extends HookConsumerWidget { controller: serverEndpointController, focusNode: serverEndpointFocusNode, ), - CheckboxListTile( - activeColor: Theme.of(context).primaryColor, - contentPadding: const EdgeInsets.symmetric(horizontal: 8), - dense: true, - side: const BorderSide(color: Colors.grey, width: 1.5), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5), - ), - enableFeedback: true, - title: const Text( - "login_form_save_login", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Colors.grey, - ), - ).tr(), - value: isSaveLoginInfo.value, - onChanged: (switchValue) { - if (switchValue != null) { - isSaveLoginInfo.value = switchValue; - } - }, - ), if (isLoading.value) const SizedBox( width: 24, @@ -161,11 +134,11 @@ class LoginForm extends HookConsumerWidget { crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.center, children: [ + const SizedBox(height: 18), LoginButton( emailController: usernameController, passwordController: passwordController, serverEndpointController: serverEndpointController, - isSavedLoginInfo: isSaveLoginInfo.value, ), if (isOauthEnable.value) ...[ Padding( @@ -181,7 +154,6 @@ class LoginForm extends HookConsumerWidget { ), OAuthLoginButton( serverEndpointController: serverEndpointController, - isSavedLoginInfo: isSaveLoginInfo.value, buttonLabel: oAuthButtonLabel.value, isLoading: isLoading, onLoginSuccess: () { @@ -304,14 +276,12 @@ class LoginButton extends ConsumerWidget { final TextEditingController emailController; final TextEditingController passwordController; final TextEditingController serverEndpointController; - final bool isSavedLoginInfo; const LoginButton({ Key? key, required this.emailController, required this.passwordController, required this.serverEndpointController, - required this.isSavedLoginInfo, }) : super(key: key); @override @@ -329,7 +299,6 @@ class LoginButton extends ConsumerWidget { emailController.text, passwordController.text, serverEndpointController.text, - isSavedLoginInfo, ); if (isAuthenticated) { @@ -361,7 +330,6 @@ class LoginButton extends ConsumerWidget { class OAuthLoginButton extends ConsumerWidget { final TextEditingController serverEndpointController; - final bool isSavedLoginInfo; final ValueNotifier isLoading; final VoidCallback onLoginSuccess; final String buttonLabel; @@ -369,7 +337,6 @@ class OAuthLoginButton extends ConsumerWidget { const OAuthLoginButton({ Key? key, required this.serverEndpointController, - required this.isSavedLoginInfo, required this.isLoading, required this.onLoginSuccess, required this.buttonLabel, @@ -407,7 +374,6 @@ class OAuthLoginButton extends ConsumerWidget { .watch(authenticationProvider.notifier) .setSuccessLoginInfo( accessToken: loginResponseDto.accessToken, - isSavedLoginInfo: isSavedLoginInfo, serverUrl: serverEndpointController.text, ); diff --git a/mobile/lib/shared/views/splash_screen.dart b/mobile/lib/shared/views/splash_screen.dart index 7aa973fcf6..f5ad5bb384 100644 --- a/mobile/lib/shared/views/splash_screen.dart +++ b/mobile/lib/shared/views/splash_screen.dart @@ -29,7 +29,6 @@ class SplashScreenPage extends HookConsumerWidget { .read(authenticationProvider.notifier) .setSuccessLoginInfo( accessToken: loginInfo.accessToken, - isSavedLoginInfo: true, serverUrl: loginInfo.serverUrl, ); if (isSuccess) { @@ -47,7 +46,7 @@ class SplashScreenPage extends HookConsumerWidget { useEffect( () { - if (loginInfo?.isSaveLogin == true) { + if (loginInfo != null) { performLoggingIn(); } else { AutoRouter.of(context).replace(const LoginRoute());