forked from Cutlery/immich
		
	feat(mobile): render login fields/buttons based on server configuration (#3339)
* WIP: Show login fields/buttons based on server configuration * PR: change login disabled message to use translation * added localization string) * text --------- Co-authored-by: Alex Tran <Alex.Tran@conductix.com>
This commit is contained in:
		
							parent
							
								
									ed64c91da6
								
							
						
					
					
						commit
						baf1ea313e
					
				@ -186,6 +186,7 @@
 | 
				
			|||||||
  "login_form_save_login": "Stay logged in",
 | 
					  "login_form_save_login": "Stay logged in",
 | 
				
			||||||
  "login_form_server_empty": "Enter a server URL.",
 | 
					  "login_form_server_empty": "Enter a server URL.",
 | 
				
			||||||
  "login_form_server_error": "Could not connect to server.",
 | 
					  "login_form_server_error": "Could not connect to server.",
 | 
				
			||||||
 | 
					  "login_disabled": "Login has been disabled",
 | 
				
			||||||
  "monthly_title_text_date_format": "MMMM y",
 | 
					  "monthly_title_text_date_format": "MMMM y",
 | 
				
			||||||
  "motion_photos_page_title": "Motion Photos",
 | 
					  "motion_photos_page_title": "Motion Photos",
 | 
				
			||||||
  "notification_permission_dialog_cancel": "Cancel",
 | 
					  "notification_permission_dialog_cancel": "Cancel",
 | 
				
			||||||
 | 
				
			|||||||
