-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
refactor: login form #24347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alextran1502
wants to merge
1
commit into
main
Choose a base branch
from
refactor-login-form
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+655
−449
Open
refactor: login form #24347
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class OAuthLoginData { | ||
| final String serverUrl; | ||
| final String state; | ||
| final String codeVerifier; | ||
|
|
||
| const OAuthLoginData({required this.serverUrl, required this.state, required this.codeVerifier}); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,27 @@ | ||
| import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
| import 'package:immich_mobile/services/oauth.service.dart'; | ||
| import 'package:immich_mobile/models/auth/oauth_login_data.model.dart'; | ||
| import 'package:immich_mobile/providers/api.provider.dart'; | ||
| import 'package:immich_mobile/services/oauth.service.dart'; | ||
| import 'package:openapi/api.dart'; | ||
|
|
||
| export 'package:immich_mobile/models/auth/oauth_login_data.model.dart'; | ||
|
|
||
| final oAuthServiceProvider = Provider((ref) => OAuthService(ref.watch(apiServiceProvider))); | ||
|
|
||
| final oAuthProvider = StateNotifierProvider<OAuthNotifier, AsyncValue<void>>( | ||
| (ref) => OAuthNotifier(ref.watch(oAuthServiceProvider)), | ||
| ); | ||
|
|
||
| class OAuthNotifier extends StateNotifier<AsyncValue<void>> { | ||
| final OAuthService _oAuthService; | ||
|
|
||
| OAuthNotifier(this._oAuthService) : super(const AsyncValue.data(null)); | ||
|
|
||
| Future<OAuthLoginData?> getOAuthLoginData(String serverUrl) { | ||
| return _oAuthService.getOAuthLoginData(serverUrl); | ||
| } | ||
|
|
||
| Future<LoginResponseDto?> completeOAuthLogin(OAuthLoginData oAuthData) { | ||
| return _oAuthService.completeOAuthLogin(oAuthData); | ||
| } | ||
| } | ||
|
Comment on lines
+15
to
+27
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels redundant. We can access and use the |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
mobile/lib/widgets/forms/login/login_credentials_form.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import 'package:easy_localization/easy_localization.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:immich_mobile/extensions/build_context_extensions.dart'; | ||
| import 'package:immich_mobile/utils/url_helper.dart'; | ||
| import 'package:immich_mobile/widgets/forms/login/email_input.dart'; | ||
| import 'package:immich_mobile/widgets/forms/login/loading_icon.dart'; | ||
| import 'package:immich_mobile/widgets/forms/login/login_button.dart'; | ||
| import 'package:immich_mobile/widgets/forms/login/o_auth_login_button.dart'; | ||
| import 'package:immich_mobile/widgets/forms/login/password_input.dart'; | ||
| import 'package:immich_mobile/widgets/forms/login/version_compatibility_warning.dart'; | ||
|
|
||
| class LoginCredentialsForm extends StatelessWidget { | ||
| final TextEditingController emailController; | ||
| final TextEditingController passwordController; | ||
| final TextEditingController serverEndpointController; | ||
| final FocusNode emailFocusNode; | ||
| final FocusNode passwordFocusNode; | ||
| final bool isLoading; | ||
| final bool isOAuthEnabled; | ||
| final bool isPasswordLoginEnabled; | ||
| final String oAuthButtonLabel; | ||
| final String? warningMessage; | ||
| final VoidCallback onLogin; | ||
| final VoidCallback onOAuthLogin; | ||
| final VoidCallback onBack; | ||
|
|
||
| const LoginCredentialsForm({ | ||
| super.key, | ||
| required this.emailController, | ||
| required this.passwordController, | ||
| required this.serverEndpointController, | ||
| required this.emailFocusNode, | ||
| required this.passwordFocusNode, | ||
| required this.isLoading, | ||
| required this.isOAuthEnabled, | ||
| required this.isPasswordLoginEnabled, | ||
| required this.oAuthButtonLabel, | ||
| required this.warningMessage, | ||
| required this.onLogin, | ||
| required this.onOAuthLogin, | ||
| required this.onBack, | ||
| }); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return AutofillGroup( | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.stretch, | ||
| children: [ | ||
| if (warningMessage != null) VersionCompatibilityWarning(message: warningMessage!), | ||
| Text( | ||
| sanitizeUrl(serverEndpointController.text), | ||
| style: context.textTheme.displaySmall, | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| if (isPasswordLoginEnabled) ...[ | ||
| const SizedBox(height: 18), | ||
| EmailInput( | ||
| controller: emailController, | ||
| focusNode: emailFocusNode, | ||
| onSubmit: passwordFocusNode.requestFocus, | ||
| ), | ||
| const SizedBox(height: 8), | ||
| PasswordInput(controller: passwordController, focusNode: passwordFocusNode, onSubmit: onLogin), | ||
| ], | ||
| isLoading | ||
| ? const LoadingIcon() | ||
| : Column( | ||
| crossAxisAlignment: CrossAxisAlignment.stretch, | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: [ | ||
| const SizedBox(height: 18), | ||
| if (isPasswordLoginEnabled) LoginButton(onPressed: onLogin), | ||
| if (isOAuthEnabled) ...[ | ||
| if (isPasswordLoginEnabled) | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric(horizontal: 16.0), | ||
| child: Divider(color: context.isDarkTheme ? Colors.white : Colors.black), | ||
| ), | ||
| OAuthLoginButton( | ||
| serverEndpointController: serverEndpointController, | ||
| buttonLabel: oAuthButtonLabel, | ||
| onPressed: onOAuthLogin, | ||
| ), | ||
| ], | ||
| ], | ||
| ), | ||
| if (!isOAuthEnabled && !isPasswordLoginEnabled) Center(child: const Text('login_disabled').tr()), | ||
| const SizedBox(height: 12), | ||
| TextButton.icon(icon: const Icon(Icons.arrow_back), onPressed: onBack, label: const Text('back').tr()), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have
ServerInfoNotifierthat fetches and stores all the above params, are we moving away from using it?