From f20890b2b178a8c8e1017d6e9b44cc5a33cdceb3 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Thu, 30 Dec 2021 09:31:17 +0300 Subject: [PATCH] forgot password & change password enhancements. --- lib/api/user_api_client.dart | 6 +-- lib/app_state/app_state.dart | 2 + lib/classes/consts.dart | 2 +- lib/ui/common_appbar.dart | 54 +++++++++++++++++++++- lib/ui/dialogs/change_password_dialog.dart | 11 ++++- lib/ui/screens/content_info_screen.dart | 3 +- lib/ui/screens/forgot_password_screen.dart | 46 +++++++++--------- lib/ui/screens/home_screen.dart | 6 +-- lib/ui/screens/quran_screen.dart | 2 +- lib/ui/screens/tangheem_detail_screen.dart | 49 ++++++++++---------- lib/ui/screens/tangheem_screen.dart | 2 +- 11 files changed, 122 insertions(+), 61 deletions(-) diff --git a/lib/api/user_api_client.dart b/lib/api/user_api_client.dart index 80c638b..696ba30 100644 --- a/lib/api/user_api_client.dart +++ b/lib/api/user_api_client.dart @@ -52,9 +52,9 @@ class UserApiClient { return await ApiClient().postJsonForObject((json) => GeneralResponseModel.fromJson(json), url, postParams); } - Future updatePassword(String _email, int _otp, String _password) async { - String url = "${ApiConsts.user}MobileUpdatePassword"; - var postParams = {"email": _email, "opt": _otp, "newPassword": _password, "confirmPassword": _password}; + Future updatePassword(String _email, String _currentPassword, String _password) async { + String url = "${ApiConsts.user}MobileChangePassword"; + var postParams = {"email": _email, "oldPassword": _currentPassword, "newPassword": _password, "confirmPassword": _password}; return await ApiClient().postJsonForObject((json) => GeneralResponseModel.fromJson(json), url, postParams); } diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index 9f637bf..99744ab 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -33,6 +33,8 @@ class AppState { String get token => _authenticationUser?.result?.data?.token; + String get userEmail => _authenticationUser?.result?.data?.email; + void setAuthenticationModel(AuthenticationUserModel _authenticationUser) { this._authenticationUser = _authenticationUser; } diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 479ff60..ce3273c 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -1,7 +1,7 @@ class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server static String baseUrl = "http://20.203.25.82"; // production server - // static String baseUrlServices = baseUrl + "/services/"; // production server + //static String baseUrlServices = baseUrl + "/services/"; // production server static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String authentication = baseUrlServices + "api/Authentication/"; static String tangheemUsers = baseUrlServices + "api/TangheemUsers/"; diff --git a/lib/ui/common_appbar.dart b/lib/ui/common_appbar.dart index 93343d1..ad65d8d 100644 --- a/lib/ui/common_appbar.dart +++ b/lib/ui/common_appbar.dart @@ -2,14 +2,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:tangheem/api/tangheem_user_api_client.dart'; +import 'package:tangheem/api/user_api_client.dart'; import 'package:tangheem/app_state/app_state.dart'; import 'package:tangheem/classes/colors.dart'; import 'package:tangheem/classes/consts.dart'; import 'package:tangheem/classes/utils.dart'; import 'package:tangheem/models/navigation_model.dart'; import 'package:tangheem/models/quick_links_model.dart'; +import 'package:tangheem/ui/dialogs/change_password_dialog.dart'; import 'package:tangheem/ui/screens/bookmark_screen.dart'; import 'package:tangheem/ui/screens/content_info_screen.dart'; +import 'package:tangheem/ui/screens/forgot_password_screen.dart'; import 'package:tangheem/ui/screens/login_screen.dart'; import 'package:tangheem/ui/screens/pdf_viewer_screen.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -146,6 +149,21 @@ class _CommonAppbarState extends State { ); } + void updatePassword(String email, String oldPassword, String password) async { + Utils.showLoading(context); + try { + await UserApiClient().updatePassword(email, oldPassword, password); + } catch (ex) { + Utils.handleException(ex, null); + Utils.hideLoading(context); + return; + } finally { + Utils.hideLoading(context); + } + Navigator.pop(context); + Utils.showToast("تم تغيير كلمة المرور بنجاح"); + } + Widget drawerView() { var height = MediaQuery.of(context).padding.top; return Drawer( @@ -267,6 +285,37 @@ class _CommonAppbarState extends State { } Navigator.pushNamed(context, LoginScreen.routeName); }), + if (AppState().isUserLogin) + Expanded( + child: PopupMenuButton( + padding: EdgeInsets.fromLTRB(0, 0, 0, 0), + onSelected: (int index) { + Navigator.pop(context); + Future.delayed(Duration(milliseconds: 200), () { + showDialog( + context: context, + barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8), + builder: (BuildContext context) => ChangePasswordDialog( + onPassword: (oldPassword, password) => updatePassword(AppState().userEmail, oldPassword, password), + ), + ); + }); + }, + icon: Icon(Icons.settings, color: ColorConsts.textGrey1), + itemBuilder: (_) => >[ + PopupMenuItem( + value: 1, + padding: EdgeInsets.fromLTRB(0, 0, 0, 0), + height: 16, + child: Center( + child: Text( + 'تغيير كلمة المرور', + style: TextStyle(color: ColorConsts.primaryBlack, fontSize: 12), + ), + ), + ), + ]), + ), ], ), ), @@ -277,8 +326,9 @@ class _CommonAppbarState extends State { child: Row( children: [ for (QuickLinksData _quickLink in quickLinks) - // commonIconButton(ApiConsts.baseUrl + _quickLink.exposeFilePath, () { for live produciton server - commonIconButton( _quickLink.exposeFilePath, () { + commonIconButton(ApiConsts.baseUrl + _quickLink.exposeFilePath, () { + //for live production server + // commonIconButton( _quickLink.exposeFilePath, () { _launchURL(_quickLink.imageUrl); }, size: 35, isAsset: false), ], diff --git a/lib/ui/dialogs/change_password_dialog.dart b/lib/ui/dialogs/change_password_dialog.dart index 6ded035..9d07308 100644 --- a/lib/ui/dialogs/change_password_dialog.dart +++ b/lib/ui/dialogs/change_password_dialog.dart @@ -6,7 +6,7 @@ import 'package:tangheem/classes/utils.dart'; import 'package:tangheem/widgets/common_textfield_widget.dart'; class ChangePasswordDialog extends StatefulWidget { - final Function(String) onPassword; + final Function(String, String) onPassword; ChangePasswordDialog({Key key, this.onPassword}) : super(key: key); @@ -17,6 +17,7 @@ class ChangePasswordDialog extends StatefulWidget { } class _ChangePasswordDialogState extends State { + final TextEditingController _currentPasswordController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); final TextEditingController _confirmPasswordController = TextEditingController(); @@ -57,6 +58,8 @@ class _ChangePasswordDialogState extends State { style: TextStyle(color: Colors.white, fontSize: 22), ), SizedBox(height: 16), + CommonTextFieldWidget(hint: "كلمة المرور الحالية", controller: _currentPasswordController, prefixIcon: "assets/icons/password.svg"), + SizedBox(height: 8), CommonTextFieldWidget(hint: "كلمة المرور الجديدة", controller: _passwordController, prefixIcon: "assets/icons/password.svg"), SizedBox(height: 8), CommonTextFieldWidget(hint: "تأكيد كلمة المرور الجديدة", controller: _confirmPasswordController, prefixIcon: "assets/icons/password.svg"), @@ -66,6 +69,10 @@ class _ChangePasswordDialogState extends State { height: 40, child: TextButton( onPressed: () { + if (_currentPasswordController.text.length < 1) { + Utils.showToast("يرجى إاخال كلمة المرور"); + return; + } if (_passwordController.text.length < 1) { Utils.showToast("يرجى إاخال كلمة المرور"); return; @@ -78,7 +85,7 @@ class _ChangePasswordDialogState extends State { Utils.showToast("خطأ في تطابق كلمات المرور"); return; } - widget.onPassword(_passwordController.text); + widget.onPassword(_currentPasswordController.text, _passwordController.text); }, style: TextButton.styleFrom( primary: Colors.white, diff --git a/lib/ui/screens/content_info_screen.dart b/lib/ui/screens/content_info_screen.dart index 9332ad6..f2b78e2 100644 --- a/lib/ui/screens/content_info_screen.dart +++ b/lib/ui/screens/content_info_screen.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:tangheem/api/tangheem_user_api_client.dart'; import 'package:tangheem/classes/colors.dart'; +import 'package:tangheem/classes/consts.dart'; import 'package:tangheem/classes/utils.dart'; import 'package:tangheem/models/content_info_model.dart'; import 'package:tangheem/ui/misc/no_data_ui.dart'; @@ -63,7 +64,7 @@ class _ContentInfoScreenState extends State { ? null : DecorationImage( fit: BoxFit.cover, - image: NetworkImage(contentList.elementAt(index).exposeFilePath), + image: NetworkImage(ApiConsts.baseUrl +contentList.elementAt(index).exposeFilePath), ), borderRadius: BorderRadius.all( Radius.circular(12.0), diff --git a/lib/ui/screens/forgot_password_screen.dart b/lib/ui/screens/forgot_password_screen.dart index 9d97226..f6e929a 100644 --- a/lib/ui/screens/forgot_password_screen.dart +++ b/lib/ui/screens/forgot_password_screen.dart @@ -36,7 +36,7 @@ class _ForgotPasswordScreenState extends State { Utils.showLoading(context); try { await UserApiClient().forgotPassword(email); - Utils.showToast("تم إرسال OTP"); + Utils.showToast("تم إرسال الرابط إلى عنوان بريدك الإلكتروني ، يرجى تعيين كلمة مرور جديدة بالنقر فوق هذا الرابط ."); } catch (ex) { Utils.handleException(ex, null); Utils.hideLoading(context); @@ -44,7 +44,7 @@ class _ForgotPasswordScreenState extends State { } finally { Utils.hideLoading(context); } - getOTP(email); + //getOTP(email); } void verifyOTP(String email, int otp) async { @@ -59,13 +59,13 @@ class _ForgotPasswordScreenState extends State { Utils.hideLoading(context); } Navigator.pop(context); - changePassword(email, otp); + //changePassword(email, otp); } void updatePassword(String email, int otp, String password) async { Utils.showLoading(context); try { - await UserApiClient().updatePassword(email, otp, password); + //await UserApiClient().updatePassword(email, otp, password); } catch (ex) { Utils.handleException(ex, null); Utils.hideLoading(context); @@ -152,23 +152,23 @@ class _ForgotPasswordScreenState extends State { ); } - void getOTP(String email) { - showDialog( - context: context, - barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8), - builder: (BuildContext context) => OTPDialog( - onOTP: (otp) => verifyOTP(email, otp), - ), - ); - } - - void changePassword(String email, int otp) { - showDialog( - context: context, - barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8), - builder: (BuildContext context) => ChangePasswordDialog( - onPassword: (password) => updatePassword(email, otp, password), - ), - ); - } + // void getOTP(String email) { + // showDialog( + // context: context, + // barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8), + // builder: (BuildContext context) => OTPDialog( + // onOTP: (otp) => verifyOTP(email, otp), + // ), + // ); + // } + // + // void changePassword(String email, int otp) { + // showDialog( + // context: context, + // barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8), + // builder: (BuildContext context) => ChangePasswordDialog( + // onPassword: (password) => updatePassword(email, otp, password), + // ), + // ); + // } } diff --git a/lib/ui/screens/home_screen.dart b/lib/ui/screens/home_screen.dart index 73abdc8..a5f091a 100644 --- a/lib/ui/screens/home_screen.dart +++ b/lib/ui/screens/home_screen.dart @@ -181,7 +181,7 @@ class _HomeScreenState extends State { mainAxisSize: MainAxisSize.min, children: [ Text( - "موسوعة الأداء القرآني", + "موسوعة النبر و التنغيم في الأداء القرآني", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20, color: ColorConsts.primaryBlue, height: 1), ), SizedBox(height: 4), @@ -203,8 +203,8 @@ class _HomeScreenState extends State { builder: (context, value, child) { return CommonDropDownButton(_selectedTangheemType, hintText: "اختر الأسلوب اللغوي", list: value, onSelect: (index) { if (_selectedTangheemType != index) { - setState((){ - _selectedSurah = -1; + setState(() { + _selectedSurah = -1; _selectedTangheemType = index; }); if (_selectedSurah >= 0) { diff --git a/lib/ui/screens/quran_screen.dart b/lib/ui/screens/quran_screen.dart index 0089768..c4caedd 100644 --- a/lib/ui/screens/quran_screen.dart +++ b/lib/ui/screens/quran_screen.dart @@ -562,7 +562,7 @@ class _QuranScreenState extends State { onTap: () async { Navigator.pop(context); List list = []; - list = _ayatTangheemTypeMapped?.data?.where((element) => int.parse(element.ayahNos.split(",")[0]) == _selectedAyaForBookmark.ayahID)?.toList() ?? []; + list = _ayatTangheemTypeMapped?.data?.where((element) => int.parse(element.ayahNos.split(",").last) == _selectedAyaForBookmark.ayahID)?.toList() ?? []; if (list.isEmpty) { Utils.showToast("لا توجد أساليب تنغيم في هذه الآية"); return; diff --git a/lib/ui/screens/tangheem_detail_screen.dart b/lib/ui/screens/tangheem_detail_screen.dart index 9d87935..2eb03d8 100644 --- a/lib/ui/screens/tangheem_detail_screen.dart +++ b/lib/ui/screens/tangheem_detail_screen.dart @@ -584,32 +584,33 @@ class _TangheemDetailScreenState extends State { ), ), Container(width: double.infinity, height: 4, color: Colors.white), - Container( - color: ColorConsts.secondaryWhite, - padding: EdgeInsets.all(4), - child: Container( - color: Colors.white, - padding: EdgeInsets.only(left: 2, right: 4), - width: double.infinity, - child: Html( - data: property.propertyValue ?? "", - style: { - 'html': Style(textAlign: TextAlign.left), - }, - ), + if ((property?.propertyValue ?? "").length > 0) + Container( + color: ColorConsts.secondaryWhite, + padding: EdgeInsets.all(4), + child: Container( + color: Colors.white, + padding: EdgeInsets.only(left: 2, right: 4), + width: double.infinity, + child: Html( + data: property.propertyValue ?? "", + style: { + 'html': Style(textAlign: TextAlign.left), + }, + ), - // Text( - // property.propertyValue ?? "", - // maxLines: 1, - // style: TextStyle( - // fontSize: 12, - // color: Color( - // Utils.stringToHex(property.textColor), - // ), - // ), - // ), + // Text( + // property.propertyValue ?? "", + // maxLines: 1, + // style: TextStyle( + // fontSize: 12, + // color: Color( + // Utils.stringToHex(property.textColor), + // ), + // ), + // ), + ), ), - ), ], ), ), diff --git a/lib/ui/screens/tangheem_screen.dart b/lib/ui/screens/tangheem_screen.dart index bd3d5fd..95aed50 100644 --- a/lib/ui/screens/tangheem_screen.dart +++ b/lib/ui/screens/tangheem_screen.dart @@ -113,7 +113,7 @@ class _TangheemScreenState extends State { style: TextStyle(fontSize: 12, color: ColorConsts.primaryBlue), ), Text( - " ${_dataList[index].ayatNumberInSurahs.split(",").toList().reversed.join(",")}", + " ${_dataList[index].ayatNumberInSurahs}", style: TextStyle(fontSize: 14, fontFamily: "BArabics", color: ColorConsts.secondaryOrange), ), ],