fix: 1,开锁页-设置-基本信息-管理员开锁密码 现可修改成密码列表里已有的密码,应不能改 2,修改管理员密码框内有旧密码问题修改
This commit is contained in:
parent
4c3da6d194
commit
130dd8be8f
@ -1,9 +1,9 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
||||
import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart';
|
||||
|
||||
import '../../../../../blue/blue_manage.dart';
|
||||
import '../../../../../blue/io_protocol/io_changeAdministratorPassword.dart';
|
||||
@ -18,14 +18,16 @@ import '../../../../../tools/eventBusEventManage.dart';
|
||||
import '../../../../../tools/storage.dart';
|
||||
import 'adminOpenLockPassword_state.dart';
|
||||
|
||||
class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
class AdminOpenLockPasswordLogic extends BaseGetXController {
|
||||
final AdminOpenLockPasswordState state = AdminOpenLockPasswordState();
|
||||
|
||||
// 获取解析后的数据
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
void _initReplySubscription() {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
if (reply is ChangeAdministratorPasswordReply && state.ifCurrentScreen.value == true) {
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
if (reply is ChangeAdministratorPasswordReply &&
|
||||
state.ifCurrentScreen.value == true) {
|
||||
_replyChangeAdministratorPassword(reply);
|
||||
}
|
||||
|
||||
@ -49,11 +51,14 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<String>? signKey =
|
||||
await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? privateKey =
|
||||
await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList =
|
||||
changeStringListToIntList(privateKey!);
|
||||
|
||||
final List<int> token = reply.data.sublist(5, 9);
|
||||
final List<String> saveStrList = changeIntListToStringList(token);
|
||||
@ -63,7 +68,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
pwdNo: state.lockBasicInfo.value.lockUserNo!,
|
||||
pwd:state.changePwdController.text,
|
||||
pwd: state.changePwdController.text,
|
||||
useCountLimit: 0xffff,
|
||||
startTime: 0,
|
||||
endTime: 0,
|
||||
@ -179,23 +184,27 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
|
||||
// 修改管理员密码(同添加自定义开锁密码,指纹/密码/卡片前5个是管理员)
|
||||
Future<void> changeAdministratorPasswordCommand() async {
|
||||
if(state.sureBtnState.value == 1){
|
||||
if (state.sureBtnState.value == 1) {
|
||||
return;
|
||||
}
|
||||
state.sureBtnState.value = 1;
|
||||
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: (){
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
state.sureBtnState.value = 0;
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<String>? signKey =
|
||||
await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? privateKey =
|
||||
await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList =
|
||||
changeStringListToIntList(privateKey!);
|
||||
|
||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||
@ -204,7 +213,7 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
pwdNo: state.lockBasicInfo.value.lockUserNo!,
|
||||
pwd:state.changePwdController.text,
|
||||
pwd: state.changePwdController.text,
|
||||
useCountLimit: 0xffff,
|
||||
startTime: 0,
|
||||
endTime: 0,
|
||||
@ -213,11 +222,12 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
signKey: signKeyDataList,
|
||||
privateKey: getPrivateKeyList,
|
||||
token: getTokenList);
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
state.sureBtnState.value = 0;
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
if(state.ifCurrentScreen.value == true){
|
||||
if (state.ifCurrentScreen.value == true) {
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
}
|
||||
@ -226,25 +236,62 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
|
||||
// 更新管理员密码
|
||||
Future<void> addLockAdminPassword(bool isChange) async {
|
||||
final GetServerDatetimeEntity entity = await ApiRepository.to.setAdminPasswordData(
|
||||
final GetServerDatetimeEntity entity =
|
||||
await ApiRepository.to.setAdminPasswordData(
|
||||
lockId: state.lockSetInfoData.value.lockBasicInfo!.lockId!,
|
||||
adminPwd: state.adminPwd.value,
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
if(isChange == true){
|
||||
showToast('修改成功'.tr, something: (){
|
||||
if (isChange == true) {
|
||||
showToast('修改成功'.tr, something: () {
|
||||
state.lockBasicInfo.value.adminPwd = state.adminPwd.value;
|
||||
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
eventBus.fire(
|
||||
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
});
|
||||
}else{
|
||||
showToast('上传成功'.tr, something: (){
|
||||
} else {
|
||||
showToast('上传成功'.tr, something: () {
|
||||
state.lockBasicInfo.value.adminPwd = state.adminPwd.value;
|
||||
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
eventBus.fire(
|
||||
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 检查管理员密码是否重复
|
||||
///
|
||||
/// 返回值:
|
||||
/// - true: 密码不重复,可以使用
|
||||
/// - false: 密码重复,不可使用
|
||||
Future<bool> checkPassword() async {
|
||||
try {
|
||||
if (state.lockSetInfoData.value.lockBasicInfo?.lockId == null) {
|
||||
showToast('锁ID不能为空'.tr);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state.adminPwd.value.isEmpty) {
|
||||
showToast('密码不能为空'.tr);
|
||||
return false;
|
||||
}
|
||||
|
||||
final PasswordKeyEntity entity = await ApiRepository.to.checkAdminPwd(
|
||||
lockId: state.lockSetInfoData.value.lockBasicInfo!.lockId!,
|
||||
adminPwd: state.changePwdController.text,
|
||||
);
|
||||
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
return true;
|
||||
} else {
|
||||
showToast(entity.errorMsg ?? '已存在相同的密码,请更换。');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
showToast('检查密码失败'.tr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
@ -257,5 +304,4 @@ class AdminOpenLockPasswordLogic extends BaseGetXController{
|
||||
super.onClose();
|
||||
_replySubscription.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
@ -16,12 +15,16 @@ class AdminOpenLockPasswordPage extends StatefulWidget {
|
||||
const AdminOpenLockPasswordPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AdminOpenLockPasswordPage> createState() => _AdminOpenLockPasswordPageState();
|
||||
State<AdminOpenLockPasswordPage> createState() =>
|
||||
_AdminOpenLockPasswordPageState();
|
||||
}
|
||||
|
||||
class _AdminOpenLockPasswordPageState extends State<AdminOpenLockPasswordPage> with RouteAware {
|
||||
final AdminOpenLockPasswordLogic logic = Get.put(AdminOpenLockPasswordLogic());
|
||||
final AdminOpenLockPasswordState state = Get.find<AdminOpenLockPasswordLogic>().state;
|
||||
class _AdminOpenLockPasswordPageState extends State<AdminOpenLockPasswordPage>
|
||||
with RouteAware {
|
||||
final AdminOpenLockPasswordLogic logic =
|
||||
Get.put(AdminOpenLockPasswordLogic());
|
||||
final AdminOpenLockPasswordState state =
|
||||
Get.find<AdminOpenLockPasswordLogic>().state;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -95,16 +98,23 @@ class _AdminOpenLockPasswordPageState extends State<AdminOpenLockPasswordPage> w
|
||||
LengthLimitingTextInputFormatter(9),
|
||||
],
|
||||
controller: state.changePwdController,
|
||||
sureClick: () {
|
||||
if(state.changePwdController.text.length < 6){
|
||||
sureClick: () async {
|
||||
if (state.changePwdController.text.length < 6) {
|
||||
logic.showToast('请输入6-9位管理员密码'.tr);
|
||||
return;
|
||||
}
|
||||
|
||||
if(state.changePwdController.text == state.lockBasicInfo.value.adminPwd!){
|
||||
if (state.changePwdController.text ==
|
||||
state.lockBasicInfo.value.adminPwd!) {
|
||||
logic.showToast('请输入新的管理员密码'.tr);
|
||||
return;
|
||||
}
|
||||
// 检查密码是否重复
|
||||
final bool isPasswordAvailable = await logic.checkPassword();
|
||||
if (!isPasswordAvailable) {
|
||||
return; // 如果密码重复,直接返回
|
||||
}
|
||||
|
||||
Get.back();
|
||||
logic.changeAdministratorPasswordCommand();
|
||||
},
|
||||
|
||||
@ -49,6 +49,8 @@ abstract class Api {
|
||||
final String passwordKeyAddURL = '/keyboardPwd/add'; //自定义密码
|
||||
final String passwordKeyCheckKeyboardpwdNameURL =
|
||||
'/keyboardPwd/checkKeyboardpwdName'; //自定义密码校验密码跟名字是否重复
|
||||
final String adminPwdCheckKeyboardPwdURL =
|
||||
'/keyboardPwd/checkKeyboardPwd'; //检查密码是否重复包括管理员密码
|
||||
final String updatePasswordKeyURL = '/keyboardPwd/update'; //修改密码详情
|
||||
final String updatePWDNumberURL = '/keyboardPwd/updatePwdUserNo'; //更新锁用户需要
|
||||
final String clearOperationRecordURL = '/lockRecords/clear'; //清空操作记录
|
||||
|
||||
@ -562,6 +562,14 @@ class ApiProvider extends BaseProvider {
|
||||
'keyboardPwd': keyboardPwd,
|
||||
}));
|
||||
|
||||
//检查密码是否重复包括管理员密码
|
||||
Future<Response> checkAdminPwd(int lockId, String keyboardPwd) => post(
|
||||
adminPwdCheckKeyboardPwdURL.toUrl,
|
||||
jsonEncode({
|
||||
'lockId': lockId,
|
||||
'keyboardPwd': keyboardPwd,
|
||||
}));
|
||||
|
||||
Future<Response> updateKeyboardPwd(
|
||||
int lockId,
|
||||
String keyboardPwdId,
|
||||
|
||||
@ -579,6 +579,13 @@ class ApiRepository {
|
||||
return PasswordKeyEntity.fromJson(res.body);
|
||||
}
|
||||
|
||||
//检查密码是否重复包括管理员密码
|
||||
Future<PasswordKeyEntity> checkAdminPwd(
|
||||
{required int lockId, required String adminPwd}) async {
|
||||
final res = await apiProvider.checkAdminPwd(lockId, adminPwd);
|
||||
return PasswordKeyEntity.fromJson(res.body);
|
||||
}
|
||||
|
||||
//修改密码
|
||||
Future<PasswordKeyEntity> updatePasswordKey(
|
||||
{required int lockId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user