forget password changes & bugs number 10 & 15-18

This commit is contained in:
mohammad
2024-09-02 10:16:28 +03:00
parent 3ff6937116
commit ddcdd4891a
12 changed files with 180 additions and 160 deletions

View File

@ -38,6 +38,7 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
HomeBloc.fetchUserInfo();
return MultiBlocProvider( return MultiBlocProvider(
providers: [ providers: [
BlocProvider(create: (context) => HomeBloc()), BlocProvider(create: (context) => HomeBloc()),
@ -57,6 +58,7 @@ class MyApp extends StatelessWidget {
), ),
theme: myTheme, theme: myTheme,
routerConfig: _router, routerConfig: _router,
)); )
);
} }
} }

View File

@ -38,13 +38,23 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
style: Theme.of(context).textTheme.headlineLarge, style: Theme.of(context).textTheme.headlineLarge,
), ),
), ),
centerBody: Text( centerBody: Wrap(
children: [
Padding(
padding: EdgeInsets.only(left: MediaQuery.of(context).size.width*0.09),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
'Physical Access', 'Physical Access',
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.headlineMedium! .headlineMedium!
.copyWith(color: Colors.white), .copyWith(color: Colors.white),
), ),
),
),
],
),
rightBody: const NavigateHomeGridView(), rightBody: const NavigateHomeGridView(),
scaffoldBody: BlocProvider( scaffoldBody: BlocProvider(
create: (BuildContext context) => create: (BuildContext context) =>
@ -82,6 +92,7 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
const SizedBox(height: 20), const SizedBox(height: 20),
Expanded( Expanded(
child: DynamicTable( child: DynamicTable(
withSelectAll: false,
isEmpty: filteredData.isEmpty, isEmpty: filteredData.isEmpty,
withCheckBox: false, withCheckBox: false,
size: MediaQuery.of(context).size, size: MediaQuery.of(context).size,
@ -113,8 +124,7 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
}))); })));
} }
Wrap _buildVisitorAdminPasswords( Wrap _buildVisitorAdminPasswords(BuildContext context, AccessBloc accessBloc) {
BuildContext context, AccessBloc accessBloc) {
return Wrap( return Wrap(
spacing: 10, spacing: 10,
runSpacing: 10, runSpacing: 10,
@ -171,15 +181,14 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout {
width: 250, width: 250,
child: CustomWebTextField( child: CustomWebTextField(
controller: accessBloc.passwordName, controller: accessBloc.passwordName,
height: 38, height: 43,
isRequired: true, isRequired: false,
textFieldName: 'Name', textFieldName: 'Name',
description: '', description: '',
), ),
), ),
const SizedBox(width: 15), const SizedBox(width: 15),
SizedBox( SizedBox(
height: 70,
child: DateTimeWebWidget( child: DateTimeWebWidget(
icon: Assets.calendarIcon, icon: Assets.calendarIcon,
isRequired: false, isRequired: false,

View File

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
@ -81,21 +82,25 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
_timer?.cancel(); _timer?.cancel();
emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
emit(SuccessForgetState()); emit(SuccessForgetState());
} else if (response == "You entered wrong otp") { }
}
on DioException catch (e) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
if(errorMessage=='this email is not registered'){
validate='Invalid Credentials!';
emit(AuthInitialState());
}else if (errorMessage == "You entered wrong otp") {
forgetValidate = 'Wrong one time password.'; forgetValidate = 'Wrong one time password.';
emit(AuthInitialState()); emit(AuthInitialState());
} else if (response == "OTP expired") { } else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.'; forgetValidate = 'One time password has been expired.';
emit(AuthInitialState()); emit(AuthInitialState());
} }
} catch (failure) {
// forgetValidate='Invalid Credentials!';
emit(AuthInitialState());
// emit(FailureForgetState(error: failure.toString()));
} }
} }
//925207
String? validateCode(String? value) { String? validateCode(String? value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'Code is required'; return 'Code is required';
@ -177,15 +182,15 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
emit(LoginInitial()); emit(LoginInitial());
} }
checkOtpCode( // checkOtpCode(
ChangePasswordEvent event, // ChangePasswordEvent event,
Emitter<AuthState> emit, // Emitter<AuthState> emit,
) async { // ) async {
emit(LoadingForgetState()); // emit(LoadingForgetState());
await AuthenticationAPI.verifyOtp( // await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text); // email: forgetEmailController.text, otpCode: forgetOtp.text);
emit(SuccessForgetState()); // emit(SuccessForgetState());
} // }
void _passwordVisible(PasswordVisibleEvent event, Emitter<AuthState> emit) { void _passwordVisible(PasswordVisibleEvent event, Emitter<AuthState> emit) {
emit(AuthLoading()); emit(AuthLoading());

View File

@ -346,8 +346,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
if (forgetBloc if (forgetBloc
.forgetFormKey.currentState! .forgetFormKey.currentState!
.validate()) { .validate()) {
forgetBloc forgetBloc.add(ChangePasswordEvent());
.add(ChangePasswordEvent());
} }
}, },
), ),
@ -355,7 +354,8 @@ class ForgetPasswordWebPage extends StatelessWidget {
], ],
), ),
const SizedBox(height: 10.0), const SizedBox(height: 10.0),
SizedBox( Center(
child: SizedBox(
child: Text( child: Text(
forgetBloc.validate, forgetBloc.validate,
style: const TextStyle( style: const TextStyle(
@ -363,6 +363,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
color: ColorsManager.red), color: ColorsManager.red),
), ),
), ),
),
SizedBox( SizedBox(
height: 10, height: 10,
), ),

