15987941
liangchengyou
feat:兑换码接口+本地密码加密
|
1
|
import 'package:common_utils/common_utils.dart';
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
2
3
|
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
4
5
6
|
import 'package:wow_english/common/request/dao/user_dao.dart';
import 'package:wow_english/common/request/exception.dart';
import 'package:wow_english/utils/loading.dart';
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
7
|
|
c61b3c1a
Key
feat: toast_util....
|
8
9
|
import '../set_pwd_page.dart';
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
10
11
12
13
|
part 'set_pwd_event.dart';
part 'set_pwd_state.dart';
class SetPwdBloc extends Bloc<SetPwdEvent, SetPwdState> {
|
e1f36554
liangchengyou
feat:调整状态监听逻辑
|
14
|
final String? phoneNumber;
|
c61b3c1a
Key
feat: toast_util....
|
15
16
|
final String? smsCode;
late final SetPwdPageType pageType;
|
e1f36554
liangchengyou
feat:调整状态监听逻辑
|
17
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
18
19
|
final TextEditingController passWordFirstController = TextEditingController();
final TextEditingController passWordSecondController = TextEditingController();
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
20
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
21
22
|
///密码是否符合规则(第一个输入框)
bool _passwordEnsure = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
23
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
24
25
|
///密码是否超过16位(第一个输入框)
bool _passwordLarger = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
26
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
27
28
|
///是否显示Icon(第一个输入框)
bool _showPwdIcon = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
29
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
30
31
|
///是否显示Icon(第二个输入框)
bool _showCheckPwdIcon = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
32
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
///密码是否一致
bool _passwordCheck = true;
bool get passwordEnsure => _passwordEnsure;
bool get passwordCheck => _passwordCheck;
bool get passwordLarger => _passwordLarger;
bool get showPwdIcon => _showPwdIcon;
bool get showCheckPwdIcon => _showCheckPwdIcon;
bool get ensure => _passwordCheck && _passwordEnsure;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
48
49
|
String get passwordText => passWordFirstController.text;
|
c61b3c1a
Key
feat: toast_util....
|
50
|
SetPwdBloc(this.phoneNumber, this.smsCode, this.pageType) : super(SetPwdInitial()) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
51
52
53
54
55
|
on<PwdEnsureEvent>(_pwdEnsureTextChange);
on<PwdCheckEvent>(_pwdCheckTextChange);
on<SetPasswordEvent>(_setPassword);
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
56
57
|
void _pwdCheckTextChange(PwdCheckEvent event, Emitter<SetPwdState> emitter) async {
if (passWordSecondController.text.isEmpty) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
58
59
60
61
62
63
64
65
|
_showCheckPwdIcon = false;
emitter(PasswordCheckIconShowState());
} else {
if (!_showCheckPwdIcon) {
_showCheckPwdIcon = true;
emitter(PasswordCheckIconShowState());
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
66
|
if (passWordFirstController.text == passWordSecondController.text) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
67
68
69
70
71
72
73
74
|
_passwordCheck = true;
emitter(SetCheckPwdState());
} else {
_passwordCheck = false;
emitter(SetCheckPwdState());
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
75
|
void _pwdEnsureTextChange(PwdEnsureEvent event, Emitter<SetPwdState> emitter) async {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
76
77
78
79
80
81
82
83
84
85
|
if (passWordFirstController.text.isEmpty) {
if (_showPwdIcon) {
_showPwdIcon = false;
emitter(PasswordIconShowState());
}
} else {
if (!_showPwdIcon) {
_showPwdIcon = true;
emitter(PasswordIconShowState());
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
86
|
if (passWordSecondController.text.isNotEmpty) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
87
88
|
if (passWordFirstController.text == passWordSecondController.text) {
_passwordCheck = true;
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
89
90
91
92
93
|
} else {
_passwordCheck = false;
}
emitter(SetCheckPwdState());
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
94
|
if (passWordFirstController.text.length >= 8 && passWordFirstController.text.length <= 16) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
95
|
///符合密码要求
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
96
|
if (!_passwordEnsure) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
97
98
99
|
_passwordEnsure = true;
emitter(SetEnsurePwdState());
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
100
101
|
if (passWordSecondController.text.isNotEmpty) {
if (passWordFirstController.text == passWordSecondController.text) {}
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
102
103
104
105
106
107
|
}
if (_passwordLarger) {
_passwordLarger = false;
emitter(PasswordLargeState());
}
} else {
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
108
|
if (passWordFirstController.text.length > 16) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
109
110
111
112
113
114
115
116
117
118
119
|
///超过十六位
if (!_passwordLarger) {
_passwordLarger = true;
emitter(PasswordLargeState());
}
} else {
if (_passwordLarger) {
_passwordLarger = false;
emitter(PasswordLargeState());
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
120
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
121
|
///密码不符合要求
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
122
|
if (_passwordEnsure) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
123
124
125
126
127
128
129
|
_passwordEnsure = false;
emitter(SetEnsurePwdState());
}
}
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
130
131
|
/// 设置密码,调接口
void _setPassword(SetPasswordEvent event, Emitter<SetPwdState> emitter) async {
|
b2dd7a7c
liangchengyou
feat:修改版本号+密码md5加密隐藏
|
132
133
|
// var password = EncryptUtil.encodeMd5(passwordText);
var password = passwordText;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
134
135
136
|
try {
await loading(() async {
switch (pageType) {
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
137
|
case SetPwdPageType.initPwd:
|
15987941
liangchengyou
feat:兑换码接口+本地密码加密
|
138
|
await UserDao.initPassword(password);
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
139
|
break;
|
da82bd70
Key
feat: user_inform...
|
140
141
142
143
|
case SetPwdPageType.changePwd:
// 现在走同一个流程和接口
/*await UserDao.changePassword(passwordText);
break;*/
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
144
145
146
147
148
149
150
|
case SetPwdPageType.resetPwd:
if (phoneNumber == null || phoneNumber!.isEmpty) {
throw ApiException(ApiException.customErrorCode, '手机号为空');
}
if (smsCode == null || smsCode!.isEmpty) {
throw ApiException(ApiException.customErrorCode, '验证码为空');
}
|
15987941
liangchengyou
feat:兑换码接口+本地密码加密
|
151
|
await UserDao.resetPassword(phoneNumber!, password, smsCode!);
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
152
153
154
155
156
157
158
159
160
161
162
163
164
|
break;
}
});
emitter(PasswordSetSuccessState());
} catch (e) {
String msg;
if (e is ApiException) {
msg = e.message ?? '未知错误';
} else {
msg = e.toString();
}
emitter(PasswordSetFailedState(msg));
}
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
165
166
|
}
}
|