Firebase身份验证:更新电子邮件

huangapple go评论95阅读模式
英文:

Firebase Authentication: Update Email

问题

I am using firebase to register my users, users can update their data but when updating the email they always send me the task unsuccessful response, and I verified that when updating the email it is well written.

This is the code:

private String vPassword, vEmail;
private Button btnValidate;
private EditText edContra, edEmail;
private TextView errorContra;
private ProgressDialog pDialog;
String sMail;

@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_pop_reset_email);

    pDialog = new ProgressDialog (this);
    vPassword = getIntent (). getStringExtra ("password");
    vEmail = getIntent (). getStringExtra ("email");
    btnValidar = findViewById (R.id.btnValidar);
    edContra = findViewById (R.id.passwordValidate);
    edEmail = findViewById (R.id.correoValidar);
    errorContra = findViewById (R.id.errorContraValidar);

    DisplayMetrics measures = new DisplayMetrics ();
    getWindowManager (). getDefaultDisplay (). getMetrics (measures);

    int width = measures.widthPixels;
    int high = measures.heightPixels;

    getWindow (). setLayout ((int) (width * 0.85), (int) (height * 0.5));

    btnValidar.setOnClickListener (new View.OnClickListener () {
        @Override
        public void onClick (View view) {
            String edPassword = edContra.getText (). ToString ();
            sMail = edEmail.getText (). toString ();
            if (edPassword.equals (vPassword)) {
                Verify ();
            } else {
                errorContra.setVisibility (View.VISIBLE);
            }
        }
    });
}

// CHECK EMAIL
private void Verify () {
    if (! sCorreo.isEmpty () && sCorreo.contains ("@") && sCorreo.contains (".")) {
        errorContra.setVisibility (View.INVISIBLE);
        pDialog.setMessage ("Updating ...");
        pDialog.setCanceledOnTouchOutside (false);
        pDialog.show ();
        UpdateMail ();
    } else {
        errorContra.setVisibility (View.VISIBLE);
        errorContra.setText ("* Type Valid Mail.");
    }
}

// UPDATE EMAIL
private void UpdateMail () {
    FirebaseUser user = FirebaseAuth.getInstance (). GetCurrentUser ();

    user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener <Void> () {
                @Override
                public void onComplete (@NonNull Task <Void> task) {
                    if (task.isSuccessful ()) {
                        Toast.makeText (PopResetEmail.this, "Mail Updated", Toast.LENGTH_SHORT) 
                        .show ();
                    } else {
                        Toast.makeText (PopResetEmail.this, "Email ERROR", Toast.LENGTH_SHORT) 
                        .show();                                          
                    }
                    pDialog.dismiss ();
                }
            });
}

// CLOSE ACTIVITY X
public void Close (View view) {
    finish ();
}

Already verify that at the time of the mail update it is taken from the edit text and converted to a string.

When testing on my device when I press the button to update, this appears in the Logcast:

