UNPKG

ez-firebase-auth

Version:
1,264 lines 139 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Component, Directive, ElementRef, Injectable, Input, NgModule, Renderer2 } from '@angular/core'; import { AngularFireAuth } from 'angularfire2/auth'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { BehaviorSubject as BehaviorSubject$1 } from 'rxjs/BehaviorSubject'; import { Subject as Subject$1 } from 'rxjs/Subject'; import { auth as auth$1 } from 'firebase'; import { assign, compact, each, filter, find, has, includes, isArray, map, omit, trim, uniqueId } from 'lodash'; import { CommonModule } from '@angular/common'; import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from '@angular/forms'; import 'rxjs/add/operator/take'; import 'rxjs/add/operator/takeUntil'; import { isEmail } from 'validator'; import 'rxjs/add/operator/combineLatest'; import 'rxjs/add/operator/debounceTime'; var EzfaEmailChangedEvent = (function () { /** * @param {?} user * @param {?} oldEmail * @param {?} newEmail */ function EzfaEmailChangedEvent(user, oldEmail, newEmail) { this.user = user; this.oldEmail = oldEmail; this.newEmail = newEmail; } return EzfaEmailChangedEvent; }()); EzfaEmailChangedEvent.type = 'EzfaEmailChangedEvent'; var EzfaOauthMethod = {}; EzfaOauthMethod.popup = 1; EzfaOauthMethod.redirect = 2; EzfaOauthMethod[EzfaOauthMethod.popup] = "popup"; EzfaOauthMethod[EzfaOauthMethod.redirect] = "redirect"; var EzfaOptions = (function () { function EzfaOptions() { this.providerIds = []; this.providers = []; this.requireDisplayName = true; this.requireTos = true; this.sendEmailVerificationLink = true; this.oauthMethod = EzfaOauthMethod.redirect; } return EzfaOptions; }()); EzfaOptions.decorators = [ { type: Injectable }, ]; /** * @nocollapse */ EzfaOptions.ctorParameters = function () { return []; }; var EzfaProviderLabels = (function () { function EzfaProviderLabels() { this['password'] = 'Email/Password'; this['twitter.com'] = 'Twitter'; this['facebook.com'] = 'Facebook'; this['github.com'] = 'GitHub'; this['google.com'] = 'Google'; } return EzfaProviderLabels; }()); var EzfaProviderLinkedEvent = (function () { /** * @param {?} user * @param {?} providerId * @param {?=} credential */ function EzfaProviderLinkedEvent(user, providerId, credential) { if (credential === void 0) { credential = null; } this.user = user; this.providerId = providerId; this.credential = credential; } return EzfaProviderLinkedEvent; }()); EzfaProviderLinkedEvent.type = 'EzfaProviderLinkedEvent'; var EzfaProviderUnlinkedEvent = (function () { /** * @param {?} user * @param {?} providerId */ function EzfaProviderUnlinkedEvent(user, providerId) { this.user = user; this.providerId = providerId; } return EzfaProviderUnlinkedEvent; }()); EzfaProviderUnlinkedEvent.type = 'EzfaProviderUnlinkedEvent'; var EzfaSignedInEvent = (function () { /** * @param {?} user * @param {?} providerId * @param {?=} credential */ function EzfaSignedInEvent(user, providerId, credential) { if (credential === void 0) { credential = null; } this.user = user; this.providerId = providerId; this.credential = credential; this.redirectCancelled = false; } return EzfaSignedInEvent; }()); EzfaSignedInEvent.type = 'EzfaSignedInEvent'; var EzfaSignedOutEvent = (function () { function EzfaSignedOutEvent() { this.redirectCancelled = false; } return EzfaSignedOutEvent; }()); EzfaSignedOutEvent.type = 'EzfaSignedOutEvent'; var EzfaService = (function () { /** * @param {?} router * @param {?} afAuth * @param {?} options */ function EzfaService(router$$1, afAuth, options) { this.router = router$$1; this.afAuth = afAuth; this.options = options; this.savedPopupPromise_ = null; var initialMethod = options.oauthMethod === EzfaOauthMethod.popup ? EzfaOauthMethod.popup : EzfaOauthMethod.redirect; this.oauthMethod$ = new BehaviorSubject$1(initialMethod); var localPersEnabled = localStorage.getItem(EzfaService.STORAGE_KEY_PERSISTENCE) === 'yes' ? false : true; this.localPersistenceEnabled$ = new BehaviorSubject$1(localPersEnabled); this.routeChanges$ = new Subject$1(); this.signedInEvents$ = new Subject$1(); this.signedOutEvents$ = new Subject$1(); this.emailChangedEvents$ = new Subject$1(); this.providerLinkedEvents$ = new Subject$1(); this.providerUnlinkedEvents$ = new Subject$1(); } Object.defineProperty(EzfaService.prototype, "auth", { /** * @return {?} */ get: function () { return this.afAuth.auth; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "authState", { /** * @return {?} */ get: function () { return this.afAuth.authState; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "applicationLabel", { /** * @return {?} */ get: function () { return this.options.applicationLabel; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "rootSlug", { /** * @return {?} */ get: function () { return this.options.rootSlug; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "providerIds", { /** * @return {?} */ get: function () { return filter(this.options.providerIds, function (id) { return includes(EzfaService.ENABLED_PROVIDERS, id); }); }, /** * @param {?} ids * @return {?} */ set: function (ids) { this.options.providerIds = ids; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "oauthProviderIds", { /** * @return {?} */ get: function () { return filter(this.providerIds, function (id) { return includes(EzfaService.ENABLED_OAUTH_PROVIDERS, id); }); }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "passwordProviderEnabled", { /** * @return {?} */ get: function () { return includes(this.providerIds, 'password'); }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "providerLabels", { /** * @return {?} */ get: function () { var /** @type {?} */ passed = this.options.providerLabels || {}; var /** @type {?} */ def = new EzfaProviderLabels(); return assign({}, def, passed); }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "requireDisplayName", { /** * @return {?} */ get: function () { return this.options.requireDisplayName !== false; }, /** * @param {?} b * @return {?} */ set: function (b) { this.options.requireDisplayName = b; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "requireTos", { /** * @return {?} */ get: function () { return this.options.requireTos !== false; }, /** * @param {?} b * @return {?} */ set: function (b) { this.options.requireTos = b; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "sendEmailVerificationLink", { /** * @return {?} */ get: function () { return this.options.sendEmailVerificationLink !== false; }, /** * @param {?} b * @return {?} */ set: function (b) { this.options.sendEmailVerificationLink = b; }, enumerable: true, configurable: true }); Object.defineProperty(EzfaService.prototype, "oauthMethod", { /** * @return {?} */ get: function () { return this.oauthMethod$.value; }, /** * @param {?} method * @return {?} */ set: function (method) { this.oauthMethod$.next(method); }, enumerable: true, configurable: true }); /** * @param {?} id * @return {?} */ EzfaService.prototype.getProviderById = function (id) { var _this = this; return new Promise(function (resolve, reject) { if (!includes(_this.providerIds, id)) { return reject({ code: 'ezfa/provider-not-configured' }); } var /** @type {?} */ customProvider = find(_this.options.providers, { providerId: id }); if (customProvider) { return resolve(customProvider); } switch (id) { case 'password': return resolve(new auth$1.EmailAuthProvider()); case 'twitter.com': return resolve(new auth$1.TwitterAuthProvider()); case 'facebook.com': return resolve(new auth$1.FacebookAuthProvider()); case 'google.com': return resolve(new auth$1.GoogleAuthProvider()); case 'github.com': return resolve(new auth$1.GithubAuthProvider()); } }); }; /** * @param {?=} slug * @return {?} */ EzfaService.prototype.routerLink = function (slug) { var /** @type {?} */ commands = ['/' + this.rootSlug]; if (slug) { commands.push(slug); } return commands; }; /** * @param {?=} slug * @param {?=} extras * @return {?} */ EzfaService.prototype.navigate = function (slug, extras) { return this.router.navigate(this.routerLink(slug), extras); }; Object.defineProperty(EzfaService.prototype, "localPersistenceEnabled", { /** * @return {?} */ get: function () { return this.localPersistenceEnabled$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} b * @return {?} */ EzfaService.prototype.setPersistenceLocal = function (b) { var _this = this; return new Promise(function (resolve) { var /** @type {?} */ persistence = b ? auth$1.Auth.Persistence.LOCAL : auth$1.Auth.Persistence.SESSION; _this.auth.setPersistence(persistence) .then(function () { if (b) { localStorage.removeItem(EzfaService.STORAGE_KEY_PERSISTENCE); } else { localStorage.setItem(EzfaService.STORAGE_KEY_PERSISTENCE, 'yes'); } _this.localPersistenceEnabled$.next(b); resolve(); }); }); }; Object.defineProperty(EzfaService.prototype, "routeChanges", { /** * @return {?} */ get: function () { return this.routeChanges$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} route * @return {?} */ EzfaService.prototype.onRouteChange = function (route) { this.routeChanges$.next(route); }; Object.defineProperty(EzfaService.prototype, "signedInEvents", { /** * @return {?} */ get: function () { return this.signedInEvents$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} event * @return {?} */ EzfaService.prototype.onSignedIn = function (event) { this.signedInEvents$.next(event); }; Object.defineProperty(EzfaService.prototype, "signedOutEvents", { /** * @return {?} */ get: function () { return this.signedOutEvents$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} event * @return {?} */ EzfaService.prototype.onSignedOut = function (event) { this.signedOutEvents$.next(event); }; Object.defineProperty(EzfaService.prototype, "emailChangedEvents", { /** * @return {?} */ get: function () { return this.emailChangedEvents$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} event * @return {?} */ EzfaService.prototype.onEmailChanged = function (event) { this.emailChangedEvents$.next(event); }; Object.defineProperty(EzfaService.prototype, "providerLinkedEvents", { /** * @return {?} */ get: function () { return this.providerLinkedEvents$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} event * @return {?} */ EzfaService.prototype.onProviderLinked = function (event) { this.providerLinkedEvents$.next(event); }; Object.defineProperty(EzfaService.prototype, "providerUnlinkedEvents", { /** * @return {?} */ get: function () { return this.providerUnlinkedEvents$.asObservable(); }, enumerable: true, configurable: true }); /** * @param {?} event * @return {?} */ EzfaService.prototype.onProviderUnlinked = function (event) { this.providerUnlinkedEvents$.next(event); }; Object.defineProperty(EzfaService.prototype, "savedPopupPromise", { /** * @return {?} */ get: function () { return this.savedPopupPromise_; }, /** * @param {?} promise * @return {?} */ set: function (promise) { this.savedPopupPromise_ = promise; }, enumerable: true, configurable: true }); return EzfaService; }()); EzfaService.STORAGE_KEY_PERSISTENCE = 'ezfa-local-persistence-disabled'; EzfaService.ENABLED_PROVIDERS = ['password', 'twitter.com', 'facebook.com', 'google.com', 'github.com']; EzfaService.ENABLED_OAUTH_PROVIDERS = ['twitter.com', 'facebook.com', 'google.com', 'github.com']; EzfaService.OUT_OF_BAND_MODES = { resetPassword: 'resetPassword', verifyEmail: 'verifyEmail', recoverEmail: 'recoverEmail' }; EzfaService.decorators = [ { type: Injectable }, ]; /** * @nocollapse */ EzfaService.ctorParameters = function () { return [ { type: Router, }, { type: AngularFireAuth, }, { type: EzfaOptions, }, ]; }; var EzfaModule = (function () { function EzfaModule() { } return EzfaModule; }()); EzfaModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule, ], providers: [ EzfaService ], declarations: [] },] }, ]; /** * @nocollapse */ EzfaModule.ctorParameters = function () { return []; }; var UserProviderData = (function () { /** * @param {?} user * @param {?} enabled */ function UserProviderData(user, enabled) { var _this = this; if (!user) { this.ids = []; this.oauthIds = []; } else { var userProviderIds = map(user.providerData, 'providerId'); this.ids = filter(userProviderIds, function (id) { return includes(enabled, id); }); this.oauthIds = filter(userProviderIds, function (id) { return includes(enabled, id) && 'password' !== id; }); } this.hasPassword = includes(this.ids, 'password'); this.canAddPassword = includes(enabled, 'password') && (!this.hasPassword); this.canAddOauth = filter(enabled, function (id) { return id !== 'password' && (!includes(_this.oauthIds, id)); }); } return UserProviderData; }()); /** * @abstract */ var BaseComponent = (function () { /** * @param {?} service */ function BaseComponent(service) { this.service = service; this.ngUnsubscribe = new Subject$1(); this.user = null; } /** * @return {?} */ BaseComponent.prototype.ngOnDestroy = function () { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); }; /** * @return {?} */ BaseComponent.prototype.onInitLoadUser = function () { var _this = this; return new Promise(function (resolve) { _this.service.authState.take(1).subscribe(function (firstResult) { _this.onAuthChangedUpdate(firstResult); _this.service.authState.takeUntil(_this.ngUnsubscribe).subscribe(function (subsequentResult) { _this.onAuthChangedUpdate(subsequentResult); }); resolve(); }); }); }; /** * @return {?} */ BaseComponent.prototype.gateToSignedInUser = function () { var _this = this; this.service.authState.takeUntil(this.ngUnsubscribe).subscribe(function (user) { if (!user) { _this.service.navigate(); } }); }; /** * @param {?} user * @return {?} */ BaseComponent.prototype.onAuthChangedUpdate = function (user) { this.user = user; this.userProviderData = new UserProviderData(user, this.service.providerIds); }; /** * @return {?} */ BaseComponent.prototype.gateToUserWithNoPassword = function () { var _this = this; this.service.authState.takeUntil(this.ngUnsubscribe).subscribe(function (user) { var /** @type {?} */ password = user ? find(user.providerData, { providerId: 'password' }) : null; if (password || (!user)) { return _this.service.navigate(); } }); }; /** * @return {?} */ BaseComponent.prototype.gateToUserWithPassword = function () { var _this = this; this.service.authState.takeUntil(this.ngUnsubscribe).subscribe(function (user) { var /** @type {?} */ password = user ? find(user.providerData, { providerId: 'password' }) : null; if (!password) { return _this.service.navigate(); } }); }; return BaseComponent; }()); var IndexRouteComponent = (function (_super) { __extends(IndexRouteComponent, _super); /** * @param {?} route * @param {?} service */ function IndexRouteComponent(route, service) { var _this = _super.call(this, service) || this; _this.route = route; return _this; } /** * @return {?} */ IndexRouteComponent.prototype.ngOnInit = function () { var _this = this; var /** @type {?} */ oobCode = this.route.snapshot.queryParams.oobCode || null; var /** @type {?} */ mode = this.route.snapshot.queryParams.mode || null; if ((!mode) || (!has(EzfaService.OUT_OF_BAND_MODES, mode)) || (!oobCode)) { this.service.authState.take(1).subscribe(function (user) { if (!user) { return _this.service.navigate('sign-in'); } else { return _this.service.navigate('account'); } }); return; } switch (mode) { case EzfaService.OUT_OF_BAND_MODES.recoverEmail: return this.service.navigate('recover-email', { queryParamsHandling: 'preserve' }); case EzfaService.OUT_OF_BAND_MODES.resetPassword: return this.service.navigate('reset-password', { queryParamsHandling: 'preserve' }); case EzfaService.OUT_OF_BAND_MODES.verifyEmail: return this.service.navigate('verify-email', { queryParamsHandling: 'preserve' }); } }; return IndexRouteComponent; }(BaseComponent)); IndexRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-index-route', template: "\n <p class=\"text-muted\">\n <i class=\"fa fa-spin fa-fw fa-refresh\"></i> Please wait...\n </p>\n ", styles: ["\n\n "] },] }, ]; /** * @nocollapse */ IndexRouteComponent.ctorParameters = function () { return [ { type: ActivatedRoute, }, { type: EzfaService, }, ]; }; var AccountRouteComponent = (function (_super) { __extends(AccountRouteComponent, _super); /** * @param {?} route * @param {?} service */ function AccountRouteComponent(route, service) { var _this = _super.call(this, service) || this; _this.route = route; _this.message = null; return _this; } /** * @return {?} */ AccountRouteComponent.prototype.ngOnInit = function () { var _this = this; this.service.onRouteChange('account'); this.initMessage(); this.onInitLoadUser() .then(function () { _this.gateToSignedInUser(); }); }; /** * @return {?} */ AccountRouteComponent.prototype.initMessage = function () { if (!this.route.snapshot.queryParams.message) { this.message = null; return; } var /** @type {?} */ message = parseInt(this.route.snapshot.queryParams.message, 10); this.message = isNaN(message) ? null : message; }; /** * @param {?} providerId * @return {?} */ AccountRouteComponent.prototype.addProvider = function (providerId) { var _this = this; if ('password' === providerId) { this.service.navigate('add-password'); return; } this.service.navigate('link', { queryParams: { providerId: providerId } }); if (EzfaOauthMethod.popup === this.service.oauthMethod) { this.service.savedPopupPromise = this.service.getProviderById(providerId) .then(function (provider) { return _this.user.linkWithPopup(provider); }); } }; return AccountRouteComponent; }(BaseComponent)); AccountRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-account', template: "\n <div *ngIf=\"user\">\n\n <div *ngIf=\"user.displayName\">\n <h6 class=\"text-muted mb-1\">Name</h6>\n <p>{{user.displayName}}</p>\n </div>\n <h6 class=\"text-muted mb-1\">Email</h6>\n <p>\n {{user.email}}\n <span class=\"badge badge-success\" *ngIf=\"user.emailVerified\">\n <i class=\"fa fa-fw fa-check\" aria-hidden=\"true\"></i>\n Verified\n </span>\n <span *ngIf=\"!user.emailVerified\">\n <a routerLink=\"../send-email-verification-link\">Verify</a>\n </span>\n </p>\n\n <h6 class=\"text-muted mb-1\">Sign In Methods</h6>\n <div class=\"mb-3\" *ngIf=\"userProviderData\">\n <ul class=\"list-group\">\n <li *ngIf=\"userProviderData.hasPassword\" class=\"list-group-item\">\n <div class=\"d-flex justify-content-between align-items-center\">\n <div>\n <span class=\"text-muted\">\n <ezfa-provider-icon providerId=\"password\"></ezfa-provider-icon>\n </span>\n <ezfa-provider-label providerId=\"password\"></ezfa-provider-label>\n <br>\n <small class=\"text-muted\">\n <a routerLink=\"../change-email\">Change Email</a>\n |\n <a routerLink=\"../change-password\">Change Password</a>\n </small>\n\n </div>\n <div>\n <a\n routerLink=\"../unlink\"\n [queryParams]=\"{providerId: 'password'}\"\n type=\"button\"\n *ngIf=\"userProviderData.ids.length > 1\"\n class=\"btn btn-sm btn-outline-light\"\n [ezfaProviderTitle]=\"{label: 'Remove', id: 'password'}\">\n <i class=\"fa fa-fw fa-times text-danger\"></i>\n <span class=\"sr-only\">\n Remove <ezfa-provider-label providerId=\"password\"></ezfa-provider-label>\n </span>\n </a>\n </div>\n </div>\n </li>\n <li *ngFor=\"let id of userProviderData.oauthIds\" class=\"list-group-item\">\n <div class=\"d-flex justify-content-between align-items-center\">\n <div>\n <span class=\"text-muted\">\n <ezfa-provider-icon [providerId]=\"id\"></ezfa-provider-icon>\n </span>\n <ezfa-provider-label [providerId]=\"id\"></ezfa-provider-label>\n </div>\n <div>\n <a\n routerLink=\"../unlink\"\n [queryParams]=\"{providerId: id}\"\n *ngIf=\"userProviderData.ids.length > 1\"\n class=\"btn btn-sm btn-outline-light\"\n [ezfaProviderTitle]=\"{label: 'Remove', id: id}\">\n <i class=\"fa fa-fw fa-times text-danger\"></i>\n <span class=\"sr-only\">\n Remove <ezfa-provider-label [providerId]=\"id\"></ezfa-provider-label>\n </span>\n </a>\n </div>\n </div>\n </li>\n </ul>\n\n <div *ngIf=\"userProviderData.canAddPassword || userProviderData.canAddOauth.length > 0\" >\n <small class=\"text-muted\">\n Add...\n </small>\n <div class=\"list-group\">\n <a\n *ngIf=\"userProviderData.canAddPassword\"\n routerLink=\"../add-password\"\n class=\"list-group-item list-group-item-action\"\n [ezfaProviderTitle]=\"{label: 'Add', id: 'password'}\">\n <ezfa-provider-icon providerId=\"password\"></ezfa-provider-icon>\n Add\n <ezfa-provider-label providerId=\"password\"></ezfa-provider-label>\n </a>\n <button *ngFor=\"let id of userProviderData.canAddOauth\"\n type=\"button\"\n class=\"list-group-item list-group-item-action\"\n (click)=\"addProvider(id)\"\n [ezfaProviderTitle]=\"{label: 'Add', id: id}\">\n <ezfa-provider-icon [providerId]=\"id\"></ezfa-provider-icon>\n Add\n <ezfa-provider-label [providerId]=\"id\"></ezfa-provider-label>\n </button>\n </div>\n </div>\n </div>\n\n\n <ezfa-persistence-form></ezfa-persistence-form>\n\n\n <p class=\"text-right mb-0\">\n <a routerLink=\"../sign-out\">Sign Out</a>\n </p>\n\n </div>\n ", styles: ["\n\n "] },] }, ]; /** * @nocollapse */ AccountRouteComponent.ctorParameters = function () { return [ { type: ActivatedRoute, }, { type: EzfaService, }, ]; }; var SignInRouteComponent = (function (_super) { __extends(SignInRouteComponent, _super); /** * @param {?} route * @param {?} service */ function SignInRouteComponent(route, service) { var _this = _super.call(this, service) || this; _this.route = route; _this.email = null; return _this; } /** * @return {?} */ SignInRouteComponent.prototype.ngOnInit = function () { var _this = this; this.service.onRouteChange('sign-in'); this.email = this.route.snapshot.queryParams.email || ''; this.onInitLoadUser() .then(function () { if (_this.user) { _this.service.navigate(); } }); }; return SignInRouteComponent; }(BaseComponent)); SignInRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-sign-in-route', template: "\n <div *ngIf=\"authService.passwordProviderEnabled\">\n <ezfa-email-sign-in-form [email]=\"email\"></ezfa-email-sign-in-form>\n <hr *ngIf=\"authService.oauthProviderIds.length > 0\">\n </div>\n\n <div *ngIf=\"authService.oauthProviderIds.length > 0\">\n <h6 class=\"text-muted\">\n <span *ngIf=\"!authService.passwordProviderEnabled\">Sign in with...</span>\n <span *ngIf=\"authService.passwordProviderEnabled\">Or sign in with...</span>\n </h6>\n <ezfa-oauth-sign-in></ezfa-oauth-sign-in>\n </div>\n <hr>\n <ezfa-persistence-form></ezfa-persistence-form>\n ", styles: ["\n\n "] },] }, ]; /** * @nocollapse */ SignInRouteComponent.ctorParameters = function () { return [ { type: ActivatedRoute, }, { type: EzfaService, }, ]; }; var Messages = {}; Messages.emailSaved = 1; Messages.passwordSaved = 2; Messages.passwordRemoved = 3; Messages.twitterAccountRemoved = 4; Messages.githubAccountRemoved = 5; Messages.googleAccountRemoved = 6; Messages.facebookAccountRemoved = 7; Messages.twitterAccountAdded = 8; Messages.githubAccountAdded = 9; Messages.facebookAccountAdded = 10; Messages.googleAccountAdded = 11; Messages.emailVerified = 12; Messages.passwordReset = 13; Messages.signedIn = 14; Messages.signedOut = 15; Messages[Messages.emailSaved] = "emailSaved"; Messages[Messages.passwordSaved] = "passwordSaved"; Messages[Messages.passwordRemoved] = "passwordRemoved"; Messages[Messages.twitterAccountRemoved] = "twitterAccountRemoved"; Messages[Messages.githubAccountRemoved] = "githubAccountRemoved"; Messages[Messages.googleAccountRemoved] = "googleAccountRemoved"; Messages[Messages.facebookAccountRemoved] = "facebookAccountRemoved"; Messages[Messages.twitterAccountAdded] = "twitterAccountAdded"; Messages[Messages.githubAccountAdded] = "githubAccountAdded"; Messages[Messages.facebookAccountAdded] = "facebookAccountAdded"; Messages[Messages.googleAccountAdded] = "googleAccountAdded"; Messages[Messages.emailVerified] = "emailVerified"; Messages[Messages.passwordReset] = "passwordReset"; Messages[Messages.signedIn] = "signedIn"; Messages[Messages.signedOut] = "signedOut"; var SignOutRouteComponent = (function (_super) { __extends(SignOutRouteComponent, _super); /** * @param {?} service */ function SignOutRouteComponent(service) { var _this = _super.call(this, service) || this; _this.screen = 'wait'; return _this; } /** * @return {?} */ SignOutRouteComponent.prototype.ngOnInit = function () { var _this = this; this.service.onRouteChange('sign-out'); this.service.auth.signOut() .then(function () { var /** @type {?} */ event = new EzfaSignedOutEvent(); _this.screen = 'success'; _this.service.onSignedOut(event); if (!event.redirectCancelled) { _this.service.navigate('sign-in', { queryParams: { message: Messages.signedOut } }); } }); }; return SignOutRouteComponent; }(BaseComponent)); SignOutRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-sign-out-route', template: "\n <div *ngIf=\" 'wait' === screen \" class=\"alert alert-light\" role=\"alert\">\n <i class=\"fa fa-fw fa-spin fa-refresh\" aria-hidden=\"true\"></i>\n Please wait. Signing you out...\n </div>\n <div *ngIf=\" 'success' === screen \" class=\"alert alert-success\" role=\"alert\">\n <i class=\"fa fa-fw fa-check\" aria-hidden=\"true\"></i>\n Thanks! You\u2019re signed out!\n </div>\n ", styles: ["\n\n "] },] }, ]; /** * @nocollapse */ SignOutRouteComponent.ctorParameters = function () { return [ { type: EzfaService, }, ]; }; var validateEmail = function (fc) { var /** @type {?} */ value = trim(fc.value); if (value.length === 0) { return null; } return isEmail(value) ? null : { email: true }; }; var clearControlErrors = function (fc, keys) { var /** @type {?} */ orig = fc.errors; if (!orig) { return; } var /** @type {?} */ updated = omit(orig, keys); if (Object.keys(updated).length > 0) { fc.setErrors(updated); } else { fc.setErrors(null); } }; var firebaseToFormError = function (error) { var /** @type {?} */ formError = {}; formError[error.code] = true; return formError; }; var AddPasswordRouteComponent = (function (_super) { __extends(AddPasswordRouteComponent, _super); /** * @param {?} fb * @param {?} service */ function AddPasswordRouteComponent(fb, service) { var _this = _super.call(this, service) || this; _this.fb = fb; _this.submitting = false; _this.unhandledError = null; return _this; } /** * @return {?} */ AddPasswordRouteComponent.prototype.ngOnInit = function () { var _this = this; this.service.onRouteChange('add-password'); this.id = uniqueId('ezfa-add-password-route'); this.fg = this.fb.group({ password: ['', [Validators.required]] }); this.fg.get('password').valueChanges.takeUntil(this.ngUnsubscribe).subscribe(function () { clearControlErrors(_this.fg.get('password'), ['auth/weak-password']); }); this.onInitLoadUser() .then(function () { _this.gateToUserWithNoPassword(); }); }; /** * @return {?} */ AddPasswordRouteComponent.prototype.submit = function () { var _this = this; this.submitting = true; this.unhandledError = null; var /** @type {?} */ password = this.fg.value.password; this.addPassword(/** @type {?} */ (this.user), password) .then(function (result) { _this.user = result; _this.submitting = false; _this.service.navigate('account'); }) .catch(function (error) { switch (error.code) { case 'auth/weak-password': ((_this.fg.get('password'))).setErrors(firebaseToFormError(error)); break; case 'auth/requires-recent-login': _this.service.navigate('reauthenticate', { queryParams: { redirect: 'add-password' } }); break; default: _this.unhandledError = error; break; } _this.submitting = false; }); }; /** * @param {?} user * @param {?} password * @return {?} */ AddPasswordRouteComponent.prototype.addPassword = function (user, password) { var _this = this; return new Promise(function (resolve, reject) { _this.service.getProviderById('password') .then(function (provider) { var /** @type {?} */ credential = auth$1.EmailAuthProvider.credential(/** @type {?} */ (user.email), password); return user.linkWithCredential(credential); }) .then(resolve) .catch(reject); }); }; return AddPasswordRouteComponent; }(BaseComponent)); AddPasswordRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-add-password-route', template: "\n\n <form [formGroup]=\"fg\" (ngSubmit)=\"submit()\">\n <div class=\"form-group\">\n <label [attr.for]=\"id + 'password'\">\n Choose Password\n </label>\n <ezfa-toggleable-password [control]=\"passwordInput\">\n <input\n #passwordInput\n [attr.id]=\"id + 'password'\"\n class=\"form-control\"\n [ezfaInvalidInput]=\"fg.get('password')\"\n placeholder=\"Password\"\n type=\"password\"\n [attr.aria-describedby]=\"id + 'passwordHelp'\"\n formControlName=\"password\">\n </ezfa-toggleable-password>\n <div [ezfaInvalidFeedback]=\"fg.get('password')\" key=\"required\">\n Required.\n </div>\n <div [ezfaInvalidFeedback]=\"fg.get('password')\" key=\"auth/weak-password\">\n That password is too weak.\n </div>\n <small [attr.id]=\"id + 'passwordHelp'\" class=\"form-text text-muted\">\n Please choose a strong password.\n </small>\n </div> <!-- password form-group -->\n <div class=\"form-group text-right\">\n <button\n type=\"submit\"\n [disabled]=\"submitting || fg.invalid\"\n class=\"btn\"\n [class.btn-outline-dark]=\"fg.invalid\"\n [class.btn-outline-success]=\"!fg.invalid\">\n <i class=\"fa fa-fw fa-save\" aria-hidden=\"true\"></i>\n Add Password\n </button>\n <p *ngIf=\"submitting\">\n <i class=\"fa fa-fw fa-spin fa-refresh\" aria-hidden=\"true\"></i>\n Adding password to account...\n </p>\n <p *ngIf=\"unhandledError\">\n <i class=\"fa fa-fw fa-warning text-danger\" aria-hidden=\"true\"></i>\n Error: {{unhandledError.code}}\n </p>\n </div>\n </form>\n ", styles: ["\n\n "] },] }, ]; /** * @nocollapse */ AddPasswordRouteComponent.ctorParameters = function () { return [ { type: FormBuilder, }, { type: EzfaService, }, ]; }; var UnlinkRouteComponent = (function (_super) { __extends(UnlinkRouteComponent, _super); /** * @param {?} route * @param {?} service */ function UnlinkRouteComponent(route, service) { var _this = _super.call(this, service) || this; _this.route = route; _this.providerId = null; _this.screen = 'wait'; _this.submitting = false; _this.unhandledError = null; return _this; } /** * @return {?} */ UnlinkRouteComponent.prototype.ngOnInit = function () { var _this = this; this.onInitLoadUser() .then(function () { _this.gateByUserAndProvider(); }); }; /** * @return {?} */ UnlinkRouteComponent.prototype.submit = function () { var _this = this; this.submitting = true; this.unhandledError = null; this.user.unlink(/** @type {?} */ (this.providerId)) .then(function (user) { var /** @type {?} */ event = new EzfaProviderUnlinkedEvent(user, _this.providerId); var /** @type {?} */ message; switch (_this.providerId) { case 'password': message = Messages.passwordRemoved; break; case 'twitter.com': message = Messages.twitterAccountRemoved; break; case 'facebook.com': message = Messages.facebookAccountRemoved; break; case 'google.com': message = Messages.googleAccountRemoved; break; case 'github.com': message = Messages.githubAccountRemoved; break; } _this.service.onProviderUnlinked(event); _this.service.navigate('account', { queryParams: { message: message } }); _this.submitting = false; }) .catch(function (error) { _this.submitting = false; _this.unhandledError = error; }); }; /** * @return {?} */ UnlinkRouteComponent.prototype.gateByUserAndProvider = function () { var _this = this; this.service.authState.takeUntil(this.ngUnsubscribe).subscribe(function (user) { _this.providerId = _this.route.snapshot.queryParams.providerId || null; if (!_this.providerId) { _this.service.navigate(); return; } if (!user) { _this.service.navigate(); return; } var /** @type {?} */ provider = find(user.providerData, { providerId: _this.providerId }) || null; if (!provider) { _this.service.navigate(); return; } _this.screen = 'form'; }); }; return UnlinkRouteComponent; }(BaseComponent)); UnlinkRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-unlink-route', template: "\n <div *ngIf=\" 'wait' === screen \" class=\"alert alert-info my-3\" role=\"alert\">\n <i class=\"fa fa-fw fa-spin fa-refresh\" aria-hidden=\"true\"></i>\n Please wait...\n </div>\n\n <div *ngIf=\" 'form' === screen \">\n <div class=\"card my-3\">\n <div class=\"card-body\">\n <p>\n Are you sure you want to\n <span *ngIf=\"providerId === 'password'\">remove the password</span>\n <span *ngIf=\"providerId !== 'password'\">\n unlink\n <ezfa-provider-label [providerId]=\"providerId\"></ezfa-provider-label>\n </span>\n from your account?\n </p>\n\n <div class=\"form-group text-right\">\n <p>\n <a class=\"btn btn-secondary\" routerLink=\"../account\">Cancel</a>\n <button class=\"btn btn-danger\" type=\"button\" (click)=\"submit()\">\n <i class=\"fa fa-times fa-fw\" aria-hidden=\"true\"></i>\n <span *ngIf=\"providerId !== 'password'\">\n Unlink\n <ezfa-provider-label [providerId]=\"providerId\"></ezfa-provider-label>\n </span>\n <span *ngIf=\"providerId === 'password'\">\n Remove Password\n </span>\n </button>\n </p>\n <p *ngIf=\"submitting\">\n <i class=\"fa fa-fw fa-spin fa-refresh\" aria-hidden=\"true\"></i>\n Removing <ezfa-provider-label [providerId]=\"providerId\"></ezfa-provider-label>\n sign in method....\n </p>\n <p *ngIf=\"unhandledError\">\n <i class=\"fa fa-fw fa-warning text-danger\" aria-hidden=\"true\"></i>\n Error: {{unhandledError.code}}\n </p>\n </div>\n </div>\n </div>\n </div>\n ", styles: ["\n\n "] },] }, ]; /** * @nocollapse */ UnlinkRouteComponent.ctorParameters = function () { return [ { type: ActivatedRoute, }, { type: EzfaService, }, ]; }; var LinkRouteComponent = (function (_super) { __extends(LinkRouteComponent, _super); /** * @param {?} route * @param {?} service */ function LinkRouteComponent(route, service) { var _this = _super.call(this, service) || this; _this.route = route; _this.error = null; _this.success = null; _this.wait = true; return _this; } /** * @return {?} */ LinkRouteComponent.prototype.ngOnInit = function () { var _this = this; this.service.onRouteChange('link'); this.providerId = this.route.snapshot.queryParams.providerId; if (!this.providerId) { this.service.navigate(); return; } this.onInitLoadUser() .then(function () { return _this.onInitHandleSavedPopupPromise(); }) .then(function (handled) { if (handled) { return true; } else { return _this.onInitCheckForRedirect(); } }) .then(function (handled) { if (!handled) { _this.link(); } _this.gateToSignedInUser(); }); }; /** * @return {?} */ LinkRouteComponent.prototype.link = function () { var _this = this; this.error = null; this.success = null; this.wait = true; this.service.getProviderById(this.providerId) .then(function (provider) { switch (_this.service.oauthMethod) { case EzfaOauthMethod.popup: return _this.user.linkWithPopup(provider); default: return _this.user.linkWithRedirect(provider); } }) .then(function (result) { if (result) { _this.onSuccess(result); } }) .catch(function (error) { _this.onError(error); }); }; /** * @return {?} */ LinkRouteComponent.prototype.onInitHandleSavedPopupPromise = function () { var _this = this; return new Promise(function (resolve) { var /** @type {?} */ p = _this.service.savedPopupPromise; _this.service.savedPopupPromise = null; if (!_this.user) { _this.service.navigate(); return resolve(true); } if (!p) { return resolve(false); } p.then(function (result) { _this.onSuccess(result); resolve(true); }) .catch(function (error) { _this.onError(error); resolve(true); }); }); }; /** * @return {?} */ LinkRouteComponent.prototype.onInitCheckForRedirect = function () { var _this = this; return new Promise(function (resolve) { if (!_this.user) { _this.service.navigate(); return resolve(true); } _this.service.auth.getRedirectResult() .then(function (result) { if (result.user) { _this.onSuccess(result); resolve(true); } else { resolve(false); } }) .catch(function (error) { _this.onError(error); resolve(true); }); }); }; /** * @param {?} cred * @return {?} */ LinkRouteComponent.prototype.onSuccess = function (cred) { this.error = null; var /** @type {?} */ event = new EzfaProviderLinkedEvent(cred.user, cred.credential.providerId, cred); this.success = event; this.wait = false; var /** @type {?} */ params = { message: null }; switch (cred.credential.providerId) { case 'twitter.com': params.message = Messages.twitterAccountAdded; break; case 'facebook.com': params.message = Messages.facebookAccountAdded; break; case 'github.com': params.message = Messages.githubAccountAdded; break; case 'google.com': params.message = Messages.googleAccountAdded; break; } this.service.onProviderLinked(event); this.service.navigate('account', { queryParams: params }); }; /** * @param {?} error * @return {?} */ LinkRouteComponent.prototype.onError = function (error) { this.wait = false; this.error = error; this.success = null; }; return LinkRouteComponent; }(BaseComponent)); LinkRouteComponent.decorators = [ { type: Component, args: [{ selector: 'ezfa-link-route', template: "\n <p class=\"text-muted\" *ngIf=\"wait\">\n <i class=\"fa fa-spin fa-fw fa-refresh\"></i> Please wait...\n </p>\n\n <div *ngIf=\"error\">\n <div [ngSwitch]=\"error.code\" class=\"alert alert-danger my-3\" role=\"alert\">\n <p>\n <i class=\"fa fa-fw fa-warning\"></i>\n <strong>\n Account Link Error\n </strong>\n </p>\n <div *ngSwitchCase=\"'auth/credential-already-in-use'\">\n <p>\n The <ezfa-provider-label [providerId]=\"error.credential.providerId\"></ezfa-provider-label>\n account you tried to add is already associated with a different\n <ezfa-application-l