From cbd9314691ac1585f37b8b98b62a41c26a81d07e Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 20 Apr 2020 20:32:50 +0300 Subject: [PATCH] token Id finally in works --- lib/config/shared_pref_kay.dart | 1 + lib/interceptor/http_interceptor.dart | 56 ++++++++------- lib/routes.dart | 5 +- lib/widgets/auth/login_form.dart | 80 +++++++++------------- lib/widgets/auth/verfiy_account.dart | 31 +++++---- lib/widgets/auth/verification_methods.dart | 4 +- 6 files changed, 85 insertions(+), 92 deletions(-) diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart index e69de29b..21c15194 100644 --- a/lib/config/shared_pref_kay.dart +++ b/lib/config/shared_pref_kay.dart @@ -0,0 +1 @@ +final TOKEN = 'token'; \ No newline at end of file diff --git a/lib/interceptor/http_interceptor.dart b/lib/interceptor/http_interceptor.dart index 1ad980c7..009fd345 100644 --- a/lib/interceptor/http_interceptor.dart +++ b/lib/interceptor/http_interceptor.dart @@ -1,42 +1,50 @@ +import 'dart:convert'; + +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/providers/auth_provider.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:http_interceptor/http_interceptor.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); -List publicUrls = [LOGIN_URL,SELECT_DEVICE_IMEI,]; +List publicUrls = [ + LOGIN_URL, + SELECT_DEVICE_IMEI, + MEMBER_CHECK_ACTIVATION_CODE_NEW, + SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE +]; class HttpInterceptor extends InterceptorContract { Future interceptRequest({RequestData data}) async { // print('RequestData ${data.body}'); try { + print({data.headers}); data.headers["Content-Type"] = "application/json"; data.headers["Accept"] = "application/json"; - if (!publicUrls.contains(data.url)) { - var loggedUserInfo = await sharedPref.getObj('loggedUser'); - print('loggedUserInfo$loggedUserInfo'); - // the sevices handel the token in differat name so I ask to be change - // we must change the implementaion once the name are changed - if(data.body['LogInTokenID']){ - data.body['LogInTokenID'] = loggedUserInfo['LogInTokenID']; - } - if(data.body['TokenID']){ - data.body['TokenID'] = loggedUserInfo['LogInTokenID']; - } - - print('data.body${data.body}'); - - } - else { - if(data.body['LogInTokenID']){ - data.body['LogInTokenID'] = ''; - } - if(data.body['TokenID']){ - data.body['TokenID'] = ''; - } - } + // if (publicUrls.contains(data.url)) { + // var loggedUserInfo = await sharedPref.getObj('loggedUser'); + // var token = await sharedPref.getString(TOKEN); + // // print("token"+token); + // // print('loggedUserInfo${loggedUserInfo["LogInTokenID"]}'); + // // // the sevices handel the token in differat name so I ask to be change + // // // we must change the imple + // var body = json.decode(data.body); + // body['LogInTokenID']=token; + // data.body = json.encode(body); + + // // data.body['LogInTokenID'] = ''; + // } else { + // if (data.body['LogInTokenID']) { + // data.body['LogInTokenID'] = ''; + // } + // if (data.body['TokenID']) { + // data.body['TokenID'] = ''; + // } + // } } catch (e) { print(e); } + + // print('data.body${data.body}'); return data; } diff --git a/lib/routes.dart b/lib/routes.dart index b0173483..1842d9aa 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -1,6 +1,4 @@ -import 'package:doctor_app_flutter/screens/patients/patient_profile_screen.dart'; - import './screens/QR_reader_screen.dart'; import './screens/auth/change_password_screen.dart'; import './screens/auth/login_screen.dart'; @@ -11,11 +9,12 @@ import './screens/dashboard_screen.dart'; import './screens/doctor_reply_screen.dart'; import './screens/medicine/medicine_search_screen.dart'; import './screens/my_schedule_screen.dart'; +import './screens/patients/patient_profile_screen.dart'; import './screens/patients/patient_search_screen.dart'; import './screens/patients/patients_screen.dart'; import './screens/settings/settings_screen.dart'; -const String INIT_ROUTE = PATIENTS; +const String INIT_ROUTE = LOGIN; const String HOME = '/'; const String LOGIN = 'login'; const String CHANGE_PASSWORD = 'change-password'; diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index f584c11a..bc56a07d 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -6,6 +6,7 @@ import 'package:hexcolor/hexcolor.dart'; import 'package:imei_plugin/imei_plugin.dart'; import 'package:provider/provider.dart'; +import '../../config/shared_pref_kay.dart'; import '../../config/size_config.dart'; import '../../models/user_model.dart'; import '../../providers/auth_provider.dart'; @@ -67,22 +68,8 @@ class _LoginFormState extends State { buildSizedBox(), TextFormField( keyboardType: TextInputType.number, - // style: TextStyle(fontSize: 30), - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/user_id_icon.png'), - hintText: 'Enter ID', - hintStyle: TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - borderSide: BorderSide(color: Hexcolor('#CCCCCC')), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: - BorderSide(color: Theme.of(context).primaryColor), - ) - //BorderRadius.all(Radius.circular(20)); - ), + decoration: buildInputDecoration( + context, 'Enter ID', 'assets/images/user_id_icon.png'), validator: (value) { if (value.isEmpty) { return 'Please enter your ID'; @@ -96,22 +83,8 @@ class _LoginFormState extends State { buildSizedBox(), TextFormField( obscureText: true, - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/password_icon.png'), - hintText: 'Enter Password', - hintStyle: - TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - borderSide: BorderSide(color: Hexcolor('#CCCCCC')), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: - BorderSide(color: Theme.of(context).primaryColor), - ) - //BorderRadius.all(Radius.circular(20)); - ), + decoration: buildInputDecoration(context, 'Enter Password', + 'assets/images/password_icon.png'), validator: (value) { if (value.isEmpty) { return 'Please enter your Password'; @@ -130,22 +103,8 @@ class _LoginFormState extends State { }, showCursor: false, readOnly: true, - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/password_icon.png'), - hintText: 'Select your porject', - hintStyle: - TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - borderSide: BorderSide(color: Hexcolor('#CCCCCC')), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: - BorderSide(color: Theme.of(context).primaryColor), - ) - //BorderRadius.all(Radius.circular(20)); - ), + decoration: buildInputDecoration(context, 'Select your porject', + 'assets/images/password_icon.png'), validator: (value) { if (value.isEmpty) { return 'Please enter your porject'; @@ -207,6 +166,28 @@ class _LoginFormState extends State { ); } +/* + *@author: Elham Rababah + *@Date:20/4/2020 + *@param: context, hint, asset + *@return: InputDecoration + *@desc: decorate input feilds + */ + InputDecoration buildInputDecoration(BuildContext context, hint, asset) { + return InputDecoration( + prefixIcon: Image.asset(asset), + hintText: hint, + hintStyle: TextStyle(fontSize: 2 * SizeConfig.textMultiplier), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(20)), + borderSide: BorderSide(color: Hexcolor('#CCCCCC')), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0)), + borderSide: BorderSide(color: Theme.of(context).primaryColor), + )); + } + SizedBox buildSizedBox() { return SizedBox( height: 20, @@ -223,6 +204,9 @@ class _LoginFormState extends State { if (res['MessageStatus'] == 1) { // insertDeviceImei(res, authProv); saveObjToString('loggedUser', res); + sharedPref.setString(TOKEN, res['LogInTokenID']); + print("token" + res['LogInTokenID']); + Navigator.of(context).pushNamed(VERIFICATION_METHODS); } else { // handel error diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart index e26c342b..e4e4d787 100644 --- a/lib/widgets/auth/verfiy_account.dart +++ b/lib/widgets/auth/verfiy_account.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; @@ -90,7 +91,6 @@ class _VerifyAccountState extends State { child: TextFormField( maxLength: 1, textAlign: TextAlign.center, - style: buildTextStyle(), keyboardType: TextInputType.number, decoration: @@ -256,8 +256,8 @@ class _VerifyAccountState extends State { Map model = { "activationCode": activationCode, - "DoctorID": _loggedUser['List_MemberInformation'][0]['MemberID'], - "LogInTokenID": _loggedUser['LogInTokenID'], + "DoctorID": _loggedUser['DoctorID'], + // "LogInTokenID": _loggedUser['LogInTokenID'], "ProjectID": 15, "LanguageID": 2, "stamp": "2020-02-26T14:48:27.221Z", @@ -272,19 +272,20 @@ class _VerifyAccountState extends State { changeLoadingStata(true); Navigator.of(context).pushNamed(HOME); - // authProv.memberCheckActivationCodeNew(model).then((res) { - // changeLoadingStata(false); - // if (res['MessageStatus'] == 1) { - // Navigator.of(context).pushNamed(HOME); - // } else { - // helpers.showErrorToast(res['ErrorEndUserMessage']); - // } - // }).catchError((err) { - // changeLoadingStata(false); + authProv.memberCheckActivationCodeNew(model).then((res) { + changeLoadingStata(false); + if (res['MessageStatus'] == 1) { + sharedPref.setString(TOKEN, res['AuthenticationTokenID']); + Navigator.of(context).pushNamed(HOME); + } else { + helpers.showErrorToast(res['ErrorEndUserMessage']); + } + }).catchError((err) { + changeLoadingStata(false); - // print('$err'); - // helpers.showErrorToast(); - // }); + print('$err'); + helpers.showErrorToast(); + }); } else { // changeLoadingStata(false); } diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 68bc464c..e4fad904 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -188,8 +188,8 @@ class _VerificationMethodsState extends State { "UserName": _loggedUser['List_MemberInformation'][0]['MemberID'], "OTP_SendType": oTPSendType }; - print('$_loggedUser'); - print(oTPSendType); + // print('$_loggedUser'); + // print(oTPSendType); authProv.sendActivationCodeByOtpNotificationType(model).then((res) { // Navigator.of(context).pushNamed(VERIFY_ACCOUNT); widget.changeLoadingStata(false);