diff --git a/angularfire/angularfire-tests.ts b/angularfire/angularfire-tests.ts index 7d39e4181d..d636c88e60 100644 --- a/angularfire/angularfire-tests.ts +++ b/angularfire/angularfire-tests.ts @@ -62,8 +62,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi obj.$save(); }); - // $inst() - if (obj.$inst() !== sync) throw "error"; + // $ref() + if (obj.$ref() !== sync) throw "error"; // $bindTo() obj.$bindTo($scope, "data").then(function () { @@ -81,8 +81,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi // $destroy() obj.$destroy(); - // $extendFactory() - var NewFactory = $FirebaseObject.$extendFactory({ + // $extend() + var NewFactory = $FirebaseObject.$extend({ getMyFavoriteColor: function () { return this.favoriteColor + ", no green!"; // obscure Monty Python reference } @@ -94,8 +94,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi { var list = sync.$asArray(); - // $inst() - if (list.$inst() !== sync) throw "error"; + // $ref() + if (list.$ref() !== sync) throw "error"; // $add() list.$add({ foo: "foo value" }); @@ -145,8 +145,8 @@ myapp.controller("MyController", ["$scope", "$firebase", '$FirebaseObject', '$Fi // $destroy() list.$destroy(); - // $extendFactory() - var ArrayWithSum = $FirebaseArray.$extendFactory({ + // $extend() + var ArrayWithSum = $FirebaseArray.$extend({ sum: function () { var total = 0; angular.forEach(this.$list, function (rec) { @@ -167,30 +167,43 @@ interface AngularFireAuthScope extends ng.IScope { loginObj: AngularFireAuth; } -myapp.controller("MyAuthController", ["$scope", "$firebaseSimpleLogin", - function($scope: AngularFireAuthScope, $firebaseSimpleLogin: AngularFireAuthService) { +myapp.controller("MyAuthController", ["$scope", "$firebaseAuth", + function($scope: AngularFireAuthScope, $firebaseAuth: AngularFireAuthService) { var dataRef = new Firebase(url); - $scope.loginObj = $firebaseSimpleLogin(dataRef); - $scope.loginObj.$getCurrentUser().then(_ => { - }); - var email = 'my@email.com'; - var password = 'mypassword'; - $scope.loginObj.$login('password', { - email: email, - password: password - }).then(function(user) { - console.log('Logged in as: ', user.uid); - }, function(error) { - console.error('Login failed: ', error); - }); - $scope.loginObj.$logout(); - $scope.loginObj.$createUser(email, password).then(_ => { - }); - $scope.loginObj.$changePassword(email, password, password).then(_ => { - }); - $scope.loginObj.$removeUser(email, password).then(_ => { - }); - $scope.loginObj.$sendPasswordResetEmail(email).then(_ => { - }); + $scope.loginObj = $firebaseAuth(dataRef); + $scope.loginObj.$getAuth(); + var credentials = { + email: 'my@email.com', + password: 'mypassword' + }; + var resetPasswordCredentials = { + email: 'my@email.com' + }; + var changePasswordCredentials = { + email: 'my@email.com', + oldPassword: 'mypassword', + newPassword: 'mypassword' + }; + var changeUserCredentials = { + oldEmail: 'my@email.com', + newEmail: 'my@email.com', + password: 'mypassword' + }; + $scope.loginObj.$authWithCustomToken("token").then(_ => {}); + $scope.loginObj.$authAnonymously().then(_ => {}); + $scope.loginObj.$authWithPassword(credentials).then(_ => {}); + $scope.loginObj.$authWithOAuthPopup("github").then(_ => {}); + $scope.loginObj.$authWithOAuthRedirect("google").then(_ => {}); + $scope.loginObj.$authWithOAuthToken("twitter", "token").then(_ => {}); + $scope.loginObj.$getAuth(); + $scope.loginObj.$onAuth(() => {}); + $scope.loginObj.$unauth(); + $scope.loginObj.$waitForAuth(); + $scope.loginObj.$requireAuth(); + $scope.loginObj.$createUser(credentials).then(_ => {}); + $scope.loginObj.$removeUser(credentials).then(_ => {}); + $scope.loginObj.$changeEmail(changeUserCredentials).then(_ => {}); + $scope.loginObj.$changePassword(changePasswordCredentials).then(_ => {}); + $scope.loginObj.$resetPassword(resetPasswordCredentials).then(_ => {}); } -]); \ No newline at end of file +]); diff --git a/angularfire/angularfire.d.ts b/angularfire/angularfire.d.ts index e4129e4bab..195fde1a04 100644 --- a/angularfire/angularfire.d.ts +++ b/angularfire/angularfire.d.ts @@ -28,17 +28,18 @@ interface AngularFireObject extends AngularFireSimpleObject { $id: string; $priority: number; $value: any; + $remove(): ng.IPromise; $save(): ng.IPromise; $loaded(resolve?: (x: AngularFireObject) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; $loaded(resolve?: (x: AngularFireObject) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; $loaded(resolve?: (x: AngularFireObject) => void, reject?: (err: any) => any): ng.IPromise; - $inst(): AngularFire; + $ref(): AngularFire; $bindTo(scope: ng.IScope, varName: string): ng.IPromise; $watch(callback: Function, context?: any): Function; $destroy(): void; } interface AngularFireObjectService { - $extendFactory(ChildClass: Object, methods?: Object): Object; + $extend(ChildClass: Object, methods?: Object): Object; } interface AngularFireArray extends Array { @@ -51,12 +52,12 @@ interface AngularFireArray extends Array { $loaded(resolve?: (x: AngularFireArray) => ng.IHttpPromise<{}>, reject?: (err: any) => any): ng.IPromise; $loaded(resolve?: (x: AngularFireArray) => ng.IPromise<{}>, reject?: (err: any) => any): ng.IPromise; $loaded(resolve?: (x: AngularFireArray) => void, reject?: (err: any) => any): ng.IPromise; - $inst(): AngularFire; + $ref(): AngularFire; $watch(cb: (event: string, key: string, prevChild: string) => void, context?: any): Function; $destroy(): void; } interface AngularFireArrayService { - $extendFactory(ChildClass: Object, methods?: Object): Object; + $extend(ChildClass: Object, methods?: Object): Object; } interface AngularFireSimpleObject { @@ -72,11 +73,20 @@ interface AngularFireAuthService { } interface AngularFireAuth { - $getCurrentUser(): ng.IPromise; - $login(provider: string, options?: Object): ng.IPromise; - $logout(): void; - $createUser(email: string, password: string): ng.IPromise; - $changePassword(email: string, oldPassword: string, newPassword: string): ng.IPromise; - $removeUser(email: string, password: string): ng.IPromise; - $sendPasswordResetEmail(email: string): ng.IPromise; + $authWithCustomToken(authToken: string, options?: Object): ng.IPromise; + $authAnonymously(options?: Object): ng.IPromise; + $authWithPassword(credentials: FirebaseCredentials, options?: Object): ng.IPromise; + $authWithOAuthPopup(provider: string, options?: Object): ng.IPromise; + $authWithOAuthRedirect(provider: string, options?: Object): ng.IPromise; + $authWithOAuthToken(provider: string, credentials: Object|string, options?: Object): ng.IPromise; + $getAuth(): FirebaseAuthData; + $onAuth(callback: Function, context?: any): Function; + $unauth(): void; + $waitForAuth(): ng.IPromise; + $requireAuth(): ng.IPromise; + $createUser(credentials: FirebaseCredentials): ng.IPromise; + $removeUser(credentials: FirebaseCredentials): ng.IPromise; + $changeEmail(credentials: FirebaseNewUserCredentials): ng.IPromise; + $changePassword(credentials: FirebaseNewPasswordCredentials): ng.IPromise; + $resetPassword(credentials: FirebaseResetPasswordCredentials): ng.IPromise; } diff --git a/firebase/firebase.d.ts b/firebase/firebase.d.ts index fdb808ec44..4c9ac86593 100644 --- a/firebase/firebase.d.ts +++ b/firebase/firebase.d.ts @@ -9,6 +9,11 @@ interface FirebaseAuthResult { } interface FirebaseDataSnapshot { + /** + * Returns true if this DataSnapshot contains any data. + * It is slightly more efficient than using snapshot.val() !== null. + */ + exists(): boolean; /** * Gets the JavaScript object representation of the DataSnapshot. */ @@ -108,6 +113,10 @@ interface FirebaseQuery { * Generates a new Query object ordered by key name. */ orderByKey(): FirebaseQuery; + /** + * Generates a new Query object ordered by child values. + */ + orderByValue(): FirebaseQuery; /** * Generates a new Query object ordered by priority. */ @@ -255,10 +264,14 @@ interface Firebase extends FirebaseQuery { * Creates a new user account using an email / password combination. */ createUser(credentials: FirebaseCredentials, onComplete: (error: any) => void): void; + /** + * Updates the email associated with an email / password user account. + */ + changeEmail(credentials: FirebaseNewUserCredentials, onComplete: (error: any) => void): void; /** * Change the password of an existing user using an email / password combination. */ - changePassword(credentials: { email: string; oldPassword: string; newPassword: string }, onComplete: (error: any) => void): void; + changePassword(credentials: FirebaseNewPasswordCredentials, onComplete: (error: any) => void): void; /** * Removes an existing user account using an email / password combination. */ @@ -266,7 +279,7 @@ interface Firebase extends FirebaseQuery { /** * Sends a password-reset email to the owner of the account, containing a token that may be used to authenticate and change the user password. */ - resetPassword(credentials: { email: string }, onComplete: (error: any) => void): void; + resetPassword(credentials: FirebaseResetPasswordCredentials, onComplete: (error: any) => void): void; onDisconnect(): FirebaseOnDisconnect; } interface FirebaseStatic { @@ -305,4 +318,20 @@ interface FirebaseAuthData { interface FirebaseCredentials { email: string; password: string; -} \ No newline at end of file +} + +interface FirebaseNewPasswordCredentials { + email: string; + oldPassword: string; + newPassword: string; +} + +interface FirebaseNewUserCredentials { + oldEmail: string; + newEmail: string; + password: string; +} + +interface FirebaseResetPasswordCredentials { + email: string; +}