reason

增加了邮箱地址验证逻辑

......@@ -21,7 +21,6 @@ class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';
final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"accountEditPageUserBirthday":
MessageLookupByLibrary.simpleMessage("Birthday"),
......
......@@ -21,7 +21,6 @@ class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'zh';
final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"accountEditPageUserBirthday":
MessageLookupByLibrary.simpleMessage("出生日期"),
......
import 'package:flutter/foundation.dart';
import 'package:Parlando/net/dio_utils.dart';
import 'package:Parlando/net/http_api.dart';
import 'package:email_validator/email_validator.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:Parlando/home/webview_page.dart';
import 'package:Parlando/login/widgets/my_text_field.dart';
import 'package:Parlando/res/resources.dart';
import 'package:Parlando/res/styles.dart';
import 'package:Parlando/util/change_notifier_manage.dart';
import 'package:Parlando/util/other_utils.dart';
import 'package:Parlando/util/toast_utils.dart';
......@@ -34,7 +34,6 @@ class _RegisterPageState extends State<RegisterPage>
final FocusNode _nodeText2 = FocusNode();
final FocusNode _nodeText3 = FocusNode();
bool _clickable = false;
bool _switchSelected=true;
@override
Map<ChangeNotifier, List<VoidCallback>?>? changeNotifier() {
......@@ -71,7 +70,18 @@ class _RegisterPageState extends State<RegisterPage>
}
void _register() {
Toast.show('点击注册');
Map<String, String> params = <String, String>{
"email": _nameController.text,
"password": _passwordController.text,
"verify_code": _vCodeController.text,
};
DioUtils.instance.asyncRequestNetwork(
Method.post,
HttpApi.register,
params: params,
onSuccess: (data) {},
onError: (code, msg) {},
);
}
@override
......@@ -99,8 +109,8 @@ class _RegisterPageState extends State<RegisterPage>
key: const Key('phone'),
focusNode: _nodeText1,
controller: _nameController,
maxLength: 11,
keyboardType: TextInputType.phone,
maxLength: 100,
keyboardType: TextInputType.emailAddress,
hintText: ParlandoLocalizations.of(context).inputPhoneHint,
),
Gaps.vGap8,
......@@ -110,15 +120,28 @@ class _RegisterPageState extends State<RegisterPage>
controller: _vCodeController,
keyboardType: TextInputType.number,
getVCode: () async {
if (_nameController.text.length == 11) {
bool valid = EmailValidator.validate(_nameController.text);
if (valid) {
Toast.show(ParlandoLocalizations.of(context).verificationButton);
/// 一般可以在这里发送真正的请求,请求成功返回true
return true;
Map<String, String> params = <String, String>{
"email": _nameController.text,
};
DioUtils.instance.asyncRequestNetwork(
Method.get,
HttpApi.verify,
params: [],
queryParameters: params,
onSuccess: (data) {
print(data);
},
onError: (code, msg) {},
);
} else {
Toast.show(ParlandoLocalizations.of(context).inputPhoneInvalid);
return false;
}
return true;
},
maxLength: 6,
hintText: ParlandoLocalizations.of(context).inputVerificationCodeHint,
......@@ -137,7 +160,7 @@ class _RegisterPageState extends State<RegisterPage>
Text.rich(
TextSpan(
text: '登录即代表同意并阅读',
style: TextStyle(fontSize: 14, color: const Color(0xFF999999)),
style: const TextStyle(fontSize: 14, color: Color(0xFF999999)),
children: [
TextSpan(
text: '《用户协议》',
......@@ -146,12 +169,12 @@ class _RegisterPageState extends State<RegisterPage>
..onTap = () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return WebViewPage(
return const WebViewPage(
title: '《用户协议》', url: 'https://flutter.dev');
}));
},
),
TextSpan(text: '和'),
const TextSpan(text: '和'),
TextSpan(
text: '《隐私政策》',
style: TextStyle(color: Theme.of(context).primaryColor),
......@@ -159,7 +182,7 @@ class _RegisterPageState extends State<RegisterPage>
..onTap = () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return WebViewPage(
return const WebViewPage(
title: '《隐私政策》', url: 'https://flutter.dev');
}));
},
......
......@@ -113,10 +113,11 @@ class _MyTextFieldState extends State<MyTextField> {
textInputAction: TextInputAction.done,
keyboardType: widget.keyboardType,
// 数字、手机号限制格式为0到9, 密码限制不包含汉字
inputFormatters: (widget.keyboardType == TextInputType.number ||
widget.keyboardType == TextInputType.phone)
? [FilteringTextInputFormatter.allow(RegExp('[0-9]'))]
: [FilteringTextInputFormatter.deny(RegExp('[\u4e00-\u9fa5]'))],
inputFormatters: [
FilteringTextInputFormatter.deny(
RegExp('[\u4e00-\u9fa5]'),
),
],
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 16.px),
hintText: widget.hintText,
......
class HttpApi {
static const String setting = 'setting';
static const String register = 'register';
static const String verify = 'verify';
static const String search = 'search/repositories';
static const String subscriptions = 'users/simplezhli/subscriptions';
static const String upload = 'uuc/upload-inco';
......
......@@ -302,6 +302,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.5"
email_validator:
dependency: "direct main"
description:
name: email_validator
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
fake_async:
dependency: transitive
description:
......
......@@ -106,6 +106,7 @@ dependencies:
# A Dart timer that can be paused, resumed and reset.
pausable_timer: ^1.0.0+3
email_validator: ^2.0.1
dependency_overrides:
decimal: 1.5.0
......