feat(auth): 优化登录页布局与字段反馈
This commit is contained in:
1 parent
e44fbdf6f2
commit
8a96f341c8
12 files changed
+355
-119
No files matched your search
@@ -8,29 +8,44 @@ class AuthLogic {
|
||||
String password = '';
|
||||
bool busy = false;
|
||||
String? errorMessage;
|
||||
AuthFieldError? fieldError;
|
||||
|
||||
AuthLogic({this.signUpMode = false, this.errorMessage});
|
||||
|
||||
void toggleMode() {
|
||||
signUpMode = !signUpMode;
|
||||
errorMessage = null;
|
||||
fieldError = null;
|
||||
}
|
||||
|
||||
/// 返回 null 表示校验通过,否则返回错误文案(由视图用 l10n 映射)
|
||||
AuthFieldError? validate() {
|
||||
final mail = email.trim();
|
||||
if (mail.isEmpty) return AuthFieldError.emailRequired;
|
||||
if (!_emailPattern.hasMatch(mail)) return AuthFieldError.emailInvalid;
|
||||
if (password.isEmpty) return AuthFieldError.passwordRequired;
|
||||
if (mail.isEmpty) return _record(AuthFieldError.emailRequired);
|
||||
if (!_emailPattern.hasMatch(mail)) {
|
||||
return _record(AuthFieldError.emailInvalid);
|
||||
}
|
||||
if (password.isEmpty) return _record(AuthFieldError.passwordRequired);
|
||||
if (password.length < 8 || password.length > 64) {
|
||||
return AuthFieldError.passwordLength;
|
||||
return _record(AuthFieldError.passwordLength);
|
||||
}
|
||||
if (!_hasLetter.hasMatch(password) || !_hasDigit.hasMatch(password)) {
|
||||
return AuthFieldError.passwordWeak;
|
||||
return _record(AuthFieldError.passwordWeak);
|
||||
}
|
||||
fieldError = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 清除当前字段错误;输入变化时由页面调用。
|
||||
void clearFieldError() {
|
||||
fieldError = null;
|
||||
}
|
||||
|
||||
AuthFieldError _record(AuthFieldError error) {
|
||||
fieldError = error;
|
||||
return error;
|
||||
}
|
||||
|
||||
String get normalizedEmail => email.trim().toLowerCase();
|
||||
|
||||
static final _emailPattern = RegExp(
|
||||
|
||||
Reference in new issue
Block a user