View File

@ -10,6 +10,7 @@ class DynamicTable extends StatefulWidget {
final BoxDecoration? cellDecoration; final BoxDecoration? cellDecoration;
final Size size; final Size size;
final bool withCheckBox; final bool withCheckBox;
final bool withSelectAll;
final bool isEmpty; final bool isEmpty;
final void Function(bool?)? selectAll; final void Function(bool?)? selectAll;
final void Function(int, bool, dynamic)? onRowSelected; final void Function(int, bool, dynamic)? onRowSelected;
@ -21,6 +22,7 @@ class DynamicTable extends StatefulWidget {
required this.size, required this.size,
required this.isEmpty, required this.isEmpty,
required this.withCheckBox, required this.withCheckBox,
required this.withSelectAll,
this.headerDecoration, this.headerDecoration,
this.cellDecoration, this.cellDecoration,
this.selectAll, this.selectAll,
@ -34,6 +36,7 @@ class DynamicTable extends StatefulWidget {
class _DynamicTableState extends State<DynamicTable> { class _DynamicTableState extends State<DynamicTable> {
late List<bool> _selected; late List<bool> _selected;
bool _selectAll = false;
@override @override
void initState() { void initState() {
@ -54,6 +57,17 @@ class _DynamicTableState extends State<DynamicTable> {
}); });
} }
void _toggleSelectAll(bool? value) {
setState(() {
_selectAll = value ?? false;
_selected = List<bool>.filled(widget.data.length, _selectAll);
if (widget.selectAll != null) {
widget.selectAll!(_selectAll);
}
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -148,7 +162,7 @@ class _DynamicTableState extends State<DynamicTable> {
), ),
child: Checkbox( child: Checkbox(
value: _selected.every((element) => element == true), value: _selected.every((element) => element == true),
onChanged: null, onChanged:widget.withSelectAll?_toggleSelectAll:null,
), ),
); );
} }

View File

