Skip to content
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

[RCF-69] Forgot Password functionality #418

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -232,4 +233,10 @@ public void stopAlarmService(@NonNull AuthResponsePigeon.Result<String> result)
}
result.success(resultString);
}

@Override
public void forgotPasswordUrl(@NonNull AuthResponsePigeon.Result<String> result) {
String response = "https://"+ BuildConfig.FORGOT_PASSWORD_URL +"/auth/realms/master/protocol/openid-connect/auth?client_id=security-admin-console&redirect_uri=https%3A%2F%2F"+ BuildConfig.FORGOT_PASSWORD_URL +"%2Fauth%2Fadmin%2Fmaster%2Fconsole%2F&state=744b7212-725b-48cb-91a9-9b8e4c33a031&response_mode=fragment&response_type=code&scope=openid&nonce=08339536-3d88-4d24-a465-16e9d02e7dbe&code_challenge=OQREJKeFfdANcrZpB10WqFQe8Y2Br881eR628O1sJnU&code_challenge_method=S256";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding static client id and nonce, response code is not recommended

result.success(response);
}
}
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ext {
serverHealthCheckPath = "\"/v1/syncdata/actuator/health\""
serverActuatorInfoPath = "\"/v1/syncdata/actuator/info\""
debugPassword = "\"APTyKejHxACQyKBSRciR\""
serverForgotPasswordURL = "\"iam.qa-platform1.mosip.net\""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we get this value from server side config, we can check this once

}


Expand Down
1 change: 1 addition & 0 deletions android/clientmanager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android {
buildConfigField("String", "CLIENT_VERSION", rootProject.ext.clientmanagerLibVersionName)
buildConfigField("String", "BASE_URL", rootProject.ext.serverBaseURL)
buildConfigField("String", "DEBUG_PASSWORD", rootProject.ext.debugPassword)
buildConfigField("String", "FORGOT_PASSWORD_URL", rootProject.ext.serverForgotPasswordURL)
}

buildTypes {
Expand Down
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 @@ -248,5 +248,8 @@
"offline": "غير متصل على الانترنت",
"logout_success": "لقد تم تسجيل بنجاح!",
"logout_failure": "حدث خطأ ما، يرجى المحاولة مرة أخرى بعد مرور بعض الوقت",
"go_to_home": "اذهب إلى المنزل"
"go_to_home": "اذهب إلى المنزل",
"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 @@ -248,5 +248,8 @@
"offline": "Offline",
"logout_success": "You have been successfully logged out!",
"logout_failure": "Something went wrong, please try again after some time",
"go_to_home": "Go To Home"
"go_to_home": "Go To Home",
"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 @@ -248,5 +248,8 @@
"offline": "Hors ligne",
"logout_success": "Vous avez été déconnecté avec succès!",
"logout_failure": "Quelque chose s'est mal passé, veuillez réessayer après un certain temps",
"go_to_home": "Aller à la maison"
"go_to_home": "Aller à la maison",
"no_internet_connection": "Pas de connexion Internet!",
"connect_and_retry": "Veuillez vous connecter à Internet et réessayer.",
"retry": "RECOMMENCEZ"
}
7 changes: 5 additions & 2 deletions assets/l10n/app_hi.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 @@ -248,5 +248,8 @@
"offline": "ऑफलाइन",
"logout_success": "आप सफलता पूर्वक लॉगआउट कर चुके हैं!",
"logout_failure": "कुछ गलती हो गई है, कृपया कुछ समय बाद पुनः प्रयास करें",
"go_to_home": "होम पर जाएं"
"go_to_home": "होम पर जाएं",
"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 @@ -248,5 +248,8 @@
"offline": "ಆಫ್ಲೈನ್",
"logout_success": "ನೀವು ಯಶಸ್ವಿಯಾಗಿ ಲಾಗ್ ಔಟ್ ಆಗಿರುವಿರಿ!",
"logout_failure": "ಏನೋ ತಪ್ಪಾಗಿದೆ, ದಯವಿಟ್ಟು ಸ್ವಲ್ಪ ಸಮಯದ ನಂತರ ಮತ್ತೆ ಪ್ರಯತ್ನಿಸಿ",
"go_to_home": "ಮನೆಗೆ ಹೋಗು"
"go_to_home": "ಮನೆಗೆ ಹೋಗು",
"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 @@ -257,5 +257,8 @@
"offline": "ஆஃப்லைனில்",
"logout_success": "நீங்கள் வெற்றிகரமாக வெளியேறிவிட்டீர்கள்!",
"logout_failure": "ஏதோ தவறாகிவிட்டது, சிறிது நேரம் கழித்து மீண்டும் முயற்சிக்கவும்",
"go_to_home": "வீட்டிற்கு போ"
"go_to_home": "வீட்டிற்கு போ",
"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();
}

}
45 changes: 43 additions & 2 deletions lib/ui/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import 'package:registration_client/main.dart';
import 'package:registration_client/pigeon/user_pigeon.dart';

import 'package:registration_client/provider/auth_provider.dart';
import 'package:registration_client/provider/registration_task_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 +34,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 @@ -337,6 +340,14 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
return context.read<ConnectivityProvider>().isConnected;
}

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 {
FocusManager.instance.primaryFocus?.unfocus();
if (password.isEmpty) {
Expand Down Expand Up @@ -578,6 +589,7 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
SizedBox(
height: isMobile && !isMobileSize ? 16.h : 34.h,
),
if(!context.watch<AuthProvider>().isNetworkPresent)...[
Text(
appLocalizations.login_text,
style: isMobile && !isMobileSize
Expand All @@ -587,7 +599,8 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
SizedBox(
height: context.watch<AuthProvider>().isValidUser ? 42.h : 38.h,
),
!context.watch<AuthProvider>().isValidUser
],
!context.watch<AuthProvider>().isValidUser && !context.watch<AuthProvider>().isNetworkPresent
? UsernameComponent(
onTap: () {
_getUserValidation();
Expand All @@ -604,7 +617,7 @@ 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 @@ -621,6 +634,19 @@ 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 @@ -629,6 +655,21 @@ 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