mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-03-11 09:51:45 +00:00
Compare commits
4 Commits
sp-231
...
forgetpass
| Author | SHA1 | Date | |
|---|---|---|---|
| 76be98354b | |||
| 3418fbe7b4 | |||
| e63bf2a2c2 | |||
| b3bb0b9eea |
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
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';
|
||||||
@ -59,18 +58,30 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
|
|
||||||
/////////////////////////////////////VALIDATORS/////////////////////////////////////
|
/////////////////////////////////////VALIDATORS/////////////////////////////////////
|
||||||
String? passwordValidator(String? value) {
|
String? passwordValidator(String? value) {
|
||||||
if (value != null) {
|
if (value == null || value.isEmpty) {
|
||||||
if (value.isEmpty) {
|
return "Please enter your password";
|
||||||
return 'Please enter your password';
|
|
||||||
}
|
|
||||||
if (value.isNotEmpty) {
|
|
||||||
if (!RegExp(
|
|
||||||
r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~])[A-Za-z\d!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]{8,}$')
|
|
||||||
.hasMatch(value)) {
|
|
||||||
return 'Password must contain at least:\n - one uppercase letter.\n - one lowercase letter.\n - one number. \n - special character';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value.length < 8) {
|
||||||
|
return 'Password must be at least 8 characters long';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!RegExp(r'[a-z]').hasMatch(value)) {
|
||||||
|
return 'Password must contain at least one lowercase letter';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!RegExp(r'[A-Z]').hasMatch(value)) {
|
||||||
|
return 'Password must contain at least one uppercase letter';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!RegExp(r'\d').hasMatch(value)) {
|
||||||
|
return 'Password must contain at least one number';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').hasMatch(value)) {
|
||||||
|
return 'Password must contain at least one special character';
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,13 +193,10 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
debugPrint('token: ${token.accessToken}');
|
debugPrint('token: ${token.accessToken}');
|
||||||
FlutterSecureStorage storage = const FlutterSecureStorage();
|
FlutterSecureStorage storage = const FlutterSecureStorage();
|
||||||
await storage.write(
|
await storage.write(
|
||||||
key: Token.loginAccessTokenKey,
|
key: Token.loginAccessTokenKey, value: token.accessToken);
|
||||||
value: token.accessToken
|
|
||||||
);
|
|
||||||
const FlutterSecureStorage().write(
|
const FlutterSecureStorage().write(
|
||||||
key: UserModel.userUuidKey,
|
key: UserModel.userUuidKey,
|
||||||
value: Token.decodeToken(token.accessToken)['uuid'].toString()
|
value: Token.decodeToken(token.accessToken)['uuid'].toString());
|
||||||
);
|
|
||||||
user = UserModel.fromToken(token);
|
user = UserModel.fromToken(token);
|
||||||
emailController.clear();
|
emailController.clear();
|
||||||
passwordController.clear();
|
passwordController.clear();
|
||||||
@ -225,7 +233,8 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
sendOtp() async {
|
sendOtp() async {
|
||||||
try {
|
try {
|
||||||
emit(AuthLoading());
|
emit(AuthLoading());
|
||||||
await AuthenticationAPI.sendOtp(body: {'email': email, 'type': 'VERIFICATION'});
|
await AuthenticationAPI.sendOtp(
|
||||||
|
body: {'email': email, 'type': 'VERIFICATION'});
|
||||||
emit(AuthSignUpSuccess());
|
emit(AuthSignUpSuccess());
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
emit(AuthLoginError(message: 'Something went wrong'));
|
emit(AuthLoginError(message: 'Something went wrong'));
|
||||||
@ -235,7 +244,8 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
reSendOtp() async {
|
reSendOtp() async {
|
||||||
try {
|
try {
|
||||||
emit(AuthLoading());
|
emit(AuthLoading());
|
||||||
await AuthenticationAPI.sendOtp(body: {'email': email, 'type': 'VERIFICATION'});
|
await AuthenticationAPI.sendOtp(
|
||||||
|
body: {'email': email, 'type': 'VERIFICATION'});
|
||||||
emit(ResendOtpSuccess());
|
emit(ResendOtpSuccess());
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
emit(AuthLoginError(message: 'Something went wrong'));
|
emit(AuthLoginError(message: 'Something went wrong'));
|
||||||
@ -282,13 +292,16 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
try {
|
try {
|
||||||
emit(AuthTokenLoading());
|
emit(AuthTokenLoading());
|
||||||
const storage = FlutterSecureStorage();
|
const storage = FlutterSecureStorage();
|
||||||
final firstLaunch = await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
|
final firstLaunch = await SharedPreferencesHelper.readBoolFromSP(
|
||||||
|
StringsManager.firstLaunch) ??
|
||||||
|
true;
|
||||||
|
|
||||||
if (firstLaunch) {
|
if (firstLaunch) {
|
||||||
storage.deleteAll();
|
storage.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
|
await SharedPreferencesHelper.saveBoolToSP(
|
||||||
|
StringsManager.firstLaunch, false);
|
||||||
|
|
||||||
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
@ -315,7 +328,6 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sendToForgetPassword({required String password}) async {
|
sendToForgetPassword({required String password}) async {
|
||||||
try {
|
try {
|
||||||
emit(AuthForgetPassLoading());
|
emit(AuthForgetPassLoading());
|
||||||
@ -325,8 +337,4 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
emit(AuthForgetPassError(message: 'Something went wrong'));
|
emit(AuthForgetPassError(message: 'Something went wrong'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
bool isStartEndTime = true;
|
bool isStartEndTime = true;
|
||||||
DateTime? startTime;
|
DateTime? startTime;
|
||||||
DateTime? endTime;
|
DateTime? endTime;
|
||||||
|
int unlockRequest = 0;
|
||||||
List<TemporaryPassword>? temporaryPasswords = [];
|
List<TemporaryPassword>? temporaryPasswords = [];
|
||||||
List<OfflinePasswordModel>? oneTimePasswords = [];
|
List<OfflinePasswordModel>? oneTimePasswords = [];
|
||||||
List<OfflinePasswordModel>? timeLimitPasswords = [];
|
List<OfflinePasswordModel>? timeLimitPasswords = [];
|
||||||
@ -128,6 +129,7 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_doorLockUpdated(DoorLockUpdated event, Emitter<SmartDoorState> emit) {
|
_doorLockUpdated(DoorLockUpdated event, Emitter<SmartDoorState> emit) {
|
||||||
|
unlockRequest = deviceStatus.unlockRequest;
|
||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,47 +31,36 @@ class _DoorLockButtonState extends State<DoorLockButton> with SingleTickerProvid
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_animationController = AnimationController(
|
_animationController = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
value: smartDoorModel.unlockRequest > 0 ? 1 : 0,
|
value: context.read<SmartDoorBloc>().unlockRequest > 0 ? 1 : 0,
|
||||||
duration: Duration(seconds: smartDoorModel.unlockRequest),
|
duration: Duration(seconds: context.read<SmartDoorBloc>().unlockRequest),
|
||||||
);
|
);
|
||||||
if (smartDoorModel.unlockRequest > 0) {
|
if (context.read<SmartDoorBloc>().unlockRequest > 0) {
|
||||||
_animationController.reverse();
|
_animationController.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
_animation = Tween<double>(begin: 0, end: 1).animate(_animationController)
|
_animation = Tween<double>(begin: 0, end: 1).animate(_animationController)
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
// if (_animation.status == AnimationStatus.completed) {
|
|
||||||
// if (widget.doorLock.status
|
|
||||||
// .firstWhere((element) => element.code == 'normal_open_switch')
|
|
||||||
// .value !=
|
|
||||||
// true) {
|
|
||||||
// DevicesCubit.getInstance().deviceControl(
|
|
||||||
// DeviceControlModel(
|
|
||||||
// deviceId: widget.doorLock.uuid, code: 'normal_open_switch', value: true),
|
|
||||||
// widget.doorLock.uuid ?? "");
|
|
||||||
// }
|
|
||||||
// BlocProvider.of<SmartDoorBloc>(context)
|
|
||||||
// .add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch));
|
|
||||||
// _animationController.reverse();
|
|
||||||
// }
|
|
||||||
// } else if (_animation.status == AnimationStatus.dismissed) {
|
|
||||||
// // if (widget.doorLock.status
|
|
||||||
// // .firstWhere((element) => element.code == 'normal_open_switch')
|
|
||||||
// // .value !=
|
|
||||||
// // false) {
|
|
||||||
// DevicesCubit.getInstance().deviceControl(
|
|
||||||
// DeviceControlModel(
|
|
||||||
// deviceId: widget.doorLock.uuid, code: 'normal_open_switch', value: false),
|
|
||||||
// widget.doorLock.uuid ?? "");
|
|
||||||
// // }
|
|
||||||
// _animationController.forward();
|
|
||||||
// }
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(DoorLockButton oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
|
if (_animationController.status == AnimationStatus.dismissed) {
|
||||||
|
if (context.read<SmartDoorBloc>().unlockRequest > 0) {
|
||||||
|
_animationController.value = 1;
|
||||||
|
_animationController.duration =
|
||||||
|
Duration(seconds: context.read<SmartDoorBloc>().unlockRequest);
|
||||||
|
_animationController.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_animationController.dispose();
|
_animationController.dispose();
|
||||||
@ -100,7 +89,7 @@ class _DoorLockButtonState extends State<DoorLockButton> with SingleTickerProvid
|
|||||||
// } else if (_animationController.status == AnimationStatus.reverse) {
|
// } else if (_animationController.status == AnimationStatus.reverse) {
|
||||||
// _animationController.forward();
|
// _animationController.forward();
|
||||||
// }
|
// }
|
||||||
if (smartDoorModel.unlockRequest > 0) {
|
if (context.read<SmartDoorBloc>().unlockRequest > 0) {
|
||||||
BlocProvider.of<SmartDoorBloc>(context)
|
BlocProvider.of<SmartDoorBloc>(context)
|
||||||
.add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch));
|
.add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user