【问题标题】:Validate existing email in flutter using a api rest使用 api rest 验证现有电子邮件
【发布时间】:2020-02-25 02:31:59
【问题描述】:

我的应用中有一个注册屏幕。我还使用 api rest 连接到数据库(mongodb)。我在nodejs中制作这个api。在这个 api 中,电子邮件被设置为唯一的。

如果用户使用数据库中现有的电子邮件输入,我如何使颤动向用户显示该电子邮件已经存在?

提前谢谢你;)

【问题讨论】:

  • 您需要有一个后端逻辑来检查数据库中是否存在电子邮件,如果电子邮件存在,您应该在电子邮件存在时给出回复,如果没有注册成功@afifi 已经提到它。

标签: mongodb rest api flutter dart


【解决方案1】:
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')));
                                }

【讨论】:

    猜你喜欢
    • 2021-03-24
    • 2019-02-21
    • 2020-09-12
    • 2020-02-28
    • 2021-12-13
    • 2016-04-21
    • 2017-02-20
    • 2021-01-30
    • 2019-12-30
    相关资源
    最近更新 更多