我找不到登录XML页面的Firebase代码来使用我的登录Java类

时间:2016-10-07 00:37:10

标签: java android firebase

这是LoginPage.java

public abstract class LoginPage extends AppCompatActivity implements OnClickListener {
    private EditText etEmailUser;
    private EditText etPassword;
    private Button bLogin;
    private TextView tvRegisterHere;
    private CheckBox btRememberME;
    private Button bForgotpassword;
    private FirebaseAuth mAuth;
    private  FirebaseAuth.AuthStateListener mAuthListener;
    private static final int RC_SIGN_IN = 0;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;
    private SharedPreferences loginPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        FirebaseAuth auth = FirebaseAuth.getInstance();
        if (auth.getCurrentUser() != null) {
            //user already logged in

        } else {

            startActivityForResult(AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setProviders(
                            AuthUI.FACEBOOK_PROVIDER)
                    .build(), RC_SIGN_IN);


            mAuth = FirebaseAuth.getInstance();

            EditText etEmail = (EditText) findViewById(R.id.etEmailUser);
            EditText etPassword = (EditText) findViewById(R.id.etPassword);
            CheckBox saveLoginCheckBox;
            final TextView registerLink = (TextView) findViewById(R.id.tvRegisterHere);

            registerLink.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent registerIntent = new Intent(LoginPage.this, register.class);
                    LoginPage.this.startActivity(registerIntent);
                }
            });


            Button bLogin = (Button) findViewById(R.id.bLogin);

            mAuthListener = new FirebaseAuth.AuthStateListener() {
                @Override
                public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

                    if (firebaseAuth.getCurrentUser() != null) {

                        startActivity(new Intent(LoginPage.this, HybridActivity.class));
                    }

                }

            };

            bLogin.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                    startSignIn();


                }
            });

            // ATTENTION: This was auto-generated to implement the App Indexing API.
            // See https://g.co/AppIndexing/AndroidStudio for more information.
            client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
        }
    }

    public void startSignIn() {

        String email = etEmailUser.getText().toString();
        String password = etPassword.getText().toString();

        if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {


        } else {
            mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Toast.makeText(LoginPage.this, "Sign in problem", Toast.LENGTH_LONG).show();
                    }
                }
            });

        }

    }
    public Action getIndexApiAction() {
        Thing object = new Thing.Builder()
                .setName("LoginPage Page") // TODO: Define a title for the content shown.
                // TODO: Make sure this auto-generated URL is correct.
                .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
                .build();
        return new Action.Builder(Action.TYPE_VIEW)
                .setObject(object)
                .setActionStatus(Action.STATUS_TYPE_COMPLETED)
                .build();
    }

    @Override
    public void onStart() {
        super.onStart();

        mAuth.addAuthStateListener(mAuthListener);

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        AppIndex.AppIndexApi.start(client, getIndexApiAction());
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        AppIndex.AppIndexApi.end(client, getIndexApiAction());
        client.disconnect();
    }
}

这是XML文件。在我的Spashscreen类加载后,我似乎无法在此网站https://www.firebase.com/docs/web/api/firebase/resetpassword.html上找到任何教程来创建复选框,忘记密码按钮并使用Facebook按钮登录。我的编码有问题吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.stormy.greenfrogcafe.LoginPage">


    <Button
        android:text="Forgot Password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bForgotpassword"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/frog"
        android:layout_centerHorizontal="true"
        android:id="@+id/imageView3"
        android:layout_above="@+id/etEmailUser"
        android:layout_alignParentTop="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/etEmailUser"
        android:hint="email "
        android:layout_above="@+id/login_button"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="144dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <com.facebook.login.widget.LoginButton
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="27dp"
        android:layout_above="@+id/bForgotpassword"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/etPassword"
        android:hint="password"
        android:layout_below="@+id/imageView3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="46dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:text="Login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bLogin"
        android:layout_below="@+id/etPassword"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:text="Register Here"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tvRegisterHere"
        android:layout_below="@+id/bLogin"
        android:layout_toRightOf="@+id/btRememberMe"
        android:layout_toEndOf="@+id/btRememberMe"
        android:layout_marginLeft="28dp"
        android:layout_marginStart="28dp" />

    <CheckBox
        android:text="Remember Me"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btRememberMe"
        android:textSize="10sp"
        android:checked="true"
        android:layout_below="@+id/bLogin"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

您提供的链接属于旧的Firebase文档。

  • 可以找到Firebase的新文档here
  • 新的Firebase文档 可以找到用户身份验证here
  • 如何指导 可以找到使用用户名和密码验证用户 here
  • 可以找到有关如何使用Firebase管理和创建用户的指南here
  • 可以找到有关将Facebook登录与Firebase集成的指南here
相关问题