2020-08-02 08:43:40.045 7910-7910/com.example.donmigue V/Toast: HANDLE HIDE: 
android.widget.Toast$TN@adee711 mView=null
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue                     
D/ViewRootImpl@c39e34d[Toast]: setView = android.widget.LinearLayout@375c076 
TM=true MM=false
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue V/Toast: Text: Dorr in 
android.widget.Toast$TN@adee711
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.096 7910-7910/com.example.donmigue E/GraphicExt: 
GraphicExtModuleLoader::CreateGraphicExtInstance false
//-----------------------------------
2020-08-02 08:43:40.097 7910-7910/com.example.donmigue 
D/ViewRootImpl@c39e34d[Toast]: Relayout returned: old=(0,55,720,1436) new= 
(230,714,490,791) req=(260,77)0 dur=19 res=0x7 s={true 3939788800} ch=true
2020-08-02 08:43:40.100 7910-7942/com.example.donmigue D/OpenGLRenderer: 
createReliableSurface : 0xbaba46c0(0xead46800)
2020-08-02 08:43:40.106 7910-7942/com.example.donmigue D/OpenGLRenderer: 
makeCurrent EglSurface : 0x0 -&gt; 0xd6e49580
2020-08-02 08:43:40.109 7910-7942/com.example.donmigue I/GPUD: 
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.110 7910-7942/com.example.donmigue I/GPUD: 
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue 
D/ViewRootImpl@630eeec[PopResetEmail]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager: 
prepareNavigationBarInfo() DecorView@a03932b[PopResetEmail]
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager: 
getNavigationBarColor() -855310
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.134 7910-7910/com.example.donmigue E/ViewRootImpl: 
sendUserActionEvent() mView returned.
//-----------------------------------
2020-08-02 08:43:40.138 7910-7942/com.example.donmigue D/OpenGLRenderer: 
makeCurrent EglSurface : 0xd6e49580 -&gt; 0xb8fc7640
2020-08-02 08:43:40.140 7910-7910/com.example.donmigue 
D/ViewRootImpl@c39e34d[Toast]: MSG_RESIZED: frame=(230,714,490,791) ci= 
(0,0,0,0) 
vi=(0,0,260,77) or=1
2020-08-02 08:43:40.140 7910-7942/com.example.donmigue I/GPUD:                                                                                                                                             
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.142 
<details>
<summary>英文:</summary>
I am using firebase to register my users, users can update their data but when updating the email they always send me the task unsuccessful response, and I verified that when updating the email it is well written.
This is the code:
`private String vPassword, vEmail;
private Button btnValidate;
private EditText edContra, edEmail;
private TextView errorContra;
private ProgressDialog pDialog;
String sMail;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_pop_reset_email);
pDialog = new ProgressDialog (this);
vPassword = getIntent (). getStringExtra (&quot;password&quot;);
vEmail = getIntent (). getStringExtra (&quot;email&quot;);
btnValidar = findViewById (R.id.btnValidar);
edContra = findViewById (R.id.passwordValidate);
edEmail = findViewById (R.id.correoValidar);
errorContra = findViewById (R.id.errorContraValidar);
DisplayMetrics measures = new DisplayMetrics ();
getWindowManager (). getDefaultDisplay (). getMetrics (measures);
int width = measurements.widthPixels;
int high = measures.heightPixels;
getWindow (). setLayout ((int) (width * 0.85), (int) (height * 0.5));
btnValidar.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View view) {
String edPassword = edContra.getText (). ToString ();
sMail = edEmail.getText (). toString ();
if (edPassword.equals (vPassword)) {
Verify ();
} else {
errorContra.setVisibility (View.VISIBLE);
}
}
});
}
// CHECK EMAIL
private void Verify () {
if (! sCorreo.isEmpty () &amp;&amp; sCorreo.contains (&quot;@&quot;) &amp;&amp; sCorreo.contains (&quot;.&quot;)) {
errorContra.setVisibility (View.INVISIBLE);
pDialog.setMessage (&quot;Updating ...&quot;);
pDialog.setCanceledOnTouchOutside (false);
pDialog.show ();
UpdateMail ();
} else {
errorContra.setVisibility (View.VISIBLE);
errorContra.setText (&quot;* Type Valid Mail.&quot;);
}
}
// UPDATE EMAIL
private void UpdateMail () {
FirebaseUser user = FirebaseAuth.getInstance (). GetCurrentUser ();
user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener &lt;Void&gt; () {
@Override
public void onComplete (@NonNull Task &lt;Void&gt; task) {
if (task.isSuccessful ()) {
Toast.makeText (PopResetEmail.this, &quot;Mail Updated&quot;, Toast.LENGTH_SHORT) 
.show ();
} else {
Toast.makeText (PopResetEmail.this, &quot;Email ERROR&quot;, Toast.LENGTH_SHORT) 
.show();                                          
}
pDialog.dismiss ();
}
});
}
// CLOSE ACTIVITY X
public void Close (View view) {
finish ();
}`
Already verify that at the time of the mail update it is taken from the edit text and converted to a string.
When testing on my device when I press the button to update, this appears in the Logcast:
2020-08-02 08:43:40.045 7910-7910/com.example.donmigue V/Toast: HANDLE HIDE: 
android.widget.Toast$TN@adee711 mView=null
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue                     
D/ViewRootImpl@c39e34d[Toast]: setView = android.widget.LinearLayout@375c076 
TM=true MM=false
2020-08-02 08:43:40.071 7910-7910/com.example.donmigue V/Toast: Text: Dorr in 
android.widget.Toast$TN@adee711
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.096 7910-7910/com.example.donmigue E/GraphicExt: 
GraphicExtModuleLoader::CreateGraphicExtInstance false
//-----------------------------------
2020-08-02 08:43:40.097 7910-7910/com.example.donmigue 
D/ViewRootImpl@c39e34d[Toast]: Relayout returned: old=(0,55,720,1436) new= 
(230,714,490,791) req=(260,77)0 dur=19 res=0x7 s={true 3939788800} ch=true
2020-08-02 08:43:40.100 7910-7942/com.example.donmigue D/OpenGLRenderer: 
createReliableSurface : 0xbaba46c0(0xead46800)
2020-08-02 08:43:40.106 7910-7942/com.example.donmigue D/OpenGLRenderer: 
makeCurrent EglSurface : 0x0 -&gt; 0xd6e49580
2020-08-02 08:43:40.109 7910-7942/com.example.donmigue I/GPUD: 
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.110 7910-7942/com.example.donmigue I/GPUD: 
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue 
D/ViewRootImpl@630eeec[PopResetEmail]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager: 
prepareNavigationBarInfo() DecorView@a03932b[PopResetEmail]
2020-08-02 08:43:40.115 7910-7910/com.example.donmigue D/InputMethodManager: 
getNavigationBarColor() -855310
//THIS IS A MISTAKE------------------
2020-08-02 08:43:40.134 7910-7910/com.example.donmigue E/ViewRootImpl: 
sendUserActionEvent() mView returned.
//-----------------------------------
2020-08-02 08:43:40.138 7910-7942/com.example.donmigue D/OpenGLRenderer: 
makeCurrent EglSurface : 0xd6e49580 -&gt; 0xb8fc7640
2020-08-02 08:43:40.140 7910-7910/com.example.donmigue 
D/ViewRootImpl@c39e34d[Toast]: MSG_RESIZED: frame=(230,714,490,791) ci= 
(0,0,0,0) 
vi=(0,0,260,77) or=1
2020-08-02 08:43:40.140 7910-7942/com.example.donmigue I/GPUD:                                                                                                                                             
@gpudInitialize: 
successfully initialized with 4, dbg=0 mmdump_dbg=0
2020-08-02 08:43:40.142 7910-7942/com.example.donmigue I/chatty: 
uid=10536(com.example.donmigue) RenderThread identical 3 lines
</details>
# 答案1
**得分**: 1
如果任务不成功,调用`task.getException()`将为您提供有关出错原因的详细信息。因此,您需要像以下代码一样显示/记录它:
```java
user.updateEmail(sMail).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(PopResetEmail.this, "邮箱已更新", Toast.LENGTH_SHORT).show();
} else {
Exception e = task.getException();
Toast.makeText(PopResetEmail.this, "更新邮箱出错:" + e.getMessage(), Toast.LENGTH_SHORT).show();
Log.w("updateEmail", "无法更新邮箱", e);
}
pDialog.dismiss();
}
});

通常这足以进行故障排除。

另请参阅:

英文:

If the task is unsuccessful, calling task.getException() will give you details about what went wrong. So you'll want to show/log that with something like:

user.updateEmail (sMail) .addOnCompleteListener (new OnCompleteListener &lt;Void&gt; () {
@Override
public void onComplete (@NonNull Task &lt;Void&gt; task) {
if (task.isSuccessful ()) {
Toast.makeText (PopResetEmail.this, &quot;Mail Updated&quot;, Toast.LENGTH_SHORT).show ();
} else {
Exception e = task.getException();
Toast.makeText (PopResetEmail.this, &quot;Error updating email: &quot;+e.getMessage(), Toast.LENGTH_SHORT).show();
Log.w(&quot;updateEmail&quot;, &quot;Unable to update email&quot;, e);
}
pDialog.dismiss ();
}
});

That usually is enough to troubleshoot.

Also see:

huangapple
  • 本文由 发表于 2020年8月2日 22:02:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63216890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定