mirror of
https://github.com/immich-app/immich.git
synced 2025-05-31 12:15:47 -04:00
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 <alex.tran1502@gmail.com>
This commit is contained in:
parent
f38c7a4b7e
commit
16183791f3
@ -13,9 +13,6 @@ class HiveSavedLoginInfo {
|
|||||||
@HiveField(2)
|
@HiveField(2)
|
||||||
String serverUrl;
|
String serverUrl;
|
||||||
|
|
||||||
@HiveField(3, defaultValue: false)
|
|
||||||
bool isSaveLogin;
|
|
||||||
|
|
||||||
@HiveField(4, defaultValue: "")
|
@HiveField(4, defaultValue: "")
|
||||||
String accessToken;
|
String accessToken;
|
||||||
|
|
||||||
@ -23,7 +20,6 @@ class HiveSavedLoginInfo {
|
|||||||
required this.email,
|
required this.email,
|
||||||
required this.password,
|
required this.password,
|
||||||
required this.serverUrl,
|
required this.serverUrl,
|
||||||
required this.isSaveLogin,
|
|
||||||
required this.accessToken,
|
required this.accessToken,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ class HiveSavedLoginInfoAdapter extends TypeAdapter<HiveSavedLoginInfo> {
|
|||||||
email: fields[0] as String,
|
email: fields[0] as String,
|
||||||
password: fields[1] as String,
|
password: fields[1] as String,
|
||||||
serverUrl: fields[2] as String,
|
serverUrl: fields[2] as String,
|
||||||
isSaveLogin: fields[3] == null ? false : fields[3] as bool,
|
|
||||||
accessToken: fields[4] == null ? '' : fields[4] as String,
|
accessToken: fields[4] == null ? '' : fields[4] as String,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -28,15 +27,13 @@ class HiveSavedLoginInfoAdapter extends TypeAdapter<HiveSavedLoginInfo> {
|
|||||||
@override
|
@override
|
||||||
void write(BinaryWriter writer, HiveSavedLoginInfo obj) {
|
void write(BinaryWriter writer, HiveSavedLoginInfo obj) {
|
||||||
writer
|
writer
|
||||||
..writeByte(5)
|
..writeByte(4)
|
||||||
..writeByte(0)
|
..writeByte(0)
|
||||||
..write(obj.email)
|
..write(obj.email)
|
||||||
..writeByte(1)
|
..writeByte(1)
|
||||||
..write(obj.password)
|
..write(obj.password)
|
||||||
..writeByte(2)
|
..writeByte(2)
|
||||||
..write(obj.serverUrl)
|
..write(obj.serverUrl)
|
||||||
..writeByte(3)
|
|
||||||
..write(obj.isSaveLogin)
|
|
||||||
..writeByte(4)
|
..writeByte(4)
|
||||||
..write(obj.accessToken);
|
..write(obj.accessToken);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,6 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
|||||||
String email,
|
String email,
|
||||||
String password,
|
String password,
|
||||||
String serverUrl,
|
String serverUrl,
|
||||||
bool isSavedLoginInfo,
|
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
// Resolve API server endpoint from user provided serverUrl
|
// Resolve API server endpoint from user provided serverUrl
|
||||||
@ -83,7 +82,6 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
|||||||
return setSuccessLoginInfo(
|
return setSuccessLoginInfo(
|
||||||
accessToken: loginResponse.accessToken,
|
accessToken: loginResponse.accessToken,
|
||||||
serverUrl: serverUrl,
|
serverUrl: serverUrl,
|
||||||
isSavedLoginInfo: isSavedLoginInfo,
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
HapticFeedback.vibrate();
|
HapticFeedback.vibrate();
|
||||||
@ -100,21 +98,9 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
|||||||
_assetCacheService.invalidate(),
|
_assetCacheService.invalidate(),
|
||||||
_albumCacheService.invalidate(),
|
_albumCacheService.invalidate(),
|
||||||
_sharedAlbumCacheService.invalidate(),
|
_sharedAlbumCacheService.invalidate(),
|
||||||
|
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).delete(savedLoginInfoKey)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Remove login info from local storage
|
|
||||||
var loginInfo =
|
|
||||||
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).get(savedLoginInfoKey);
|
|
||||||
if (loginInfo != null) {
|
|
||||||
loginInfo.email = "";
|
|
||||||
loginInfo.password = "";
|
|
||||||
loginInfo.isSaveLogin = false;
|
|
||||||
|
|
||||||
await Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).put(
|
|
||||||
savedLoginInfoKey,
|
|
||||||
loginInfo,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +142,6 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
|||||||
Future<bool> setSuccessLoginInfo({
|
Future<bool> setSuccessLoginInfo({
|
||||||
required String accessToken,
|
required String accessToken,
|
||||||
required String serverUrl,
|
required String serverUrl,
|
||||||
required bool isSavedLoginInfo,
|
|
||||||
}) async {
|
}) async {
|
||||||
_apiService.setAccessToken(accessToken);
|
_apiService.setAccessToken(accessToken);
|
||||||
var userResponseDto = await _apiService.userApi.getMyUserInfo();
|
var userResponseDto = await _apiService.userApi.getMyUserInfo();
|
||||||
@ -181,22 +166,16 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
|||||||
deviceType: deviceInfo["deviceType"],
|
deviceType: deviceInfo["deviceType"],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isSavedLoginInfo) {
|
|
||||||
// Save login info to local storage
|
// Save login info to local storage
|
||||||
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).put(
|
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).put(
|
||||||
savedLoginInfoKey,
|
savedLoginInfoKey,
|
||||||
HiveSavedLoginInfo(
|
HiveSavedLoginInfo(
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
isSaveLogin: true,
|
|
||||||
serverUrl: serverUrl,
|
serverUrl: serverUrl,
|
||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox)
|
|
||||||
.delete(savedLoginInfoKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register device info
|
// Register device info
|
||||||
|
@ -29,7 +29,6 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
useTextEditingController.fromValue(TextEditingValue.empty);
|
useTextEditingController.fromValue(TextEditingValue.empty);
|
||||||
final apiService = ref.watch(apiServiceProvider);
|
final apiService = ref.watch(apiServiceProvider);
|
||||||
final serverEndpointFocusNode = useFocusNode();
|
final serverEndpointFocusNode = useFocusNode();
|
||||||
final isSaveLoginInfo = useState<bool>(false);
|
|
||||||
final isLoading = useState<bool>(false);
|
final isLoading = useState<bool>(false);
|
||||||
final isOauthEnable = useState<bool>(false);
|
final isOauthEnable = useState<bool>(false);
|
||||||
final oAuthButtonLabel = useState<String>('OAuth');
|
final oAuthButtonLabel = useState<String>('OAuth');
|
||||||
@ -75,7 +74,6 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
usernameController.text = loginInfo.email;
|
usernameController.text = loginInfo.email;
|
||||||
passwordController.text = loginInfo.password;
|
passwordController.text = loginInfo.password;
|
||||||
serverEndpointController.text = loginInfo.serverUrl;
|
serverEndpointController.text = loginInfo.serverUrl;
|
||||||
isSaveLoginInfo.value = loginInfo.isSaveLogin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getServeLoginConfig();
|
getServeLoginConfig();
|
||||||
@ -88,7 +86,6 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
usernameController.text = 'testuser@email.com';
|
usernameController.text = 'testuser@email.com';
|
||||||
passwordController.text = 'password';
|
passwordController.text = 'password';
|
||||||
serverEndpointController.text = 'http://10.1.15.216:2283/api';
|
serverEndpointController.text = 'http://10.1.15.216:2283/api';
|
||||||
isSaveLoginInfo.value = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Center(
|
return Center(
|
||||||
@ -124,30 +121,6 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
controller: serverEndpointController,
|
controller: serverEndpointController,
|
||||||
focusNode: serverEndpointFocusNode,
|
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)
|
if (isLoading.value)
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 24,
|
width: 24,
|
||||||
@ -161,11 +134,11 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
const SizedBox(height: 18),
|
||||||
LoginButton(
|
LoginButton(
|
||||||
emailController: usernameController,
|
emailController: usernameController,
|
||||||
passwordController: passwordController,
|
passwordController: passwordController,
|
||||||
serverEndpointController: serverEndpointController,
|
serverEndpointController: serverEndpointController,
|
||||||
isSavedLoginInfo: isSaveLoginInfo.value,
|
|
||||||
),
|
),
|
||||||
if (isOauthEnable.value) ...[
|
if (isOauthEnable.value) ...[
|
||||||
Padding(
|
Padding(
|
||||||
@ -181,7 +154,6 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
OAuthLoginButton(
|
OAuthLoginButton(
|
||||||
serverEndpointController: serverEndpointController,
|
serverEndpointController: serverEndpointController,
|
||||||
isSavedLoginInfo: isSaveLoginInfo.value,
|
|
||||||
buttonLabel: oAuthButtonLabel.value,
|
buttonLabel: oAuthButtonLabel.value,
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
onLoginSuccess: () {
|
onLoginSuccess: () {
|
||||||
@ -304,14 +276,12 @@ class LoginButton extends ConsumerWidget {
|
|||||||
final TextEditingController emailController;
|
final TextEditingController emailController;
|
||||||
final TextEditingController passwordController;
|
final TextEditingController passwordController;
|
||||||
final TextEditingController serverEndpointController;
|
final TextEditingController serverEndpointController;
|
||||||
final bool isSavedLoginInfo;
|
|
||||||
|
|
||||||
const LoginButton({
|
const LoginButton({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.emailController,
|
required this.emailController,
|
||||||
required this.passwordController,
|
required this.passwordController,
|
||||||
required this.serverEndpointController,
|
required this.serverEndpointController,
|
||||||
required this.isSavedLoginInfo,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -329,7 +299,6 @@ class LoginButton extends ConsumerWidget {
|
|||||||
emailController.text,
|
emailController.text,
|
||||||
passwordController.text,
|
passwordController.text,
|
||||||
serverEndpointController.text,
|
serverEndpointController.text,
|
||||||
isSavedLoginInfo,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
@ -361,7 +330,6 @@ class LoginButton extends ConsumerWidget {
|
|||||||
|
|
||||||
class OAuthLoginButton extends ConsumerWidget {
|
class OAuthLoginButton extends ConsumerWidget {
|
||||||
final TextEditingController serverEndpointController;
|
final TextEditingController serverEndpointController;
|
||||||
final bool isSavedLoginInfo;
|
|
||||||
final ValueNotifier<bool> isLoading;
|
final ValueNotifier<bool> isLoading;
|
||||||
final VoidCallback onLoginSuccess;
|
final VoidCallback onLoginSuccess;
|
||||||
final String buttonLabel;
|
final String buttonLabel;
|
||||||
@ -369,7 +337,6 @@ class OAuthLoginButton extends ConsumerWidget {
|
|||||||
const OAuthLoginButton({
|
const OAuthLoginButton({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.serverEndpointController,
|
required this.serverEndpointController,
|
||||||
required this.isSavedLoginInfo,
|
|
||||||
required this.isLoading,
|
required this.isLoading,
|
||||||
required this.onLoginSuccess,
|
required this.onLoginSuccess,
|
||||||
required this.buttonLabel,
|
required this.buttonLabel,
|
||||||
@ -407,7 +374,6 @@ class OAuthLoginButton extends ConsumerWidget {
|
|||||||
.watch(authenticationProvider.notifier)
|
.watch(authenticationProvider.notifier)
|
||||||
.setSuccessLoginInfo(
|
.setSuccessLoginInfo(
|
||||||
accessToken: loginResponseDto.accessToken,
|
accessToken: loginResponseDto.accessToken,
|
||||||
isSavedLoginInfo: isSavedLoginInfo,
|
|
||||||
serverUrl: serverEndpointController.text,
|
serverUrl: serverEndpointController.text,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ class SplashScreenPage extends HookConsumerWidget {
|
|||||||
.read(authenticationProvider.notifier)
|
.read(authenticationProvider.notifier)
|
||||||
.setSuccessLoginInfo(
|
.setSuccessLoginInfo(
|
||||||
accessToken: loginInfo.accessToken,
|
accessToken: loginInfo.accessToken,
|
||||||
isSavedLoginInfo: true,
|
|
||||||
serverUrl: loginInfo.serverUrl,
|
serverUrl: loginInfo.serverUrl,
|
||||||
);
|
);
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
@ -47,7 +46,7 @@ class SplashScreenPage extends HookConsumerWidget {
|
|||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() {
|
() {
|
||||||
if (loginInfo?.isSaveLogin == true) {
|
if (loginInfo != null) {
|
||||||
performLoggingIn();
|
performLoggingIn();
|
||||||
} else {
|
} else {
|
||||||
AutoRouter.of(context).replace(const LoginRoute());
|
AutoRouter.of(context).replace(const LoginRoute());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user