在Parse Android中登录用户名和电子邮件(Login username AND email in Parse Android)

编程入门 行业动态 更新时间:2024-10-26 16:26:04
在Parse Android中登录用户名和电子邮件(Login username AND email in Parse 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.

Link

最满意答案

根据你原来的问题和评论,这里是我的建议。 看来你想让一个用户输入一个电子邮件或用户名,以及他们的密码登录。 您的数据库需要这些字段都是唯一的。

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

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

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

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

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

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

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

Parse will automatically check that the email and username are unique for you.

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

更多推荐

本文发布于:2023-08-04 22:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1421975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   用户名   Android   Parse   username

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!