@ -36,6 +36,7 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
    final isLoading = useState<bool>(false);
 | 
					    final isLoading = useState<bool>(false);
 | 
				
			||||||
    final isLoadingServer = useState<bool>(false);
 | 
					    final isLoadingServer = useState<bool>(false);
 | 
				
			||||||
    final isOauthEnable = useState<bool>(false);
 | 
					    final isOauthEnable = useState<bool>(false);
 | 
				
			||||||
 | 
					    final isPasswordLoginEnable = useState<bool>(false);
 | 
				
			||||||
    final oAuthButtonLabel = useState<String>('OAuth');
 | 
					    final oAuthButtonLabel = useState<String>('OAuth');
 | 
				
			||||||
    final logoAnimationController = useAnimationController(
 | 
					    final logoAnimationController = useAnimationController(
 | 
				
			||||||
      duration: const Duration(seconds: 60),
 | 
					      duration: const Duration(seconds: 60),
 | 
				
			||||||
@ -69,9 +70,11 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (loginConfig != null) {
 | 
					        if (loginConfig != null) {
 | 
				
			||||||
          isOauthEnable.value = loginConfig.enabled;
 | 
					          isOauthEnable.value = loginConfig.enabled;
 | 
				
			||||||
 | 
					          isPasswordLoginEnable.value = loginConfig.passwordLoginEnabled;
 | 
				
			||||||
          oAuthButtonLabel.value = loginConfig.buttonText ?? 'OAuth';
 | 
					          oAuthButtonLabel.value = loginConfig.buttonText ?? 'OAuth';
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          isOauthEnable.value = false;
 | 
					          isOauthEnable.value = false;
 | 
				
			||||||
 | 
					          isPasswordLoginEnable.value = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        serverEndpoint.value = endpoint;
 | 
					        serverEndpoint.value = endpoint;
 | 
				
			||||||
@ -82,6 +85,7 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
          toastType: ToastType.error,
 | 
					          toastType: ToastType.error,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        isOauthEnable.value = false;
 | 
					        isOauthEnable.value = false;
 | 
				
			||||||
 | 
					        isPasswordLoginEnable.value = true;
 | 
				
			||||||
        isLoadingServer.value = false;
 | 
					        isLoadingServer.value = false;
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
      } catch (e) {
 | 
					      } catch (e) {
 | 
				
			||||||
@ -91,6 +95,7 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
          toastType: ToastType.error,
 | 
					          toastType: ToastType.error,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        isOauthEnable.value = false;
 | 
					        isOauthEnable.value = false;
 | 
				
			||||||
 | 
					        isPasswordLoginEnable.value = true;
 | 
				
			||||||
        isLoadingServer.value = false;
 | 
					        isLoadingServer.value = false;
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -262,6 +267,7 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
              style: Theme.of(context).textTheme.displaySmall,
 | 
					              style: Theme.of(context).textTheme.displaySmall,
 | 
				
			||||||
              textAlign: TextAlign.center,
 | 
					              textAlign: TextAlign.center,
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            if (isPasswordLoginEnable.value) ...[
 | 
				
			||||||
              const SizedBox(height: 18),
 | 
					              const SizedBox(height: 18),
 | 
				
			||||||
              EmailInput(
 | 
					              EmailInput(
 | 
				
			||||||
                controller: usernameController,
 | 
					                controller: usernameController,
 | 
				
			||||||
@ -274,6 +280,7 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
                focusNode: passwordFocusNode,
 | 
					                focusNode: passwordFocusNode,
 | 
				
			||||||
                onSubmit: login,
 | 
					                onSubmit: login,
 | 
				
			||||||
              ),
 | 
					              ),
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Note: This used to have an AnimatedSwitcher, but was removed
 | 
					            // Note: This used to have an AnimatedSwitcher, but was removed
 | 
				
			||||||
            // because of https://github.com/flutter/flutter/issues/120874
 | 
					            // because of https://github.com/flutter/flutter/issues/120874
 | 
				
			||||||
@ -295,15 +302,17 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
                    mainAxisAlignment: MainAxisAlignment.center,
 | 
					                    mainAxisAlignment: MainAxisAlignment.center,
 | 
				
			||||||
                    children: [
 | 
					                    children: [
 | 
				
			||||||
                      const SizedBox(height: 18),
 | 
					                      const SizedBox(height: 18),
 | 
				
			||||||
 | 
					                      if (isPasswordLoginEnable.value)
 | 
				
			||||||
                        LoginButton(onPressed: login),
 | 
					                        LoginButton(onPressed: login),
 | 
				
			||||||
                      if (isOauthEnable.value) ...[
 | 
					                      if (isOauthEnable.value) ...[
 | 
				
			||||||
 | 
					                        if (isPasswordLoginEnable.value)
 | 
				
			||||||
                          Padding(
 | 
					                          Padding(
 | 
				
			||||||
                            padding: const EdgeInsets.symmetric(
 | 
					                            padding: const EdgeInsets.symmetric(
 | 
				
			||||||
                              horizontal: 16.0,
 | 
					                              horizontal: 16.0,
 | 
				
			||||||
                            ),
 | 
					                            ),
 | 
				
			||||||
                            child: Divider(
 | 
					                            child: Divider(
 | 
				
			||||||
                            color:
 | 
					                              color: Brightness.dark ==
 | 
				
			||||||
                                Brightness.dark == Theme.of(context).brightness
 | 
					                                      Theme.of(context).brightness
 | 
				
			||||||
                                  ? Colors.white
 | 
					                                  ? Colors.white
 | 
				
			||||||
                                  : Colors.black,
 | 
					                                  : Colors.black,
 | 
				
			||||||
                            ),
 | 
					                            ),
 | 
				
			||||||
@ -317,6 +326,10 @@ class LoginForm extends HookConsumerWidget {
 | 
				
			|||||||
                      ],
 | 
					                      ],
 | 
				
			||||||
                    ],
 | 
					                    ],
 | 
				
			||||||
                  ),
 | 
					                  ),
 | 
				
			||||||
 | 
					            if (!isOauthEnable.value && !isPasswordLoginEnable.value)
 | 
				
			||||||
 | 
					              Center(
 | 
				
			||||||
 | 
					                child: const Text('login_disabled').tr(),
 | 
				
			||||||
 | 
					              ),
 | 
				
			||||||
            const SizedBox(height: 12),
 | 
					            const SizedBox(height: 12),
 | 
				
			||||||
            TextButton.icon(
 | 
					            TextButton.icon(
 | 
				
			||||||
              icon: const Icon(Icons.arrow_back),
 | 
					              icon: const Icon(Icons.arrow_back),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user