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