当前位置: 首页>>代码示例>>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;未经允许,请勿转载。