Skip to content

Commit

Permalink
[RCF-69] Forgot Password functionality (#418)
Browse files Browse the repository at this point in the history
* forgot password implementation

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

* forgot password keycloak url integarted

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

* network component alignment issue

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

* RCF-69 fetching the value from configue properties

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

* RCF-69 fetching the value from configue properties

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

* RCF-69 review changes

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

* RCF-69 review changes

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>

---------

Signed-off-by: Sachin S P <sachin.sp@cyberpwn.com>
Co-authored-by: Sachin S P <sachin.sp@cyberpwn.com>
  • Loading branch information
SachinPremkumar and Sachin S P authored Jan 16, 2025
1 parent 61a6354 commit 269e4e6
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 42 deletions.
6 changes: 6 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<queries>
<!-- If your application checks for inAppBrowserView launch mode support -->
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ MachineDetailsApi getMachineDetailsApi(ClientCryptoManagerService clientCryptoMa
AuthenticationApi getAuthenticationApi(SyncRestService syncRestService,
SyncRestUtil syncRestFactory,
LoginService loginService,
AuditManagerService auditManagerService) {
AuditManagerService auditManagerService,GlobalParamRepository globalParamRepository) {
return new AuthenticationApi(appContext, syncRestService, syncRestFactory,
loginService, auditManagerService);
loginService, auditManagerService, globalParamRepository);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import io.mosip.registration.clientmanager.BuildConfig;
import io.mosip.registration.clientmanager.constant.AuditEvent;
import io.mosip.registration.clientmanager.constant.Components;
import io.mosip.registration.clientmanager.dto.http.ResponseWrapper;
import io.mosip.registration.clientmanager.dto.http.ServiceError;
import io.mosip.registration.clientmanager.exception.InvalidMachineSpecIDException;
import io.mosip.registration.clientmanager.repository.GlobalParamRepository;
import io.mosip.registration.clientmanager.service.LoginService;
import io.mosip.registration.clientmanager.spi.AuditManagerService;
import io.mosip.registration.clientmanager.spi.SyncRestService;
Expand All @@ -48,6 +50,7 @@ public class AuthenticationApi implements AuthResponsePigeon.AuthResponseApi {
LoginService loginService;
AuditManagerService auditManagerService;
SharedPreferences sharedPreferences;
GlobalParamRepository globalParamRepository;
public static final String IS_OFFICER = "is_officer";
public static final String IS_SUPERVISOR = "is_supervisor";
public static final String IS_DEFAULT = "is_default";
Expand All @@ -59,12 +62,13 @@ public class AuthenticationApi implements AuthResponsePigeon.AuthResponseApi {

@Inject
public AuthenticationApi(Context context, SyncRestService syncRestService, SyncRestUtil syncRestFactory,
LoginService loginService, AuditManagerService auditManagerService) {
LoginService loginService, AuditManagerService auditManagerService, GlobalParamRepository globalParamRepository) {
this.context = context;
this.syncRestService = syncRestService;
this.syncRestFactory = syncRestFactory;
this.loginService = loginService;
this.auditManagerService = auditManagerService;
this.globalParamRepository = globalParamRepository;
sharedPreferences = this.context.
getSharedPreferences(
this.context.getString(R.string.app_name),
Expand Down Expand Up @@ -232,4 +236,10 @@ public void stopAlarmService(@NonNull AuthResponsePigeon.Result<String> result)
}
result.success(resultString);
}

@Override
public void forgotPasswordUrl(@NonNull AuthResponsePigeon.Result<String> result) {
String response = this.globalParamRepository.getCachedStringForgotPassword();
result.success(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ public class RegistrationConstants {
public static final String SELECTED_HANDLES = "mosip.registration.default-selected-handle-fields";
public static final String TEMPLATE_IMPORTANT_GUIDELINES = "mosip.registration.important_guidelines";
public static final String PRE_REG_PACKET_LOCATION = "mosip.registration.registration_pre_reg_packet_location";
public static final String FORGOT_PASSWORD_URL = "mosip.registration.reset_password_url";
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,8 @@ public List<String> getSelectedHandles() {
.distinct()
.collect(Collectors.toList());
}

public String getCachedStringForgotPassword() {
return globalParamMap.get(RegistrationConstants.FORGOT_PASSWORD_URL);
}
}
7 changes: 5 additions & 2 deletions assets/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"next_button": "مقبل",
"password": "شعار",
"enter_password": "أدخل كلمة المرور",
"forgot_password": "نسيت كلمة المرور?",
"forgot_password": "هل نسيت كلمة السر؟",
"login_button": "تسجيل الدخول",
"back_button": "ظهر",
"user_validated": "تم التحقق من صحة المستخدم!",
Expand Down Expand Up @@ -307,5 +307,8 @@
"application_id_not_exist": "معرف التطبيق غير موجود!",
"correct_application_id": "يرجى التحقق من معرف التطبيق الذي تم إدخاله أو إدخال معرف صحيح ومحاولة جلبه مرة أخرى.",
"enter_application_id": "الرجاء إدخال معرف التطبيق",
"okay": "تمام"
"okay": "تمام",
"no_internet_connection": "لا يوجد اتصال بالإنترنت!",
"connect_and_retry": "يرجى الاتصال بالإنترنت وإعادة المحاولة.",
"retry": "إعادة المحاولة"
}
7 changes: 5 additions & 2 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"next_button": "NEXT",
"password": "Password",
"enter_password": "Enter Password",
"forgot_password": "Forgot Password?",
"forgot_password": "FORGOT PASSWORD?",
"login_button": "LOGIN",
"back_button": "BACK",
"user_validated": "User Validated!",
Expand Down Expand Up @@ -308,5 +308,8 @@
"application_id_not_exist": "Application ID does not exist!",
"correct_application_id": "Please check the entered Application ID or enter a correct ID and try to fetch it again.",
"enter_application_id": "Please Enter Application ID",
"okay": "OKAY"
"okay": "OKAY",
"no_internet_connection": "No Internet Connection!",
"connect_and_retry": "Please connect with internet and retry.",
"retry": "RETRY"
}
7 changes: 5 additions & 2 deletions assets/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"next_button": "PROCHAINE",
"password": "Mot de passe",
"enter_password": "Entrez le mot de passe",
"forgot_password": "Mot de passe oublié?",
"forgot_password": "MOT DE PASSE OUBLIÉ ?",
"login_button": "CONNECTEZ-VOUS",
"back_button": "PRÉCÉDENT",
"user_validated": "Utilisateur validé !",
Expand Down Expand Up @@ -307,5 +307,8 @@
"application_id_not_exist": "L'ID de l'application n'existe pas!",
"correct_application_id": "Veuillez vérifier l'ID d'application saisi ou saisir un ID correct et essayer de le récupérer à nouveau.",
"enter_application_id": "Veuillez saisir l'ID de la demande",
"okay": "D'ACCORD"
"okay": "D'ACCORD",
"no_internet_connection": "Pas de connexion Internet!",
"connect_and_retry": "Veuillez vous connecter à Internet et réessayer.",
"retry": "RECOMMENCEZ"
}
5 changes: 4 additions & 1 deletion assets/l10n/app_hi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,8 @@
"application_id_not_exist": "एप्लिकेशन आईडी मौजूद नहीं है!",
"correct_application_id": "कृपया दर्ज की गई एप्लिकेशन आईडी की जांच करें या सही आईडी दर्ज करें और इसे दोबारा लाने का प्रयास करें।",
"enter_application_id": "कृपया आवेदन आईडी दर्ज करें",
"okay": "ठीक है"
"okay": "ठीक है",
"no_internet_connection": "कोई इंटरनेट कनेक्शन नहीं!",
"connect_and_retry": "कृपया इंटरनेट से जुड़ें और पुनः प्रयास करें।",
"retry": "पुन: प्रयास"
}
7 changes: 5 additions & 2 deletions assets/l10n/app_kn.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"next_button": "ಮುಂದೆ",
"password": "ಪಾಸ್ ವರ್ಡ್",
"enter_password": "ಪಾಸ್ ವರ್ಡ್ ನಮೂದಿಸಿ",
"forgot_password": "ಪಾಸ್ ವರ್ಡ್ ಮರೆತಿದ್ದೀರಾ?",
"forgot_password": "ಪಾಸ್ವರ್ಡ್ ಮರೆತಿರುವಿರಾ?",
"login_button": "ಲಾಗಿನ್",
"back_button": "ಹಿಂದೆ",
"user_validated": "ಬಳಕೆದಾರ ಮೌಲ್ಯೀಕರಿಸಲಾಗಿದೆ!",
Expand Down Expand Up @@ -307,5 +307,8 @@
"application_id_not_exist": "ಅಪ್ಲಿಕೇಶನ್ ಐಡಿ ಅಸ್ತಿತ್ವದಲ್ಲಿಲ್ಲ!",
"correct_application_id": "ದಯವಿಟ್ಟು ನಮೂದಿಸಿದ ಅಪ್ಲಿಕೇಶನ್ ಐಡಿಯನ್ನು ಪರಿಶೀಲಿಸಿ ಅಥವಾ ಸರಿಯಾದ ಐಡಿಯನ್ನು ನಮೂದಿಸಿ ಮತ್ತು ಅದನ್ನು ಮತ್ತೆ ಪಡೆಯಲು ಪ್ರಯತ್ನಿಸಿ.",
"enter_application_id": "ದಯವಿಟ್ಟು ಅಪ್ಲಿಕೇಶನ್ ಐಡಿಯನ್ನು ನಮೂದಿಸಿ",
"okay": "ಸರಿ"
"okay": "ಸರಿ",
"no_internet_connection": "ಇಂಟರ್ನೆಟ್ ಸಂಪರ್ಕವಿಲ್ಲ!",
"connect_and_retry": "ದಯವಿಟ್ಟು ಇಂಟರ್ನೆಟ್\u200Cನೊಂದಿಗೆ ಸಂಪರ್ಕಿಸಿ ಮತ್ತು ಮರುಪ್ರಯತ್ನಿಸಿ.",
"retry": "ಮರುಪ್ರಯತ್ನಿಸಿ"
}
7 changes: 5 additions & 2 deletions assets/l10n/app_ta.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"next_button": "அடுத்தவர்",
"password": "அடையாளச் சொல்",
"enter_password": "கடவுச்சொல்லை உள்ளிடவும்",
"forgot_password": "கடவுச்சொல் மறந்துவிட்டதா?",
"forgot_password": "கடவுச்சொல்லை மறந்துவிட்டீர்களா?",
"login_button": "உள்நுழைவு",
"back_button": "முதுகு",
"user_validated": "பயனர் சரிபார்க்கப்பட்டது!",
Expand Down Expand Up @@ -316,5 +316,8 @@
"application_id_not_exist": "விண்ணப்ப ஐடி இல்லை",
"correct_application_id": "உள்ளிட்ட விண்ணப்ப ஐடியைச் சரிபார்க்கவும் அல்லது சரியான ஐடியை உள்ளிட்டு, அதை மீண்டும் பெற முயற்சிக்கவும்.",
"enter_application_id": "விண்ணப்ப ஐடியை உள்ளிடவும்",
"okay": "சரி"
"okay": "சரி",
"no_internet_connection": "இணைய இணைப்பு இல்லை!",
"connect_and_retry": "இணையத்துடன் இணைத்து மீண்டும் முயற்சிக்கவும்.",
"retry": "மீண்டும் முயற்சிக்கவும்"
}
7 changes: 7 additions & 0 deletions assets/svg/No internet connection.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions lib/platform_android/auth_service_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ class AuthServiceImpl implements AuthService {
return stopAlarmServiceResponse;
}

