在 Parse Android 中登录用户名和电子邮件 [英] Login username AND email in Parse Android

查看:26
本文介绍了在 Parse Android 中登录用户名和电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现这个,我想检查 twice 电子邮件和用户名,所以,我想如果我做一个普通查询并检查 twice 两个,确实有效,但这是一个错误,因为当我尝试检查密码字段时,这是一个问题.

I need to implement this, I want check twice both, email and username, So, I thought if I do a normal query and check twice both, does work, but it was a error because when I tried to check password field, it's a problem.

我从解析博客上看到了这个答案,但这不是我需要的.我认为是可能的.

I saw this answer from parse blog but It's not that I need. I think is possible.

链接

推荐答案

根据您的原始问题和评论,我的建议如下.您似乎想让用户输入电子邮件或用户名以及密码来登录.您的数据库需要这两个字段都是唯一的.

Based on your original question, and the comments, here is what I'd suggest. It seems that you want to have a user enter an email OR username, as well as their password, to login. Your database needs both of these fields to be unique.

如果您有 Parse,我仍然不清楚为什么要使用单独的 User 表,但是,假设您只是使用 Parse User 对象,让我们继续.

I'm still unclear why you are using a separate User table if you have Parse, but, let's proceed anyway assuming you are just using the Parse User object.

在 Parse 中,您需要以标准方式注册用户

In Parse, you'll want to register the user the standard way

ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email@example.com");

user.signUpInBackground(new SignUpCallback() {
  ...
});

Parse 将自动为您检查电子邮件和用户名是否唯一.

然后,要使用用户名或电子邮件登录,您需要在登录前编写一些查询.这会将电子邮件交换为用户名,然后使用用户输入的用户名和密码登录.

Then, to login using either the username OR the email, you'll want to write a bit of a query before the login. This will swap the email for a username and then login with that username and password that the user entered.

// If the entered username has an @, assume it is an email
String username = "bob@example.com";

if (username.indexOf("@")) {
  ParseQuery<ParseUser> query = ParseUser.getQuery();
  query.whereEqualTo("email", username);
  query.getFirstInBackground(new GetCallback<ParseObject>() {
      public void done(ParseObject object, ParseException e) {
          if (object == null) {
              Log.d("score", "The getFirst request failed.");
          } else {
               String actualUsername = object.get("username");
               ParseUser.logInInBackground(actualusername, "showmethemoney", new LogInCallback() {
                 ...
               });
          }
      }
   });
}

这篇关于在 Parse Android 中登录用户名和电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