无法使用Android电子邮件登录解析帐户

时间:2015-08-13 07:51:00

标签: java android parse-platform

我想要一种方法,使用我的用户名或我的电子邮件登录我的Parse帐户。我现在的代码只能使用我的用户名。虽然根据日志,我的电子邮件被检测到。

这是代码,

.gitignore

Layout.xml :@Danielson要求

private class SignInOnClickListener implements View.OnClickListener {

    @Override
    public void onClick(View v) {
        // Get the username and password from the view
        final String username_email = mUsernameEmailEtxt.getText().toString().toLowerCase();
        final String password = mPasswordEtxt.getText().toString();
        final String email = mUsernameEmailEtxt.getText().toString().toLowerCase();

        if (isFormInputValid(username_email, password)) {
            if (username_email.indexOf('@') != -1) { // HERE!
                Log.d("detector", "username_email detected as email:" + email.toString());
                ParseUser.logInInBackground(email, password, new LogInCallback() {
                    public void done(ParseUser user, ParseException e) {
                        if (user != null) {
                            // Hooray! The user is logged in.
                            Intent intent = new Intent(getBaseContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                            finish();
                        }
                    }
                });
            } else {
                Log.d("detector", "username_email detected as username:" + username_email.toString());
                ParseUser.logInInBackground(username_email, password, new LogInCallback() {
                    public void done(ParseUser user, ParseException e) {
                        if (user != null) {
                            // Hooray! The user is logged in.
                            Intent intent = new Intent(getBaseContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                            finish();
                        } else {
                            findViewById(R.id.error).setVisibility(View.VISIBLE);
                            Log.d("error", "username or email invalid");
                        }

                    }
                });
            }

        }
    }
}

更新:修正了!您必须请求与电子邮件关联的用户名才能登录。

这是最终的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:background="@color/black"
        android:orientation="vertical"
        android:padding="15dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:orientation="vertical">

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:orientation="vertical">

            <EditText
                android:id="@+id/username_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/username"
                android:inputType="text"
                android:maxLength="30"

                android:singleLine="true"
                android:textColor="@color/off_white"
                android:textColorHint="@color/off_white" />

            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/password"
                android:inputType="textPassword"
                android:maxLength="30"


                android:singleLine="true"
                android:textColor="@color/off_white"
                android:textColorHint="@color/off_white" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btn_sign_in"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:layout_weight="50"
                android:background="@color/black"
                android:text="@string/sign_in"
                android:textColor="@color/green" />

            <Button
                android:id="@+id/btn_sign_up"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginStart="5dp"
                android:layout_weight="50"
                android:background="@color/black"
                android:text="@string/sign_up"
                android:textColor="@color/green" />
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:id="@+id/error"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/container"
        android:layout_centerHorizontal="true"
        android:background="@color/red"
        android:focusableInTouchMode="false"
        android:gravity="center"
        android:padding="8dp"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:visibility="gone" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

Parse只接受用户名和密码登录。即logInInBackground方法需要用户名和密码。

相关问题