|
282 | 282 | }; |
283 | 283 |
|
284 | 284 | // Attach an event handler for when the object is changed. You can attach |
285 | | - // handlers for all Firebase events. Additionally, the following events, |
286 | | - // specific to AngularFire, can be attached to. |
| 285 | + // handlers for all Firebase events like "child_added", "value", and |
| 286 | + // "child_removed". Additionally, the following events, specific to |
| 287 | + // AngularFire, can be listened to. |
287 | 288 | // |
288 | 289 | // - "change": The provided function will be called whenever the local |
289 | 290 | // object is modified because the remote data was updated. |
|
442 | 443 | self._updateModel(key, val); |
443 | 444 | } |
444 | 445 |
|
| 446 | + // Helper function to attach and broadcast events. |
445 | 447 | function _handleAndBroadcastEvent(type, handler) { |
446 | 448 | return function(snapshot, prevChild) { |
447 | 449 | handler(snapshot, prevChild); |
|
659 | 661 | // will at a minimum contain the `id` and `provider` properties. |
660 | 662 | // |
661 | 663 | // The returned object will also have the following methods available: |
662 | | - // $login(), $logout(), $createUser() and $changePassword(). |
| 664 | + // $login(), $logout(), $createUser(), $changePassword(), $removeUser(), |
| 665 | + // and $getCurrentUser(). |
663 | 666 | return function(ref) { |
664 | 667 | var auth = new AngularFireAuth($q, $t, $rs, ref); |
665 | 668 | return auth.construct(); |
|
717 | 720 | var deferred = this._q.defer(); |
718 | 721 | var self = this; |
719 | 722 |
|
720 | | - //To avoid the promise from being fulfilled by our initial login state, make sure we have it before |
721 | | - //triggering the login and creating a new promise. |
| 723 | + // To avoid the promise from being fulfilled by our initial login state, |
| 724 | + // make sure we have it before triggering the login and creating a new |
| 725 | + // promise. |
722 | 726 | this.getCurrentUser().then(function() { |
723 | 727 | self._loginDeferred = deferred; |
724 | 728 | self._authClient.login(provider, options); |
|
729 | 733 |
|
730 | 734 | // Unauthenticate the Firebase reference. |
731 | 735 | logout: function() { |
732 | | - //tell the simple login client to log us out. |
| 736 | + // Tell the simple login client to log us out. |
733 | 737 | this._authClient.logout(); |
734 | 738 |
|
735 | | - //forget who we were, so that any getCurrentUser calls will wait for another user event. |
| 739 | + // Forget who we were, so that any getCurrentUser calls will wait for |
| 740 | + // another user event. |
736 | 741 | delete this._currentUserData; |
737 | 742 | }, |
738 | 743 |
|
739 | | - // Creates a user for Firebase Simple Login. |
740 | | - // Function 'cb' receives an error as the first argument and a |
741 | | - // Simple Login user object as the second argument. Pass noLogin=true |
742 | | - // if you don't want the newly created user to also be logged in. |
| 744 | + // Creates a user for Firebase Simple Login. Function 'cb' receives an |
| 745 | + // error as the first argument and a Simple Login user object as the second |
| 746 | + // argument. Set the optional 'noLogin' argument to true if you don't want |
| 747 | + // the newly created user to also be logged in. |
743 | 748 | createUser: function(email, password, noLogin) { |
744 | 749 | var self = this; |
745 | 750 | var deferred = this._q.defer(); |
|
750 | 755 | deferred.reject(err); |
751 | 756 | } else { |
752 | 757 | if (!noLogin) { |
753 | | - //resolve the promise with a new promise for login |
754 | | - deferred.resolve(self.login("password", {email: email, password: password})); |
| 758 | + // Resolve the promise with a new promise for login. |
| 759 | + deferred.resolve(self.login("password", { |
| 760 | + email: email, |
| 761 | + password: password |
| 762 | + })); |
755 | 763 | } else { |
756 | 764 | deferred.resolve(user); |
757 | 765 | } |
|
761 | 769 | return deferred.promise; |
762 | 770 | }, |
763 | 771 |
|
764 | | - // Changes the password for a Firebase Simple Login user. |
765 | | - // Take an email, old password and new password as three mandatory |
766 | | - // arguments. Returns a promise. |
| 772 | + // Changes the password for a Firebase Simple Login user. Take an email, |
| 773 | + // old password and new password as three mandatory arguments. Returns a |
| 774 | + // promise. |
767 | 775 | changePassword: function(email, oldPassword, newPassword) { |
768 | 776 | var self = this; |
769 | 777 | var deferred = this._q.defer(); |
770 | 778 |
|
771 | | - self._authClient.changePassword(email, oldPassword, newPassword, function(err) { |
772 | | - if (err) { |
773 | | - self._rootScope.$broadcast("$firebaseSimpleLogin:error", err); |
774 | | - deferred.reject(err); |
775 | | - } else { |
776 | | - deferred.resolve(); |
| 779 | + self._authClient.changePassword(email, oldPassword, newPassword, |
| 780 | + function(err) { |
| 781 | + if (err) { |
| 782 | + self._rootScope.$broadcast("$firebaseSimpleLogin:error", err); |
| 783 | + deferred.reject(err); |
| 784 | + } else { |
| 785 | + deferred.resolve(); |
| 786 | + } |
777 | 787 | } |
778 | | - }); |
| 788 | + ); |
779 | 789 |
|
780 | 790 | return deferred.promise; |
781 | 791 | }, |
782 | 792 |
|
783 | | - //Gets a promise for the current user info |
| 793 | + // Gets a promise for the current user info. |
784 | 794 | getCurrentUser: function() { |
785 | 795 | var self = this; |
786 | 796 | var deferred = this._q.defer(); |
|
794 | 804 | return deferred.promise; |
795 | 805 | }, |
796 | 806 |
|
797 | | - //Remove a user for the listed email address. Returns a promise. |
| 807 | + // Remove a user for the listed email address. Returns a promise. |
798 | 808 | removeUser: function(email, password) { |
799 | 809 | var self = this; |
800 | 810 | var deferred = this._q.defer(); |
|
811 | 821 | return deferred.promise; |
812 | 822 | }, |
813 | 823 |
|
814 | | - //Send a password reset email to the user for an email + password account. |
815 | | - //resetPassword: function() { |
816 | | - //coming soon... |
| 824 | + // Send a password reset email to the user for an email + password account. |
| 825 | + // resetPassword: function() { |
| 826 | + // Stub: Coming soon to Simple Login. |
817 | 827 | //}, |
818 | 828 |
|
819 | 829 | // Internal callback for any Simple Login event. |
820 | 830 | _onLoginEvent: function(err, user) { |
821 | | - |
822 | 831 | // HACK -- calls to logout() trigger events even if we're not logged in, |
823 | 832 | // making us get extra events. Throw them away. This should be fixed by |
824 | | - // changing Simple Login so that its callbacks refer directly to the action that caused them. |
825 | | - if(this._currentUserData === user && err === null) { |
| 833 | + // changing Simple Login so that its callbacks refer directly to the |
| 834 | + // action that caused them. |
| 835 | + if (this._currentUserData === user && err === null) { |
826 | 836 | return; |
827 | 837 | } |
828 | 838 |
|
|
0 commit comments