region and access_management ui

This commit is contained in:
mohammad
2024-08-12 15:23:45 +03:00
parent cb0ebcca37
commit 3f1fdf4f93
3 changed files with 287 additions and 249 deletions

View File

@ -40,10 +40,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
if (_timer != null && _timer!.isActive) {
return;
}
_remainingTime = 60;
add(UpdateTimerEvent(
remainingTime: _remainingTime, isButtonEnabled: false));
debugPrint('_remainingTime=$_remainingTime');
_remainingTime = 1;
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
_remainingTime = (await AuthenticationAPI.sendOtp(email: forgetEmailController.text,regionUuid: regionUuid))!;
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
_remainingTime--;
@ -125,7 +123,6 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} catch (failure) {
validate='Something went wrong';
emit(const LoginFailure(error: 'Something went wrong'));
// emit(LoginFailure(error: failure.toString()));
return;
}
if (token.accessTokenIsNotEmpty) {
@ -187,6 +184,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return 'Email is required';
} else if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value)) {
return 'Enter a valid email address';
}else if (regionUuid=='') {
return 'Please select your region';
}
return null;
}

View File

@ -10,11 +10,11 @@ import 'package:syncrow_web/pages/common/first_layer.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/style.dart';
class ForgetPasswordWebPage extends StatelessWidget {
const ForgetPasswordWebPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocProvider(
create: (context) => AuthBloc()..add(RegionInitialEvent()),
@ -22,8 +22,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
listener: (context, state) {
if (state is SuccessForgetState) {
Navigator.of(context).pop();
}
else if (state is FailureForgetState) {
} else if (state is FailureForgetState) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.error),
@ -47,13 +46,15 @@ class ForgetPasswordWebPage extends StatelessWidget {
late ScrollController _scrollController;
_scrollController = ScrollController();
void _scrollToCenter() {
final double middlePosition = _scrollController.position.maxScrollExtent / 2;
final double middlePosition =
_scrollController.position.maxScrollExtent / 2;
_scrollController.animateTo(
middlePosition,
duration: const Duration(seconds: 1),
curve: Curves.easeInOut,
);
}
WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollToCenter();
});
@ -90,8 +91,10 @@ class ForgetPasswordWebPage extends StatelessWidget {
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius: const BorderRadius.all(Radius.circular(30)),
border: Border.all(color: ColorsManager.graysColor.withOpacity(0.2)),
borderRadius:
const BorderRadius.all(Radius.circular(30)),
border: Border.all(
color: ColorsManager.graysColor.withOpacity(0.2)),
),
child: Form(
key: forgetBloc.forgetFormKey,
@ -123,7 +126,8 @@ class ForgetPasswordWebPage extends StatelessWidget {
children: [
Text(
"Country/Region",
style: Theme.of(context).textTheme.bodySmall,
style:
Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 10),
SizedBox(
@ -143,20 +147,23 @@ class ForgetPasswordWebPage extends StatelessWidget {
'Select your region/country',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
),
),
isDense: true,
style: const TextStyle(color: Colors.black),
items:forgetBloc.regionList!.map((RegionModel region) {
style:
const TextStyle(color: Colors.black),
items: forgetBloc.regionList!
.map((RegionModel region) {
return DropdownMenuItem<String>(
value: region.id,
child: Text(region.name),
);
}).toList(),
onChanged: (String? value) {
forgetBloc.add(SelectRegionEvent(val: value!,));
forgetBloc.add(SelectRegionEvent(
val: value!,
));
},
),
)
@ -167,16 +174,21 @@ class ForgetPasswordWebPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Account",
style: Theme.of(context).textTheme.bodySmall,
Text(
"Account",
style:
Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.validateEmail,
controller: forgetBloc.forgetEmailController,
decoration: textBoxDecoration()!.copyWith(hintText: 'Enter your email'),
style: const TextStyle(color: Colors.black),
controller:
forgetBloc.forgetEmailController,
decoration: textBoxDecoration()!.copyWith(
hintText: 'Enter your email'),
style:
const TextStyle(color: Colors.black),
),
),
],
@ -186,13 +198,17 @@ class ForgetPasswordWebPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("One Time Password",
style: Theme.of(context).textTheme.bodySmall,),
Text(
"One Time Password",
style:
Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.validateCode,
keyboardType: TextInputType.visiblePassword,
keyboardType:
TextInputType.visiblePassword,
controller: forgetBloc.forgetOtp,
decoration: textBoxDecoration()!.copyWith(
hintText: 'Enter Code',
@ -201,13 +217,15 @@ class ForgetPasswordWebPage extends StatelessWidget {
child: Center(
child: InkWell(
onTap: () {
BlocProvider.of<AuthBloc>(context).add(StartTimerEvent());
BlocProvider.of<AuthBloc>(
context)
.add(StartTimerEvent());
},
child:
Text(
child: Text(
'Get Code ${state is TimerState && !state.isButtonEnabled ? "(${BlocProvider.of<AuthBloc>(context).formattedTime(state.remainingTime)}) " : ""}',
style: TextStyle(
color: state is TimerState && !state.isButtonEnabled
color: state is TimerState &&
!state.isButtonEnabled
? Colors.grey
: ColorsManager.btnColor,
),
@ -216,7 +234,8 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
),
),
style: const TextStyle(color: Colors.black),
style:
const TextStyle(color: Colors.black),
),
),
],
@ -226,18 +245,24 @@ class ForgetPasswordWebPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Password",
style: Theme.of(context).textTheme.bodySmall,),
Text(
"Password",
style:
Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 10),
SizedBox(
child: TextFormField(
validator: forgetBloc.passwordValidator,
keyboardType: TextInputType.visiblePassword,
controller: forgetBloc.forgetPasswordController,
keyboardType:
TextInputType.visiblePassword,
controller:
forgetBloc.forgetPasswordController,
decoration: textBoxDecoration()!.copyWith(
hintText: 'At least 8 characters',
),
style: const TextStyle(color: Colors.black),
style:
const TextStyle(color: Colors.black),
),
),
],
@ -256,7 +281,9 @@ class ForgetPasswordWebPage extends StatelessWidget {
backgroundColor: ColorsManager.btnColor,
child: const Text('Submit'),
onPressed: () {
if (forgetBloc.forgetFormKey.currentState!.validate()) {
if (forgetBloc
.forgetFormKey.currentState!
.validate()) {
forgetBloc.add(ChangePasswordEvent());
}
},
@ -265,9 +292,17 @@ class ForgetPasswordWebPage extends StatelessWidget {
],
),
const SizedBox(height: 10.0),
SizedBox(child: Text(forgetBloc.validate,
style: const TextStyle(fontWeight: FontWeight.w700,color: ColorsManager.red ),),),
SizedBox(height: 10,),
SizedBox(
child: Text(
forgetBloc.validate,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: ColorsManager.red),
),
),
SizedBox(
height: 10,
),
SizedBox(
width: size.width * 0.2,
child: Row(
@ -304,7 +339,6 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
],
),
)
);
));
}
}

