mongodb - 使用 api rest 验证现有电子邮件
问题描述
我的应用程序中有一个注册屏幕。我还使用 api rest 连接到数据库(mongodb)。我在nodejs中制作这个api。在这个 api 中,电子邮件被设置为唯一的。
如果用户使用数据库中的现有电子邮件输入该电子邮件已经存在,我如何使颤振显示给用户?
先感谢您 ;)
解决方案
type this code in your onPressed method:
http.Response response = await http.post(
'//type your server-url here',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'name': name,
'email': email,
'password': password,
}),
);
if (response.body == 'email already exists') {
//the message "email already exists" comes from your backend.
//It may differ from this message depending on your backend
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Email already exists')));
} else {
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Processing Data')));
}
推荐阅读
- c++ - 当 G++ 未给出错误时,未定义对 LD 的“SDL2_Init”的引用
- mysql - 比较 SQL 中的两个表并在新列中将行设置为“真”
- matplotlib - 从使用 matplotlib 创建的密度图中的 bin 中提取数据
- angular - Angular Ivy:无法绑定到“formGroup”,因为它不是“form”的已知属性。但是 ReactiveFormsModule 和 FormsModule 被导入
- visual-studio-code - 如何在 Windows 的 VS Code 上输入集成终端?
- symfony - 更改未登录用户的重定向 URL
- mysql - 将两个具有现有值的表连接到 null 中的非现有值
- python - 如何使用脚本正确管理数据库
- amazon-web-services - AWS Cloudfront 备用域名 403 被禁止
- python - 如何根据当前列表中的值从另一个列表中获取元素?