@override
Future<String> forgotPasswordUrl() async{
late String forgotPasswordResponse;
try {
forgotPasswordResponse = await AuthResponseApi().forgotPasswordUrl();
} on PlatformException {
debugPrint('forgotPassword call failed!');
} catch (e) {
debugPrint(e.toString());
}
return forgotPasswordResponse;
}


}

Expand Down
2 changes: 2 additions & 0 deletions lib/platform_spi/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ abstract class AuthService {

Future<String> stopAlarmService();

Future<String> forgotPasswordUrl();

factory AuthService() => getAuthServiceImpl();
}
16 changes: 16 additions & 0 deletions lib/provider/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class AuthProvider with ChangeNotifier {
String _userId = "";
String _username = "";
String _userEmail = "";
bool _isNetworkPresent = false;
String _forgotPasswordUrl = "";

bool get isLoggedIn => _isLoggedIn;
bool get isSyncing => _isSyncing;
Expand All @@ -49,6 +51,8 @@ class AuthProvider with ChangeNotifier {
String get userId => _userId;
String get username => _username;
String get userEmail => _userEmail;
bool get isNetworkPresent => _isNetworkPresent;
String get forgotPasswordUrl => _forgotPasswordUrl;

setIsLoggedIn(bool value) {
_isLoggedIn = value;
Expand Down Expand Up @@ -207,4 +211,16 @@ class AuthProvider with ChangeNotifier {

notifyListeners();
}

setIsNetworkPresent(bool value){
_isNetworkPresent = value;
notifyListeners();
}

getForgotPasswordUrl() async {
String forgotPasswordUrl = await auth.forgotPasswordUrl();
_forgotPasswordUrl = forgotPasswordUrl;
notifyListeners();
}

}
61 changes: 50 additions & 11 deletions lib/ui/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:registration_client/pigeon/user_pigeon.dart';
import 'package:registration_client/provider/auth_provider.dart';
import 'package:registration_client/provider/sync_provider.dart';
import 'package:registration_client/ui/dashboard/dashboard_tablet.dart';
import 'package:registration_client/ui/widgets/network_component.dart';
import 'package:registration_client/ui/widgets/sync_alert_dialog.dart';
import 'package:registration_client/utils/app_style.dart';
import 'package:registration_client/ui/machine_keys.dart';
Expand All @@ -32,6 +33,7 @@ import 'package:registration_client/utils/responsive.dart';
import 'package:registration_client/ui/widgets/password_component.dart';
import 'package:registration_client/ui/widgets/username_component.dart';
import 'package:colorful_progress_indicators/colorful_progress_indicators.dart';
import 'package:url_launcher/url_launcher.dart';

import '../utils/life_cycle_event_handler.dart';

Expand Down Expand Up @@ -260,6 +262,14 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
);
}

