更新用户模块

This commit is contained in:
wyf
2025-06-09 19:11:25 +08:00
parent 8dfc522a69
commit 501d133bad
19 changed files with 1470 additions and 307 deletions

View File

@@ -23,7 +23,7 @@ class LoginModel {
String? account = '17649984946'; //账户
// String? account = '13953240733'; //账户
String? password = 'wyf123..'; //密码
String? password = '123wyf..'; //密码
// String? account = '15255134931'; //账户
// String? password = 'mht123,.'; //密码

View File

@@ -0,0 +1,163 @@
import 'package:ef/ef.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
part 'update_password_controller.g.dart';
@JsonSerializable()
class UpdatePasswordModel {
String? phone; //手机号
String? code; //验证码
String? pd; //密码
String? confirm; //验证密码
bool? pdshow = true; //是否显示密码
bool? cpdshow = true; //是否显示密码
UpdatePasswordModel();
static UpdatePasswordModel fromJson(Map<String, dynamic> json) =>
_$UpdatePasswordModelFromJson(json);
Map<String, dynamic> toJson() => _$UpdatePasswordModelToJson(this);
}
class UpdatePasswordController extends GetControllerEx<UpdatePasswordModel> {
UpdatePasswordController() {
attr = GetModel(UpdatePasswordModel()).obs;
}
UserInfoController userInfoController = Get.find();
//确认验证码
Future<String> resetPassword(BuildContext context) async {
String message = "";
if (model.phone == null || model.phone!.isEmpty) {
message = "请输入手机号".tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (!MyUtils.isValidPhoneNumber(model.phone!)) {
message = '请输入正确的手机号'.tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (model.code == null || model.code!.isEmpty) {
message = "请输入验证码".tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (model.pd == null || model.pd!.isEmpty) {
message = "请输入密码".tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
String passwordMsg = "密码格式提示".tr;
bool hasUppercase = model.pd!.contains(RegExp(r'[A-Z]'));
bool hasDigit = model.pd!.contains(RegExp(r'[0-9]'));
bool hasSpecialCharacters =
model.pd!.contains(RegExp(r'[!@#$%^&*(),.?":{}|<>]'));
bool hasLetter = model.pd!.contains(RegExp(r'[a-zA-Z]'));
if (model.pd!.length < 8) {
message = passwordMsg;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (!hasLetter || !hasDigit) {
message = passwordMsg;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (!(hasSpecialCharacters || hasUppercase)) {
message = passwordMsg;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (model.confirm == null || model.confirm!.isEmpty) {
message = "请输入确认密码".tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (model.pd != model.confirm) {
message = "两次密码不一致".tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.user_changePassword;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
final user = userInfoController.model.user!;
var data = {
"userName": user.email ?? user.phone,
"password": model.pd,
"verify": model.code
};
await requestWithLog(
logTitle: "修改密码",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
TopSlideNotification.show(context, text: "操作成功".tr);
},
onFailure: (res) {
message = res.msg!;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
},
);
return message;
}
//获取验证码
Future<String> getCode(BuildContext context) async {
String message = "";
if (model.phone == null || model.phone!.isEmpty) {
message = "请输入手机号".tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
if (!MyUtils.isValidPhoneNumber(model.phone!)) {
message = '请输入正确的手机号'.tr;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
return message;
}
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.send_code;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
var data = {"userName": model.phone, "type": 3};
await requestWithLog(
data: data,
logTitle: "发送验证码",
method: MyHttpMethod.post,
queryUrl: queryUrl,
onSuccess: (res) {
TopSlideNotification.show(context, text: "发送验证码成功".tr);
},
onFailure: (res) {
message = res.msg!;
TopSlideNotification.show(context,
text: message, textColor: themeController.currentColor.sc9);
},
);
return message;
}
}

View File

@@ -0,0 +1,27 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'update_password_controller.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UpdatePasswordModel _$UpdatePasswordModelFromJson(Map<String, dynamic> json) =>
UpdatePasswordModel()
..phone = json['phone'] as String?
..code = json['code'] as String?
..pd = json['pd'] as String?
..confirm = json['confirm'] as String?
..pdshow = json['pdshow'] as bool?
..cpdshow = json['cpdshow'] as bool?;
Map<String, dynamic> _$UpdatePasswordModelToJson(
UpdatePasswordModel instance) =>
<String, dynamic>{
'phone': instance.phone,
'code': instance.code,
'pd': instance.pd,
'confirm': instance.confirm,
'pdshow': instance.pdshow,
'cpdshow': instance.cpdshow,
};