@ -32,21 +32,19 @@ class CustomWebTextField extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
if (isRequired)
Row( Row(
children: [ children: [
Text( if (isRequired)
'* ', Text('* ',
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme.bodyMedium!
.bodyMedium!
.copyWith(color: Colors.red), .copyWith(color: Colors.red),
), ),
Text( Text(
textFieldName, textFieldName,
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme.bodySmall!
.bodySmall!
.copyWith(color: Colors.black, fontSize: 13), .copyWith(color: Colors.black, fontSize: 13),
), ),
], ],
@ -70,15 +68,17 @@ class CustomWebTextField extends StatelessWidget {
), ),
Container( Container(
height: height ?? 35, height: height ?? 35,
decoration: containerDecoration decoration: containerDecoration.copyWith(
.copyWith(color: const Color(0xFFF5F6F7), boxShadow: [ color: const Color(0xFFF5F6F7),
boxShadow: [
BoxShadow( BoxShadow(
color: Colors.grey.withOpacity(0.3), color: Colors.grey.withOpacity(0.3),
spreadRadius: 2, spreadRadius: 2,
blurRadius: 3, blurRadius: 3,
offset: const Offset(1, 1), // changes position of shadow offset: const Offset(1, 1), // changes position of shadow
), ),
]), ]
),
child: TextFormField( child: TextFormField(
validator: validator, validator: validator,
controller: controller, controller: controller,

View File

@ -51,10 +51,9 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
'Low Battery ($lowBatteryCount)', 'Low Battery ($lowBatteryCount)',
]; ];
return CustomScrollView( return Column(
slivers: [ children: [
SliverToBoxAdapter( Container(
child: Container(
padding: isLargeScreenSize(context) padding: isLargeScreenSize(context)
? const EdgeInsets.all(30) ? const EdgeInsets.all(30)
: const EdgeInsets.all(15), : const EdgeInsets.all(15),
@ -66,8 +65,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
tabs: tabs, tabs: tabs,
selectedIndex: selectedIndex, selectedIndex: selectedIndex,
onTabChanged: (index) { onTabChanged: (index) {
context context.read<DeviceManagementBloc>()
.read<DeviceManagementBloc>()
.add(SelectedFilterChanged(index)); .add(SelectedFilterChanged(index));
}, },
), ),
@ -84,8 +82,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
? () { ? () {
final selectedDevice = context final selectedDevice = context
.read<DeviceManagementBloc>() .read<DeviceManagementBloc>()
.selectedDevices .selectedDevices.first;
.first;
showDialog( showDialog(
context: context, context: context,
builder: (context) => DeviceControlDialog( builder: (context) => DeviceControlDialog(
@ -109,13 +106,13 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
], ],
), ),
), ),
), Expanded(
SliverFillRemaining(
child: Padding( child: Padding(
padding: isLargeScreenSize(context) padding: isLargeScreenSize(context)
? const EdgeInsets.all(30) ? const EdgeInsets.all(30)
: const EdgeInsets.all(15), : const EdgeInsets.all(15),
child: DynamicTable( child: DynamicTable(
withSelectAll: false,
cellDecoration: containerDecoration, cellDecoration: containerDecoration,
onRowSelected: (index, isSelected, row) { onRowSelected: (index, isSelected, row) {
final selectedDevice = devicesToShow[index]; final selectedDevice = devicesToShow[index];

View File

@ -43,6 +43,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
try { try {
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey); var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
user = await HomeApi().fetchUserInfo(uuid); user = await HomeApi().fetchUserInfo(uuid);
} catch (e) { } catch (e) {
return; return;
} }

View File

@ -40,7 +40,7 @@ class AddDeviceDialog extends StatelessWidget {
fontSize: 24, fontSize: 24,
color: Colors.black), color: Colors.black),
), ),
content: Container( content: SizedBox(
height: MediaQuery.of(context).size.height / 1.7, height: MediaQuery.of(context).size.height / 1.7,
width: MediaQuery.of(context).size.width / 2, width: MediaQuery.of(context).size.width / 2,
child: Padding( child: Padding(
@ -78,7 +78,7 @@ class AddDeviceDialog extends StatelessWidget {
), ),
], ],
)), )),
SizedBox( const SizedBox(
height: 20, height: 20,
), ),
const SizedBox( const SizedBox(
@ -93,7 +93,7 @@ class AddDeviceDialog extends StatelessWidget {
flex: 4, flex: 4,
child: CustomWebTextField( child: CustomWebTextField(
controller: visitorBloc.deviceNameController, controller: visitorBloc.deviceNameController,
isRequired: true, isRequired: false,
textFieldName: 'Device Name', textFieldName: 'Device Name',
description: '', description: '',
), ),
@ -103,7 +103,7 @@ class AddDeviceDialog extends StatelessWidget {
flex: 4, flex: 4,
child: CustomWebTextField( child: CustomWebTextField(
controller: visitorBloc.deviceIdController, controller: visitorBloc.deviceIdController,
isRequired: true, isRequired: false,
textFieldName: 'Device ID', textFieldName: 'Device ID',
description: '', description: '',
), ),
@ -113,7 +113,7 @@ class AddDeviceDialog extends StatelessWidget {
flex: 4, flex: 4,
child: CustomWebTextField( child: CustomWebTextField(
controller: visitorBloc.unitNameController, controller: visitorBloc.unitNameController,
isRequired: true, isRequired: false,
textFieldName: 'Unit Name', textFieldName: 'Unit Name',
description: '', description: '',
), ),
@ -168,14 +168,15 @@ class AddDeviceDialog extends StatelessWidget {
flex: 3, flex: 3,
child: state is TableLoaded child: state is TableLoaded
? DynamicTable( ? DynamicTable(
withSelectAll: true,
initialSelectedIds: selectedDeviceIds, initialSelectedIds: selectedDeviceIds,
cellDecoration: containerDecoration, cellDecoration: containerDecoration,
isEmpty: visitorBloc.data.isEmpty, isEmpty: visitorBloc.data.isEmpty,
selectAll: (p0) { selectAll: (p0) {
visitorBloc.selectedDeviceIds.clear(); visitorBloc.selectedDeviceIds.clear();
for (var item in state.data) { for (var item in state.data) {
visitorBloc visitorBloc.add(SelectDeviceEvent(item.uuid));
.add(SelectDeviceEvent(item.uuid));
} }
}, },
onRowSelected: (index, isSelected, row) { onRowSelected: (index, isSelected, row) {
@ -200,8 +201,7 @@ class AddDeviceDialog extends StatelessWidget {
item.online.value.toString(), item.online.value.toString(),
]; ];
}).toList(), }).toList(),
) ) : const Center(child: CircularProgressIndicator()))
: const Center(child: CircularProgressIndicator()))
], ],
), ),
), ),

View File

@ -323,8 +323,7 @@ class VisitorPasswordDialog extends StatelessWidget {
: visitorBloc.usageFrequencySelected, : visitorBloc.usageFrequencySelected,
onChanged: (String? value) { onChanged: (String? value) {
if (value != null) { if (value != null) {
context context.read<VisitorPasswordBloc>()
.read<VisitorPasswordBloc>()
.add(SelectUsageFrequency(value)); .add(SelectUsageFrequency(value));
} }
}, },
@ -344,7 +343,7 @@ class VisitorPasswordDialog extends StatelessWidget {
if (visitorBloc.usageFrequencySelected == 'One-Time' && if (visitorBloc.usageFrequencySelected == 'One-Time' &&
visitorBloc.accessTypeSelected == 'Offline Password') visitorBloc.accessTypeSelected == 'Offline Password')
Text( Text(
'Within the validity period, there is no limit to the number of times each device can be unlocked.', 'Within the validity period, each device can be unlocked only once, and the maximum validity period is 6 hours',
style: Theme.of(context).textTheme.bodySmall!.copyWith( style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor, fontSize: 9), color: ColorsManager.grayColor, fontSize: 9),
), ),

View File

@ -25,7 +25,9 @@ class AuthenticationAPI {
path: ApiEndpoints.forgetPassword, path: ApiEndpoints.forgetPassword,
body: {"email": email, "password": password}, body: {"email": email, "password": password},
showServerMessage: true, showServerMessage: true,
expectedResponseModel: (json) {}); expectedResponseModel: (json) {
print('json=$json');
});
return response; return response;
} }
@ -66,7 +68,6 @@ class AuthenticationAPI {
} }
static Future verifyOtp({required String email, required String otpCode}) async { static Future verifyOtp({required String email, required String otpCode}) async {
try {
final response = await HTTPService().post( final response = await HTTPService().post(
path: ApiEndpoints.verifyOtp, path: ApiEndpoints.verifyOtp,
body: {"email": email, "type": "PASSWORD", "otpCode": otpCode}, body: {"email": email, "type": "PASSWORD", "otpCode": otpCode},
@ -79,17 +80,7 @@ class AuthenticationAPI {
} }
}); });
return response; return response;
} on DioException catch (e) {
if (e.response != null) {
if (e.response!.statusCode == 400) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
return errorMessage;
}
} else {
debugPrint('Error: ${e.message}');
}
}
} }
static Future<List<RegionModel>> fetchRegion() async { static Future<List<RegionModel>> fetchRegion() async {

View File

@ -8,6 +8,7 @@ class HomeApi {
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId!), path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId!),
showServerMessage: true, showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
print('fetchUserInfo$json');
return UserModel.fromJson(json); return UserModel.fromJson(json);
}); });
return response; return response;