goToUrl(String url) async {
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch $url';
}
}

_getLoginAction() async {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
FocusManager.instance.primaryFocus?.unfocus();
Expand Down Expand Up @@ -471,16 +481,19 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
SizedBox(
height: isMobile && !isMobileSize ? 16.h : 34.h,
),
Text(
appLocalizations.login_text,
style: isMobile && !isMobileSize
? AppTextStyle.tabletPortraitHeaderText
: AppTextStyle.mobileHeaderText,
),
SizedBox(
height: context.watch<AuthProvider>().isValidUser ? 42.h : 38.h,
),
!context.watch<AuthProvider>().isValidUser
if (!context.watch<AuthProvider>().isNetworkPresent) ...[
Text(
appLocalizations.login_text,
style: isMobile && !isMobileSize
? AppTextStyle.tabletPortraitHeaderText
: AppTextStyle.mobileHeaderText,
),
SizedBox(
height: context.watch<AuthProvider>().isValidUser ? 42.h : 38.h,
),
],
!context.watch<AuthProvider>().isValidUser &&
!context.watch<AuthProvider>().isNetworkPresent
? UsernameComponent(
onTap: () {
_getUserValidation();
Expand All @@ -497,7 +510,8 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
},
)
: const SizedBox(),
context.watch<AuthProvider>().isValidUser
context.watch<AuthProvider>().isValidUser &&
!context.watch<AuthProvider>().isNetworkPresent
? PasswordComponent(
isDisabled: password.isEmpty || password.length > 50,
onTapLogin: () async {
Expand All @@ -514,6 +528,17 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
authProvider.setIsSyncing(false);
});
},
onTapForgotPassword: () async {
await connectivityProvider.checkNetworkConnection();
bool isConnected = connectivityProvider.isConnected;
if (isConnected) {
await authProvider.getForgotPasswordUrl();
String res = authProvider.forgotPasswordUrl;
await goToUrl(res);
} else {
authProvider.setIsNetworkPresent(true);
}
},
onChanged: (v) {
setState(() {
password = v;
Expand All @@ -522,6 +547,20 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
isLoggingIn: authProvider.isSyncing,
)
: const SizedBox(),
context.watch<AuthProvider>().isNetworkPresent
? NetworkComponent(
isMobile: isMobile,
onTapRetry: () async {
await connectivityProvider.checkNetworkConnection();
bool isConnected = connectivityProvider.isConnected;
if (isConnected) {
authProvider.setIsNetworkPresent(false);
await authProvider.getForgotPasswordUrl();
String res = authProvider.forgotPasswordUrl;
await goToUrl(res);
}
})
: const SizedBox(),
],
),
);
Expand Down
Loading

0 comments on commit 269e4e6

Please sign in to comment.