當前位置: 首頁>>代碼示例>>Java>>正文


Java Firebase.AuthResultHandler方法代碼示例

本文整理匯總了Java中com.firebase.client.Firebase.AuthResultHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java Firebase.AuthResultHandler方法的具體用法?Java Firebase.AuthResultHandler怎麽用?Java Firebase.AuthResultHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.firebase.client.Firebase的用法示例。


在下文中一共展示了Firebase.AuthResultHandler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: attemptLogin

import com.firebase.client.Firebase; //導入方法依賴的package包/類
/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 */
private void attemptLogin() {

    // Reset errors.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String password = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
        mEmailView.setError(getString(R.string.error_field_required));
        focusView = mEmailView;
        cancel = true;
    } else if (!isEmailValid(email)) {
        mEmailView.setError(getString(R.string.error_invalid_email));
        focusView = mEmailView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {

        showProgress(true);
        Firebase ref = new Firebase(Constant_ApplicationConstant.FirebaseURL);

        Firebase.AuthResultHandler authResultHandler = new Firebase.AuthResultHandler() {
            @Override
            public void onAuthenticated(AuthData authData) {
                Log.e("AuthData", authData.toString());
                SharedPreferences.Editor ed = sp.edit();
                ed.remove("UID");
                ed.putString("UID", authData.getUid());
                ed.commit();
                showProgress(false);
                goToUserList(authData.getUid());
            }

            @Override
            public void onAuthenticationError(FirebaseError firebaseError) {
                Log.e("AuthErr", firebaseError.toString());
                Toast.makeText(getBaseContext(),firebaseError.toString(),Toast.LENGTH_SHORT).show();
                showProgress(false);
            }
        };

        ref.authWithPassword(email,password,authResultHandler);
    }
}
 
開發者ID:WenhaoWu,項目名稱:Morsi,代碼行數:69,代碼來源:Activity_Login.java


注:本文中的com.firebase.client.Firebase.AuthResultHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。