diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index c600610b..635e12a5 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -139,4 +139,19 @@ const Map> localizedValues = { }, "another-acc": {"en": "Use Another Account", "ar": "استخدم حسابا آخر"}, "next": {"en": "Next", "ar": 'التالى'}, + "first-name": {"en": "First Name", "ar": "الاسم الأول"}, + "middle-name": {"en": "Middle Name", "ar": "الاسم الثاني"}, + "last-name": {"en": "Last Name", "ar": "إسم العائلة"}, + "female": {"en": "Female", "ar": "أنثى"}, + "male": {"en": "Male", "ar": "ذكر"}, + "preferred-language": {"en": "Preferred Language", "ar": "اللغة المفضلة"}, + "english": {"en": "English", "ar": "الإنجليزية"}, + "arabic": {"en": "Arabic", "ar": "العربية"}, + "locations-register": { + "en": "Where do you want to create this file?", + "ar": "أين تريد فتح هذا الملف؟" + }, + "ksa": {"en": "KSA", "ar": "السعودية"}, + "dubai": {"en": "Dubai", "ar": "دبي"}, + "enter-email": {"en": "Enter Email", "ar": "ادخل البريد الالكتروني"}, }; diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index f20d6a9c..456cb02b 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -63,6 +63,8 @@ class BaseAppClient { } else if (parsed['MessageStatus'] == 1) { onSuccess(parsed, statusCode); } else { + onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], + statusCode); logout(); } diff --git a/lib/models/Authentication/check_activation_code_request.dart b/lib/models/Authentication/check_activation_code_request.dart index 71440dc4..a4bf79c3 100644 --- a/lib/models/Authentication/check_activation_code_request.dart +++ b/lib/models/Authentication/check_activation_code_request.dart @@ -22,7 +22,7 @@ class CheckActivationCodeReq { Null sessionID; bool isDentalAllowedBackend; int deviceTypeID; - + bool forRegisteration; CheckActivationCodeReq( {this.patientMobileNumber, this.mobileNo, @@ -46,7 +46,8 @@ class CheckActivationCodeReq { this.patientOutSA, this.sessionID, this.isDentalAllowedBackend, - this.deviceTypeID}); + this.deviceTypeID, + this.forRegisteration}); CheckActivationCodeReq.fromJson(Map json) { patientMobileNumber = json['PatientMobileNumber']; @@ -72,6 +73,7 @@ class CheckActivationCodeReq { sessionID = json['SessionID']; isDentalAllowedBackend = json['isDentalAllowedBackend']; deviceTypeID = json['DeviceTypeID']; + forRegisteration = json['ForRegisteration']; } Map toJson() { @@ -99,6 +101,7 @@ class CheckActivationCodeReq { data['SessionID'] = this.sessionID; data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; data['DeviceTypeID'] = this.deviceTypeID; + data['ForRegisteration'] = this.forRegisteration; return data; } } diff --git a/lib/models/Authentication/register_user_requet.dart b/lib/models/Authentication/register_user_requet.dart new file mode 100644 index 00000000..ebefcfcf --- /dev/null +++ b/lib/models/Authentication/register_user_requet.dart @@ -0,0 +1,151 @@ +class RegisterUserRequest { + Patientobject patientobject; + String patientIdentificationID; + int patientMobileNumber; + String logInTokenID; + double versionID; + int channel; + int languageID; + String iPAdress; + String generalid; + int patientOutSA; + Null sessionID; + bool isDentalAllowedBackend; + int deviceTypeID; + + RegisterUserRequest( + {this.patientobject, + this.patientIdentificationID, + this.patientMobileNumber, + this.logInTokenID, + this.versionID, + this.channel, + this.languageID, + this.iPAdress, + this.generalid, + this.patientOutSA, + this.sessionID, + this.isDentalAllowedBackend, + this.deviceTypeID}); + + RegisterUserRequest.fromJson(Map json) { + patientobject = json['Patientobject'] != null + ? new Patientobject.fromJson(json['Patientobject']) + : null; + patientIdentificationID = json['PatientIdentificationID']; + patientMobileNumber = json['PatientMobileNumber']; + logInTokenID = json['LogInTokenID']; + versionID = json['VersionID']; + channel = json['Channel']; + languageID = json['LanguageID']; + iPAdress = json['IPAdress']; + generalid = json['generalid']; + patientOutSA = json['PatientOutSA']; + sessionID = json['SessionID']; + isDentalAllowedBackend = json['isDentalAllowedBackend']; + deviceTypeID = json['DeviceTypeID']; + } + + Map toJson() { + final Map data = new Map(); + if (this.patientobject != null) { + data['Patientobject'] = this.patientobject.toJson(); + } + data['PatientIdentificationID'] = this.patientIdentificationID; + data['PatientMobileNumber'] = this.patientMobileNumber; + data['LogInTokenID'] = this.logInTokenID; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['LanguageID'] = this.languageID; + data['IPAdress'] = this.iPAdress; + data['generalid'] = this.generalid; + data['PatientOutSA'] = this.patientOutSA; + data['SessionID'] = this.sessionID; + data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; + data['DeviceTypeID'] = this.deviceTypeID; + return data; + } +} + +class Patientobject { + bool tempValue; + int patientIdentificationType; + String patientIdentificationNo; + int mobileNumber; + int patientOutSA; + String firstName; + String middleName; + String lastName; + dynamic strDateofBirth; + String dateofBirth; + int gender; + String nationalityID; + String dateofBirthN; + String emailAddress; + String sourceType; + String preferredLanguage; + String marital; + + Patientobject( + {this.tempValue, + this.patientIdentificationType, + this.patientIdentificationNo, + this.mobileNumber, + this.patientOutSA, + this.firstName, + this.middleName, + this.lastName, + this.strDateofBirth, + this.dateofBirth, + this.gender, + this.nationalityID, + this.dateofBirthN, + this.emailAddress, + this.sourceType, + this.preferredLanguage, + this.marital}); + + Patientobject.fromJson(Map json) { + tempValue = json['TempValue']; + patientIdentificationType = json['PatientIdentificationType']; + patientIdentificationNo = json['PatientIdentificationNo']; + mobileNumber = json['MobileNumber']; + patientOutSA = json['PatientOutSA']; + firstName = json['FirstName']; + middleName = json['MiddleName']; + lastName = json['LastName']; + strDateofBirth = json['StrDateofBirth']; + dateofBirth = json['DateofBirth']; + gender = json['Gender']; + nationalityID = json['NationalityID']; + dateofBirthN = json['DateofBirthN']; + emailAddress = json['EmailAddress']; + sourceType = json['SourceType']; + + preferredLanguage = json['PreferredLanguage']; + marital = json['Marital']; + } + + Map toJson() { + final Map data = new Map(); + data['TempValue'] = this.tempValue; + data['PatientIdentificationType'] = this.patientIdentificationType; + data['PatientIdentificationNo'] = this.patientIdentificationNo; + data['MobileNumber'] = this.mobileNumber; + data['PatientOutSA'] = this.patientOutSA; + data['FirstName'] = this.firstName; + data['MiddleName'] = this.middleName; + data['LastName'] = this.lastName; + data['StrDateofBirth'] = this.strDateofBirth; + data['DateofBirth'] = this.dateofBirth; + data['Gender'] = this.gender; + data['NationalityID'] = this.nationalityID; + data['DateofBirthN'] = this.dateofBirthN; + data['EmailAddress'] = this.emailAddress; + data['SourceType'] = this.sourceType; + + data['PreferredLanguage'] = this.preferredLanguage; + data['Marital'] = this.marital; + return data; + } +} diff --git a/lib/models/Authentication/registered_authenticated_user_req.dart b/lib/models/Authentication/registered_authenticated_user_req.dart new file mode 100644 index 00000000..c261d062 --- /dev/null +++ b/lib/models/Authentication/registered_authenticated_user_req.dart @@ -0,0 +1,104 @@ +class RegisteredAuthenticatedUserRequest { + double versionID; + int channel; + int languageID; + String iPAdress; + String generalid; + int patientOutSA; + String sessionID; + bool isDentalAllowedBackend; + int deviceTypeID; + int patientID; + String tokenID; + String voipToken; + int patientTypeID; + int patientType; + String deviceToken; + String deviceType; + String patientMobileNumber; + String nationalID; + int gender; + int loginType; + String mACAddress; + int latitude; + int longitude; + + RegisteredAuthenticatedUserRequest( + {this.versionID, + this.channel, + this.languageID, + this.iPAdress, + this.generalid, + this.patientOutSA, + this.sessionID, + this.isDentalAllowedBackend, + this.deviceTypeID, + this.patientID, + this.tokenID, + this.voipToken, + this.patientTypeID, + this.patientType, + this.deviceToken, + this.deviceType, + this.patientMobileNumber, + this.nationalID, + this.gender, + this.loginType, + this.mACAddress, + this.latitude, + this.longitude}); + + RegisteredAuthenticatedUserRequest.fromJson(Map json) { + versionID = json['VersionID']; + channel = json['Channel']; + languageID = json['LanguageID']; + iPAdress = json['IPAdress']; + generalid = json['generalid']; + patientOutSA = json['PatientOutSA']; + sessionID = json['SessionID']; + isDentalAllowedBackend = json['isDentalAllowedBackend']; + deviceTypeID = json['DeviceTypeID']; + patientID = json['PatientID']; + tokenID = json['TokenID']; + voipToken = json['VoipToken']; + patientTypeID = json['PatientTypeID']; + patientType = json['PatientType']; + deviceToken = json['DeviceToken']; + deviceType = json['DeviceType']; + patientMobileNumber = json['PatientMobileNumber']; + nationalID = json['NationalID']; + gender = json['Gender']; + loginType = json['LoginType']; + mACAddress = json['MACAddress']; + latitude = json['Latitude']; + longitude = json['Longitude']; + } + + Map toJson() { + final Map data = new Map(); + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['LanguageID'] = this.languageID; + data['IPAdress'] = this.iPAdress; + data['generalid'] = this.generalid; + data['PatientOutSA'] = this.patientOutSA; + data['SessionID'] = this.sessionID; + data['isDentalAllowedBackend'] = this.isDentalAllowedBackend; + data['DeviceTypeID'] = this.deviceTypeID; + data['PatientID'] = this.patientID; + data['TokenID'] = this.tokenID; + data['VoipToken'] = this.voipToken; + data['PatientTypeID'] = this.patientTypeID; + data['PatientType'] = this.patientType; + data['DeviceToken'] = this.deviceToken; + data['DeviceType'] = this.deviceType; + data['PatientMobileNumber'] = this.patientMobileNumber; + data['NationalID'] = this.nationalID; + data['Gender'] = this.gender; + data['LoginType'] = this.loginType; + data['MACAddress'] = this.mACAddress; + data['Latitude'] = this.latitude; + data['Longitude'] = this.longitude; + return data; + } +} diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index 9f1eb367..2fc0a08a 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -1,4 +1,5 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart'; import 'package:diplomaticquarterapp/pages/ToDoList/ToDo.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; @@ -69,7 +70,12 @@ class _LandingPageState extends State { body: PageView( physics: NeverScrollableScrollPhysics(), controller: pageController, - children: [Container(), MedicalProfilePage(), MyAdmissionsPage(), ToDo()], + children: [ + Container(), + MedicalProfilePage(), + MyAdmissionsPage(), + ToDo() + ], ), bottomNavigationBar: BottomNavBar(changeIndex: _changeCurrentTab), ); @@ -90,14 +96,23 @@ class _LandingPageState extends State { } } - void checkUserStatus(token) { + void checkUserStatus(token) async { authService .selectDeviceImei(token) .then((SelectDeviceIMEIRES value) => setUserValues(value)); + if (await sharedPref.getObject(USER_PROFILE) != null) { + var data = + AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); + if (data != null) + authService.registeredAuthenticatedUser(data, token, 0, 0); + // setState(() { + // this.user = data; + // print(this.user); + // }); + } } void setUserValues(value) async { - print(value); sharedPref.setObject(IMEI_USER_DATA, value); } } diff --git a/lib/pages/login/confirm-login.dart b/lib/pages/login/confirm-login.dart index 609d16bc..8ecfef39 100644 --- a/lib/pages/login/confirm-login.dart +++ b/lib/pages/login/confirm-login.dart @@ -37,7 +37,7 @@ class _ConfirmLogin extends State { String errorMsg = ''; SelectDeviceIMEIRES user; bool isLoading = false; - CheckPatientAuthenticationReq registerd_data; + var registerd_data; bool isMoreOption = false; var zipCode; @@ -119,9 +119,11 @@ class _ConfirmLogin extends State { textAlign: TextAlign.center, ), subtitle: Text( - formatDate(DateUtil - .convertStringToDate( - user.editedOn)), + user.editedOn != null + ? formatDate(DateUtil + .convertStringToDate( + user.editedOn)) + : '--', textAlign: TextAlign.center), )), @@ -299,9 +301,9 @@ class _ConfirmLogin extends State { this.checkUserAuthentication(type); } else { if (this.loginTokenID != null) { - Future.delayed(Duration(seconds: 1), () { - this.sendActivationCode(type); - }); + // Future.delayed(Duration(seconds: 1), () { + this.sendActivationCode(type); + // }); } else { this.checkUserAuthentication(type); } @@ -320,9 +322,9 @@ class _ConfirmLogin extends State { sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), this.loginTokenID = value['LogInTokenID'], sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), - Future.delayed(Duration(seconds: 1), () { - this.sendActivationCode(type); - }) + // Future.delayed(Duration(seconds: 1), () { + this.sendActivationCode(type) + // }) } else { @@ -418,14 +420,17 @@ class _ConfirmLogin extends State { // AuthenticationService.IMEI_USER_DATA, // false // ); + setState(() { setUser(); }); if (await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN) != null) { + isMoreOption = true; this.registerd_data = CheckPatientAuthenticationReq.fromJson( await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN)); } + this.mobileNumber = this.registerd_data != null ? this.registerd_data.patientMobileNumber : int.parse(this.user.mobile); @@ -456,7 +461,7 @@ class _ConfirmLogin extends State { request.loginType = this.selectedOption; request.oTPSendType = this.selectedOption == 1 ? 1 : 2; request.zipCode = this.zipCode; - request.isRegister = false; + request.logInTokenID = this.loginTokenID ?? ""; if (this.registerd_data != null) { @@ -464,45 +469,63 @@ class _ConfirmLogin extends State { request.patientID = this.registerd_data.patientID ?? 0; request.patientIdentificationID = request.nationalID = this.registerd_data.patientIdentificationID ?? '0'; + + request.isRegister = this.registerd_data.isRegister; } else { request.searchType = request.searchType ?? 2; request.patientID = this.user.patientID ?? 0; request.nationalID = request.nationalID ?? '0'; request.patientIdentificationID = request.patientIdentificationID ?? '0'; + request.isRegister = false; } request.deviceTypeID = request.searchType; return request; } - checkActivationCode({value}) { + checkActivationCode({value}) async { SMSOTP.showLoadingDialog(context, true); var request = this.getCommonRequest().toJson(); - this.authService.checkActivationCode(request, value: value).then((result) => - { - if (result is Map) - { - result = CheckActivationCode.fromJson(result), - - this.userData = - result.list, //AuthenticatedUser.fromJson(result['List'][0]), - this.sharedPref.setObject(USER_PROFILE, result.list), - this.loginTokenID = result.logInTokenID, - this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), - this.sharedPref.setString(TOKEN, result.authenticationTokenID), - this.checkIfUserAgreedBefore(result), - // Navigator.of(context).pop(), - SMSOTP.showLoadingDialog(context, false), - } - else - { - // Navigator.of(context).pop(), - SMSOTP.showLoadingDialog(context, false), - Future.delayed(Duration(seconds: 1), () { - AppToast.showErrorToast(message: result); - }), - } - }); + this + .authService + .checkActivationCode(request, value: value) + .then((result) => { + if (result is Map) + { + result = CheckActivationCode.fromJson(result), + if (this.registerd_data != null && + this.registerd_data.isRegister == true) + { + Navigator.of(context).pushNamed( + REGISTER_INFO, + ) + } + else + { + this.userData = result + .list, //AuthenticatedUser.fromJson(result['List'][0]), + this.sharedPref.setObject(USER_PROFILE, result.list), + this.loginTokenID = result.logInTokenID, + this + .sharedPref + .setObject(LOGIN_TOKEN_ID, result.logInTokenID), + this + .sharedPref + .setString(TOKEN, result.authenticationTokenID), + this.checkIfUserAgreedBefore(result), + // Navigator.of(context).pop(), + SMSOTP.showLoadingDialog(context, false), + } + } + else + { + // Navigator.of(context).pop(), + SMSOTP.showLoadingDialog(context, false), + Future.delayed(Duration(seconds: 1), () { + AppToast.showErrorToast(message: result); + }), + } + }); } checkIfUserAgreedBefore(CheckActivationCode result) { @@ -519,7 +542,7 @@ class _ConfirmLogin extends State { } goToHome() { - authService.insertDeviceImei().then((value) => print(value)); + // authService.insertDeviceImei().then((value) => print(value)); Navigator.of(context).pushNamed(HOME); // const request = new LoginRequest(); // if (this.loginType === AuthenticationService.IDENTIFCIATION_LOGIN_TYPE) { diff --git a/lib/pages/login/register-info.dart b/lib/pages/login/register-info.dart index 70e5fb29..fe86c77a 100644 --- a/lib/pages/login/register-info.dart +++ b/lib/pages/login/register-info.dart @@ -1,10 +1,14 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/config/size_config.dart'; +import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart'; import 'package:diplomaticquarterapp/models/Authentication/register_info_response.dart'; +import 'package:diplomaticquarterapp/models/Authentication/register_user_requet.dart'; import 'package:diplomaticquarterapp/pages/login/login-type.dart'; +import 'package:diplomaticquarterapp/routes.dart'; import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; +import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; @@ -13,9 +17,13 @@ import 'package:diplomaticquarterapp/widgets/card/rounded_container.dart'; import 'package:diplomaticquarterapp/widgets/input/text_field.dart'; import 'package:diplomaticquarterapp/widgets/mobile-no/mobile_no.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart'; import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:hijri/hijri_calendar.dart'; +import 'package:intl/intl.dart'; class RegisterInfo extends StatefulWidget { @override @@ -25,9 +33,14 @@ class RegisterInfo extends StatefulWidget { class _RegisterInfo extends State { final authService = new AuthProvider(); final sharedPref = new AppSharedPreferences(); + var emailAddress = new TextEditingController(); RegisterInfoResponse registerInfo; bool isLoading; int page = 1; + String selectedLanguage = 'English'; + var registerRequest; + + var selectSourceType = 'KSA'; @override void initState() { getRegisterInfo(); @@ -41,100 +54,291 @@ class _RegisterInfo extends State { isShowAppBar: true, body: SingleChildScrollView( child: Container( - padding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30), - height: SizeConfig.realScreenHeight * .9, + // padding: EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 30), + height: SizeConfig.realScreenHeight, width: SizeConfig.realScreenWidth, - child: Column(children: [ - Expanded( - flex: 1, - child: AppText( - TranslationBase.of(context).patientInfo, - fontSize: SizeConfig.textMultiplier * 3, - textAlign: TextAlign.left, - )), - registerInfo != null && page == 1 - ? Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + child: RoundedContainer( + child: Padding( + padding: + EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0), + child: Stack( + // crossAxisAlignment: CrossAxisAlignment.start, + // mainAxisAlignment: MainAxisAlignment.start, children: [ - AppText('National ID'), - Container( - margin: EdgeInsets.only(bottom: 10), - child: TextFields( - hintText: registerInfo.idNumber, - prefixIcon: Icon(Icons.chrome_reader_mode, - color: Colors.red), - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - AppText('Name'), - Container( - margin: EdgeInsets.only(bottom: 10), - child: TextFields( - hintText: registerInfo.firstNameEn + - ' ' + - registerInfo.lastNameEn, - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - AppText('Gender'), - Container( - margin: EdgeInsets.only(bottom: 10), - child: TextFields( - hintText: registerInfo.maritalStatusCode == 'U' - ? 'Unknown' - : registerInfo.maritalStatusCode == 'M' - ? 'Male' - : 'Female', - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - AppText('Nationality'), - Container( - margin: EdgeInsets.only(bottom: 10), - child: TextFields( - hintText: registerInfo.nationalityCode, - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, - )), - AppText('Date of Birth'), - Container( - margin: EdgeInsets.only(bottom: 10), - child: TextFields( - hintText: registerInfo.dateOfBirth, - padding: EdgeInsets.only( - top: 20, bottom: 20, left: 10, right: 10), - readOnly: true, + Padding( + padding: EdgeInsets.only(bottom: 0), + child: AppText( + TranslationBase.of(context).patientInfo, + fontWeight: FontWeight.bold, + // fontSize: SizeConfig.textMultiplier * 2, + textAlign: TextAlign.left, )), + registerInfo != null && page == 1 + ? Padding( + padding: EdgeInsets.only(top: 20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.idNumber, + prefixIcon: Icon( + Icons.chrome_reader_mode, + color: Colors.red), + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + AppText( + TranslationBase.of(context).firstName), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.firstNameEn, + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + AppText( + TranslationBase.of(context).middleName), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.secondNameEn, + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + AppText(TranslationBase.of(context).lastName), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.lastNameEn, + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + AppText(TranslationBase.of(context).gender), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo + .maritalStatusCode == + 'U' + ? 'Unknown' + : registerInfo.maritalStatusCode == + 'M' + ? AppText( + TranslationBase.of(context) + .male) + : AppText( + TranslationBase.of(context) + .female), + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + AppText( + TranslationBase.of(context).nationality), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.nationalityCode, + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + AppText(TranslationBase.of(context).dob), + Container( + margin: EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: registerInfo.dateOfBirth, + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + readOnly: true, + )), + ], + )) + : registerInfo != null && page == 2 + ? isLoading == true + ? AppCircularProgressIndicator() + : Padding( + padding: EdgeInsets.only(top: 20), + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + mainAxisAlignment: + MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + AppText(TranslationBase.of(context) + .prefferedLanguage), + Container( + margin: EdgeInsets.only(top: 0), + decoration: BoxDecoration( + border: Border.all( + color: Colors.grey, + width: 1), + borderRadius: + BorderRadius.circular( + 5.0)), + padding: EdgeInsets.all(5), + child: + DropdownButtonHideUnderline( + child: DropdownButton( + focusColor: + Colors.white, + dropdownColor: + Colors.white, + isExpanded: true, + value: + selectedLanguage, + iconSize: 40, + elevation: 16, + onChanged: (String + newValue) => + {}, + items: [ + TranslationBase.of( + context) + .english, + TranslationBase.of( + context) + .arabic, + ].map< + DropdownMenuItem< + String>>((String + value) { + return DropdownMenuItem< + String>( + value: value, + child: + Text(value), + ); + }).toList()))), + AppText(TranslationBase.of(context) + .registrLocation), + Container( + margin: + EdgeInsets.only(bottom: 10), + decoration: BoxDecoration( + border: Border.all( + color: Colors.grey, + width: 1), + borderRadius: + BorderRadius.circular( + 5.0)), + padding: EdgeInsets.all(5), + child: + DropdownButtonHideUnderline( + child: DropdownButton( + focusColor: + Colors.white, + dropdownColor: + Colors.white, + isExpanded: true, + value: + selectSourceType, + iconSize: 40, + elevation: 16, + onChanged: (String + newValue) => + {}, + items: [ + TranslationBase.of( + context) + .ksa, + TranslationBase.of( + context) + .dubai, + ].map< + DropdownMenuItem< + String>>((String + value) { + return DropdownMenuItem< + String>( + value: value, + child: + Text(value), + ); + }).toList()))), + AppText(TranslationBase.of(context) + .enterEmail), + Container( + margin: + EdgeInsets.only(bottom: 10), + child: TextFields( + hintText: + TranslationBase.of(context) + .enterEmail, + controller: emailAddress, + padding: EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10), + )) + ], + )) + : SizedBox(), + // AppText('National ID'), + + page == 1 + ? Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Expanded( + child: DefaultButton( + TranslationBase.of(context).next, + () => {nextPage()}, + textColor: Colors.white, + )) + ], + ) + ], + ) + : Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Expanded( + child: DefaultButton( + TranslationBase.of(context).register, + () => {registerNow()}, + textColor: Colors.white, + )) + ]) + ]) ], - ) - : registerInfo != null && page == 2 - ? Column( - children: [], - ) - : SizedBox(), - Expanded( - flex: 2, - child: Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Row( - children: [ - Expanded( - child: DefaultButton( - TranslationBase.of(context).next, - () => {nextPage()}, - textColor: Colors.white, - )) - ], - ), - ], - )) - ]), + ))), ))); } @@ -144,11 +348,89 @@ class _RegisterInfo extends State { }); } - registerNow() {} + registerNow() { + var patientRequest = Patientobject(); + var request = RegisterUserRequest(); + showLoader(true); + patientRequest.dateofBirth = DateUtil.convertISODateToJsonDate( + registerInfo.dateOfBirth.replaceAll('/', '-')); + patientRequest.emailAddress = emailAddress.text; + patientRequest.patientIdentificationNo = registerInfo.idNumber; + patientRequest.patientIdentificationType = 2; + patientRequest.sourceType = selectSourceType == 'KSA' ? '1' : '2'; + patientRequest.nationalityID = registerInfo.nationalityCode; + patientRequest.dateofBirthN = HijriCalendar.fromDate(DateFormat('mm-dd-yyy') + .parse(registerInfo.dateOfBirth.replaceAll('/', '-'))) + .toString(); + patientRequest.firstName = registerInfo.firstNameEn; + patientRequest.middleName = registerInfo.secondNameEn; + patientRequest.lastName = registerInfo.lastNameEn; + patientRequest.gender = registerInfo.gender == 'F' ? 2 : 1; + patientRequest.mobileNumber = registerRequest['PatientMobileNumber']; + patientRequest.marital = registerInfo.maritalStatusCode == 'M' ? '1' : '0'; + // patientRequest.projectID = null; + patientRequest.strDateofBirth = DateFormat('mm-dd-yyy') + .parse(registerInfo.dateOfBirth.replaceAll('/', '-')) + .toString(); //DateFormat("MM-dd-yyyy") + //.parse(registerInfo.dateOfBirth.replaceAll('/', '-')); + patientRequest.tempValue = true; + request.logInTokenID = registerRequest['LogInTokenID']; + request.patientMobileNumber = registerRequest['PatientMobileNumber']; + request.patientIdentificationID = registerInfo.idNumber; + request.patientOutSA = registerRequest['PatientOutSA']; + request.patientobject = patientRequest; + request.patientobject.preferredLanguage = + selectedLanguage == 'Arabic' ? '1' : '2'; + authService.registerUser(request).then((value) => {registerd(value)}); + } + + registerd(result) { + showLoader(false); + if (result is Map) { + result = CheckActivationCode.fromJson(result); + + // this.userData = + // result.list; //AuthenticatedUser.fromJson(result['List'][0]), + this.sharedPref.setObject(USER_PROFILE, result.list); + // this.loginTokenID = result.logInTokenID; + this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); + this.sharedPref.setString(TOKEN, result.authenticationTokenID); + this.checkIfUserAgreedBefore(result); + // Navigator.of(context).pop(), + + } else { + // Navigator.of(context).pop(), + AppToast.showErrorToast(message: result); + } + } + + checkIfUserAgreedBefore(result) { + if (result.isNeedUserAgreement) { + //move to agreement page. + } else { + insertIMEI(); + } + } + + insertIMEI() { + authService + .insertDeviceImei() + .then((value) => {Navigator.of(context).pushNamed(HOME)}); + } + getRegisterInfo() async { registerInfo = RegisterInfoResponse.fromJson(await sharedPref.getObject(NHIC_DATA)); - + registerRequest = await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN); + setState(() { + registerInfo = registerInfo; + }); print(await sharedPref.getObject(NHIC_DATA)); } + + showLoader(bool isTrue) { + setState(() { + isLoading = isTrue; + }); + } } diff --git a/lib/pages/login/register.dart b/lib/pages/login/register.dart index 5197b652..3706f452 100644 --- a/lib/pages/login/register.dart +++ b/lib/pages/login/register.dart @@ -185,6 +185,7 @@ class _Register extends State { // if (this.loginType == 1) { request.patientIdentificationID = int.parse(nationalIDorFile.text); request.patientID = 0; + request.isRegister = true; // } else { // request.patientIdentificationID = 0; // request.patientID = int.parse(nationalIDorFile.text); @@ -223,18 +224,19 @@ class _Register extends State { nRequest['LogInTokenID'] = response['LogInTokenID']; if (response['hasFile'] == true) { AppToast.showErrorToast(message: response['ErrorEndUserMessage']); - //confirm box need to implement - // this.cs.confirmLogin(); } else { nRequest['forRegister'] = true; + nRequest['isRegister'] = true; + nRequest["PatientIdentificationID"] = + nRequest["PatientIdentificationID"].toString(); sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest); - + sharedPref.setString(LOGIN_TOKEN_ID, response['LogInTokenID']); this.chekUserData(response['LogInTokenID']); } } else { - if (response['ErrorCode'] == '-986') { - AppToast.showErrorToast(message: response['ErrorEndUserMessage']); - } + // if (response['ErrorCode'] == '-986') { + AppToast.showErrorToast(message: response); + //} } } @@ -262,11 +264,14 @@ class _Register extends State { result = CheckUserStatusResponse.fromJson(result), sharedPref.setObject(NHIC_DATA, result), Navigator.of(context).pushNamed( - REGISTER_INFO, + CONFIRM_LOGIN, ) + // Navigator.of(context).pushNamed( + // REGISTER_INFO, + // ) } else - {AppToast.showErrorToast(message: result['ErrorEndUserMessage'])} + {AppToast.showErrorToast(message: result)} //this.onRegister(); }); } diff --git a/lib/services/authentication/auth_provider.dart b/lib/services/authentication/auth_provider.dart index 4b0717b4..f74fb056 100644 --- a/lib/services/authentication/auth_provider.dart +++ b/lib/services/authentication/auth_provider.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_request.dart'; @@ -8,14 +6,12 @@ import 'package:diplomaticquarterapp/models/Authentication/check_activation_code import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart'; import 'package:diplomaticquarterapp/models/Authentication/check_user_status_req.dart'; import 'package:diplomaticquarterapp/models/Authentication/checkpatient_for_registration.dart'; -import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_request.dart'; -import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_response.dart'; import 'package:diplomaticquarterapp/models/Authentication/insert_device_imei_request.dart'; +import 'package:diplomaticquarterapp/models/Authentication/register_user_requet.dart'; import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart'; +import 'package:diplomaticquarterapp/models/Authentication/registered_authenticated_user_req.dart'; import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart'; -import 'package:diplomaticquarterapp/models/Request.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; -import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:flutter/cupertino.dart'; // SharedPreferences sharedPref = new SharedPreferences(); @@ -35,6 +31,9 @@ const CHECK_PATIENT_FOR_REGISTRATION = "/Authentication.svc/REST/CheckPatientForRegisteration"; const CHECK_USER_STATUS = "/NHIC.svc/REST/GetPatientInfo"; +const REGISTER_USER = '/Authentication.svc/REST/PatientRegistration'; +const LOGGED_IN_USER_URL = + '/MobileNotifications.svc/REST/Insert_PatientMobileDeviceInfo'; class AuthProvider with ChangeNotifier { bool isLogin = false; @@ -223,7 +222,6 @@ class AuthProvider with ChangeNotifier { var neRequest = CheckActivationCodeReq.fromJson(request); neRequest.activationCode = value ?? "0000"; neRequest.isSilentLogin = value != null ? false : true; - neRequest.isRegister = false; neRequest.versionID = VERSION_ID; neRequest.channel = CHANNEL; neRequest.iPAdress = IP_ADDRESS; @@ -233,6 +231,8 @@ class AuthProvider with ChangeNotifier { neRequest.patientOutSA = neRequest.zipCode == '966' ? 0 : 1; neRequest.projectOutSA = neRequest.zipCode == '966' ? 0 : 1; neRequest.isDentalAllowedBackend = false; + neRequest.forRegisteration = neRequest.isRegister; + neRequest.isRegister = false; dynamic localRes; try { await new BaseAppClient().post(CHECK_ACTIVATION_CODE, @@ -303,4 +303,60 @@ class AuthProvider with ChangeNotifier { throw error; } } + + Future registerUser(RegisterUserRequest request) async { + request.versionID = VERSION_ID; + request.channel = CHANNEL; + request.iPAdress = IP_ADDRESS; + request.generalid = GENERAL_ID; + request.deviceTypeID = DeviceTypeID; + request.languageID = LANGUAGE_ID; + + // request.tokenID = ''; + dynamic localRes; + try { + await new BaseAppClient().post(REGISTER_USER, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + localRes = error; + return Future.value(error); + }, body: request.toJson()); + return Future.value(localRes); + } catch (error) { + throw error; + } + } + + Future registeredAuthenticatedUser( + AuthenticatedUser user, deviceToken, lat, long) async { + var request = new RegisteredAuthenticatedUserRequest(); + request.deviceToken = deviceToken; + request.voipToken = + ""; //this.cs.sharedService.getSharedData(AuthenticationService.APNS_TOKEN, false); + request.deviceType = DeviceTypeID.toString(); + request.patientMobileNumber = '0' + user.mobileNumber; + request.nationalID = user.patientIdentificationNo; + request.gender = user.gender; + request.patientID = user.patientID; + request.patientOutSA = user.outSA; + request.loginType = await sharedPref.getInt(LAST_LOGIN) ?? 1; + request.mACAddress = '00:00:00:00:00:00'; + request.latitude = lat; + request.longitude = long; + request.languageID = int.parse(user.preferredLanguage); + dynamic localRes; + try { + await new BaseAppClient().post(LOGGED_IN_USER_URL, + onSuccess: (dynamic response, int statusCode) { + localRes = response; + }, onFailure: (String error, int statusCode) { + localRes = error; + return Future.value(error); + }, body: request.toJson()); + return Future.value(localRes); + } catch (error) { + throw error; + } + } } diff --git a/lib/uitl/date_uitl.dart b/lib/uitl/date_uitl.dart index 8b8d0c19..950cb25c 100644 --- a/lib/uitl/date_uitl.dart +++ b/lib/uitl/date_uitl.dart @@ -1,3 +1,4 @@ +import 'package:intl/intl.dart'; class DateUtil { /// convert String To Date function /// [date] String we want to convert @@ -132,4 +133,13 @@ class DateUtil { else return ""; } + + static convertISODateToJsonDate(String isoDate) { + return "/Date(" + + DateFormat('mm-dd-yyy') + .parse(isoDate) + .millisecondsSinceEpoch + .toString() + + ")/"; + } } diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 2cf6ca23..f2282cd3 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -177,6 +177,20 @@ class TranslationBase { String get useAnotherAccount => localizedValues['another-acc'][locale.languageCode]; String get next => localizedValues['next'][locale.languageCode]; + String get firstName => localizedValues['first-name'][locale.languageCode]; + String get middleName => localizedValues['middle-name'][locale.languageCode]; + String get lastName => localizedValues['last-name'][locale.languageCode]; + String get male => localizedValues['male'][locale.languageCode]; + String get female => localizedValues['female'][locale.languageCode]; + String get prefferedLanguage => + localizedValues['preferred-language'][locale.languageCode]; + String get english => localizedValues['english'][locale.languageCode]; + String get arabic => localizedValues['arabic'][locale.languageCode]; + String get registrLocation => + localizedValues['locations-register'][locale.languageCode]; + String get ksa => localizedValues['ksa'][locale.languageCode]; + String get dubai => localizedValues['dubai'][locale.languageCode]; + String get enterEmail => localizedValues['enter-email'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate { diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index 260f5851..3d856574 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -235,6 +235,7 @@ class _AppDrawerState extends State { login() async { var data = await sharedPref.getObject(IMEI_USER_DATA); + sharedPref.remove(REGISTER_DATA_FOR_LOGIIN); if (data != null) { Navigator.of(context).pushNamed(CONFIRM_LOGIN); } else { diff --git a/pubspec.yaml b/pubspec.yaml index 50784aa5..e2735c4f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -80,7 +80,8 @@ dependencies: # Location Helper map_launcher: ^0.8.1 - + #hijri + hijri: ^2.0.3