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

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

问题描述

我要实现这一点,我想检查<击>两次两者,电子邮件和用户名,所以,我想,如果我做一个正常的查询和检查<击>两次两者,不工作,但它是一个错误,因为当我试图检查密码字段,这是一个问题。

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.

我还不清楚为什么你使用一个单独的用户表,如果你有解析,但是,让我们继续反正你只是使用分析用户对象的假设。

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.

在解析,你要注册用户的标准方式。

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() {
  ...
});

解析会自动检查电子邮件和用户名是你唯一

然后,使用用户名或电子邮件登录,你会想在登录之前写一点查询。这将交换电子邮件用户名,然后使用该用户名和密码,用户输入的登录。

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() {
                 ...
               });
          }
      }
   });
}

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

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