19
19
goog . provide ( 'firebaseui.auth.widget.handler.handleEmailChangeRevocation' ) ;
20
20
goog . provide ( 'firebaseui.auth.widget.handler.handleEmailVerification' ) ;
21
21
goog . provide ( 'firebaseui.auth.widget.handler.handlePasswordReset' ) ;
22
+ goog . provide ( 'firebaseui.auth.widget.handler.handleRevertSecondFactorAddition' ) ;
23
+ goog . provide ( 'firebaseui.auth.widget.handler.handleVerifyAndChangeEmail' ) ;
22
24
23
25
goog . require ( 'firebaseui.auth.soy2.strings' ) ;
24
26
goog . require ( 'firebaseui.auth.ui.element' ) ;
@@ -30,6 +32,10 @@ goog.require('firebaseui.auth.ui.page.PasswordRecoveryEmailSent');
30
32
goog . require ( 'firebaseui.auth.ui.page.PasswordReset' ) ;
31
33
goog . require ( 'firebaseui.auth.ui.page.PasswordResetFailure' ) ;
32
34
goog . require ( 'firebaseui.auth.ui.page.PasswordResetSuccess' ) ;
35
+ goog . require ( 'firebaseui.auth.ui.page.RevertSecondFactorAdditionFailure' ) ;
36
+ goog . require ( 'firebaseui.auth.ui.page.RevertSecondFactorAdditionSuccess' ) ;
37
+ goog . require ( 'firebaseui.auth.ui.page.VerifyAndChangeEmailFailure' ) ;
38
+ goog . require ( 'firebaseui.auth.ui.page.VerifyAndChangeEmailSuccess' ) ;
33
39
goog . require ( 'firebaseui.auth.widget.Handler' ) ;
34
40
goog . require ( 'firebaseui.auth.widget.HandlerName' ) ;
35
41
goog . require ( 'firebaseui.auth.widget.handler.common' ) ;
@@ -272,6 +278,128 @@ firebaseui.auth.widget.handler.handleEmailVerification = function(
272
278
} ;
273
279
274
280
281
+ /**
282
+ * Handles the verify and change email action flow.
283
+ *
284
+ * @param {!firebaseui.auth.AuthUI } app The current Firebase UI instance whose
285
+ * configuration is used.
286
+ * @param {!Element } container The container DOM element.
287
+ * @param {string } actionCode The verify and change email action code.
288
+ * @param {?function()= } onContinueClick The optional callback to invoke when
289
+ * the continue button is clicked. If not provided, no continue button is
290
+ * displayed.
291
+ */
292
+ firebaseui . auth . widget . handler . handleVerifyAndChangeEmail = function (
293
+ app , container , actionCode , onContinueClick ) {
294
+ let email = null ;
295
+ // Gets the email related to the code.
296
+ app . registerPending (
297
+ app . getAuth ( )
298
+ . checkActionCode ( actionCode )
299
+ . then ( ( info ) => {
300
+ email = info [ 'data' ] [ 'email' ] ;
301
+ // Then applies it.
302
+ return app . getAuth ( ) . applyActionCode ( actionCode ) ;
303
+ } )
304
+ . then (
305
+ ( ) => {
306
+ const component =
307
+ new firebaseui . auth . ui . page . VerifyAndChangeEmailSuccess (
308
+ email , onContinueClick ) ;
309
+ component . render ( container ) ;
310
+ // Set current UI component.
311
+ app . setCurrentComponent ( component ) ;
312
+ } ,
313
+ ( error ) => {
314
+ const component =
315
+ new firebaseui . auth . ui . page . VerifyAndChangeEmailFailure ( ) ;
316
+ component . render ( container ) ;
317
+ // Set current UI component.
318
+ app . setCurrentComponent ( component ) ;
319
+ } ) ) ;
320
+ } ;
321
+
322
+
323
+ /**
324
+ * Handles the revert second factor addition email action flow.
325
+ *
326
+ * @param {!firebaseui.auth.AuthUI } app The current Firebase UI instance whose
327
+ * configuration is used.
328
+ * @param {!Element } container The container DOM element.
329
+ * @param {string } actionCode The revert second factor addition action code.
330
+ */
331
+ firebaseui . auth . widget . handler . handleRevertSecondFactorAddition =
332
+ function ( app , container , actionCode ) {
333
+ let email = null ;
334
+ let multiFactorInfo = null ;
335
+ app . registerPending (
336
+ app . getAuth ( )
337
+ . checkActionCode ( actionCode )
338
+ . then ( ( info ) => {
339
+ email = info [ 'data' ] [ 'email' ] ;
340
+ multiFactorInfo = info [ 'data' ] [ 'multiFactorInfo' ] ;
341
+ // Then applies it.
342
+ return app . getAuth ( ) . applyActionCode ( actionCode ) ;
343
+ } )
344
+ . then ( ( ) => {
345
+ firebaseui . auth . widget . handler
346
+ . handleRevertSecondFactorAdditionSuccess_ (
347
+ app , container , email , multiFactorInfo ) ;
348
+ } , ( error ) => {
349
+ const component =
350
+ new firebaseui . auth . ui . page
351
+ . RevertSecondFactorAdditionFailure ( ) ;
352
+ component . render ( container ) ;
353
+ // Set current UI component.
354
+ app . setCurrentComponent ( component ) ;
355
+ } ) ) ;
356
+ } ;
357
+
358
+
359
+ /**
360
+ * Handles the successful revert second factor addition action.
361
+ * @param {!firebaseui.auth.AuthUI } app The current Firebase UI instance whose
362
+ * configuration is used.
363
+ * @param {!Element } container The container DOM element.
364
+ * @param {string } email The email of the acount.
365
+ * @param {!firebase.auth.MultiFactorInfo } multiFactorInfo The info of
366
+ * multi-factor to be unenrolled.
367
+ * @private
368
+ */
369
+ firebaseui . auth . widget . handler . handleRevertSecondFactorAdditionSuccess_ =
370
+ function ( app , container , email , multiFactorInfo ) {
371
+ let component = new firebaseui . auth . ui . page . RevertSecondFactorAdditionSuccess (
372
+ multiFactorInfo [ 'factorId' ] ,
373
+ ( ) => {
374
+ component . executePromiseRequest (
375
+ goog . bind ( app . getAuth ( ) . sendPasswordResetEmail , app . getAuth ( ) ) ,
376
+ [ email ] ,
377
+ ( ) => {
378
+ // Reset password code sent.
379
+ component . dispose ( ) ;
380
+ component =
381
+ new firebaseui . auth . ui . page . PasswordRecoveryEmailSent (
382
+ email ,
383
+ undefined ,
384
+ app . getConfig ( ) . getTosUrl ( ) ,
385
+ app . getConfig ( ) . getPrivacyPolicyUrl ( ) ) ;
386
+ component . render ( container ) ;
387
+ // Set current UI component.
388
+ app . setCurrentComponent ( component ) ;
389
+ } , ( error ) => {
390
+ // Failed to send reset password code.
391
+ component . showInfoBar (
392
+ firebaseui . auth . soy2 . strings . errorSendPasswordReset ( )
393
+ . toString ( ) ) ;
394
+ } ) ;
395
+ } ,
396
+ multiFactorInfo [ 'phoneNumber' ] ) ;
397
+ component . render ( container ) ;
398
+ // Set current UI component.
399
+ app . setCurrentComponent ( component ) ;
400
+ } ;
401
+
402
+
275
403
// Register handlers.
276
404
firebaseui . auth . widget . handler . register (
277
405
firebaseui . auth . widget . HandlerName . PASSWORD_RESET ,
@@ -288,3 +416,15 @@ firebaseui.auth.widget.handler.register(
288
416
firebaseui . auth . widget . HandlerName . EMAIL_VERIFICATION ,
289
417
/** @type {firebaseui.auth.widget.Handler } */
290
418
( firebaseui . auth . widget . handler . handleEmailVerification ) ) ;
419
+
420
+ /** @suppress {missingRequire} */
421
+ firebaseui . auth . widget . handler . register (
422
+ firebaseui . auth . widget . HandlerName . REVERT_SECOND_FACTOR_ADDITION ,
423
+ /** @type {!firebaseui.auth.widget.Handler } */
424
+ ( firebaseui . auth . widget . handler . handleRevertSecondFactorAddition ) ) ;
425
+
426
+ /** @suppress {missingRequire} */
427
+ firebaseui . auth . widget . handler . register (
428
+ firebaseui . auth . widget . HandlerName . VERIFY_AND_CHANGE_EMAIL ,
429
+ /** @type {!firebaseui.auth.widget.Handler } */
430
+ ( firebaseui . auth . widget . handler . handleVerifyAndChangeEmail ) ) ;
0 commit comments