View File

@ -45,33 +45,38 @@ class AuthenticationAPI {
"regionUuid": regionUuid
},
showServerMessage: true,
options: Options(),
expectedResponseModel: (json) {
Map<String, dynamic> parsedJson = jsonDecode(json);
int cooldown = parsedJson['data']['cooldown'];
debugPrint('Cooldown: $cooldown seconds');
return cooldown;
return 30;
}
);
return response;
return 30;
} on DioError catch (e) {
if (e.response != null) {
if (e.response!.statusCode == 400) {
// Handle 400 Bad Request
final errorData = e.response!.data;
String errorMessage = errorData['message'] ?? 'Unknown error';
int cooldown = errorData['data']['cooldown'] ?? 0;
String errorMessage = errorData['message'];
debugPrint('Unexpected Error: $errorMessage');
if(errorMessage=='User not found'){
return 1;
}else{
int cooldown = errorData['data']['cooldown'] ?? 1;
return cooldown;
}
} else {
debugPrint('Error: ${e.response!.statusCode} - ${e.response!.statusMessage}');
return 1;
}
} else {
debugPrint('Error: ${e.message}');
return 1;
}
return null;
return 1;
} catch (e) {
debugPrint('Unexpected Error: $e');
return null;
return 1;
}
}
@ -79,7 +84,7 @@ class AuthenticationAPI {
{required String email, required String otpCode}) async {
final response = await HTTPService().post(
path: ApiEndpoints.verifyOtp,
body: {"email": email, "type": "VERIFICATION", "otpCode": otpCode},
body: {"email": email, "type": "PASSWORD", "otpCode": otpCode},
showServerMessage: true,
expectedResponseModel: (json) {
if (json['message'] == 'Otp Verified Successfully') {