Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Rationalized & documented API
Browse files Browse the repository at this point in the history
- Renamed `removed-user` to `user-removed`
- Renamed `create` to `createUser`
- Removed `passwordRequred` property/error (password validation should be done in client, since there is nothing enforced on server)
- Put FB error object directly into event detail
  • Loading branch information
kevinpschaaf committed Aug 5, 2014
1 parent e764162 commit aa667d7
Showing 1 changed file with 90 additions and 20 deletions.
110 changes: 90 additions & 20 deletions firebase-login.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
/**
* Fired when user is removed (password provider type)
*
* @event removed-user
* @event user-removed
*/

/**
Expand Down Expand Up @@ -102,13 +102,6 @@
*/
params: null,

/**
* When using a password provider this allows passwords to be required (Firebase does not require passwords)
* @attribute passwordRequired
* @type Boolean
*/
passwordRequired: false,

ready: function() {
if (!this.location) {
// FIXME(kschaaf): doesn't seem to be a way to un-register auth callbacks, so
Expand All @@ -119,7 +112,7 @@
this.auth = new FirebaseSimpleLogin(this.ref, function(error, user) {
if (error) {
// an error occurred while attempting login
this.fire('error', {message: error});
this.fire('error', error);
} else if (user) {
// user authenticated with Firebase
this.user = user;
Expand All @@ -145,6 +138,26 @@
}.bind(this));
},

/**
* Performs a login attempt, using the `provider` specified via attribute/property,
* or optionally via `provider` argument to the `login` function. Optionally,
* provider-specific login parameters can be specified via attribute (JSON)/property,
* or via the `params` argument to the `login` function.
*
* If the login is successful, the `login` event is fired, with `e.detail.user`
* containing the authenticated user object from Firebase.
*
* If login fails, the `error` event is fired, with `e.detail` containing error
* information supplied from Firebase.
*
* If the browswer supports `navigator.onLine` network status reporting and the
* network is currently offline, the login attempt will be queued until the network
* is restored.
*
* @method login
* @param {string} provider (optional)
* @param {string} params (optional)
*/
login: function(provider, params) {
if (navigator.onLine === false) {
this.queuedLogin = {provider: provider, params: params};
Expand All @@ -158,6 +171,20 @@
}
},

/**
* Performs a logout attempt.
*
* If the login is successful, the `logout` event is fired.
*
* If login fails, the `error` event is fired, with `e.detail` containing error
* information supplied from Firebase.
*
* If the browswer supports `navigator.onLine` network status reporting and the
* network is currently offline, the logout attempt will be queued until the network
* is restored.
*
* @method logout
*/
logout: function() {
if (navigator.onLine === false) {
this.queuedLogout = true;
Expand All @@ -176,47 +203,90 @@
}
},

create: function(email, password) {
if (this.passwordRequired && email != "" && password == "") {
this.fire('error', {message:{message:"Password required"}})
return;
}

/**
* Creates a "password provider"-based user account.
*
* If the operation is successful, the `user-created` event is fired.
*
* If the operation fails, the `error` event is fired, with `e.detail`
* containing error information supplied from Firebase.
*
* @method createUser
* @param {string} email
* @param {string} password
*/
createUser: function(email, password) {
this.auth.createUser(email, password, function(error, user) {
if (!error) {
this.fire('user-created', {user: user});
} else {
this.fire('error', {message: error});
this.fire('error', error);
}
}.bind(this));
},

/**
* Changes the password of a "password provider"-based user account.
*
* If the operation is successful, the `user-created` event is fired.
*
* If the operation fails, the `error` event is fired, with `e.detail`
* containing error information supplied from Firebase.
*
* @method changePassword
* @param {string} email
* @param {string} oldPassword
* @param {string} newPassword
*/
changePassword: function(email, oldPassword, newPassword) {
this.auth.changePassword(email, oldPassword, newPassword, function(error, success) {
if (!error) {
this.fire('password-changed');
} else {
this.fire('error', {message: error});
this.fire('error', error);
}
}.bind(this));
},

/**
* Sends a password reset email for a "password provider"-based user account.
*
* If the operation is successful, the `user-created` event is fired.
*
* If the operation fails, the `error` event is fired, with `e.detail`
* containing error information supplied from Firebase.
*
* @method sendPasswordResetEmail
* @param {string} email
*/
sendPasswordResetEmail: function(email) {
this.auth.sendPasswordResetEmail(email, function(error, success) {
if (!error) {
this.fire('password-reset');
} else {
this.fire('error', {message: error});
this.fire('error', error);
}
}.bind(this));
},

/**
* Removes a "password provider"-based user account.
*
* If the operation is successful, the `user-created` event is fired.
*
* If the operation fails, the `error` event is fired, with `e.detail`
* containing error information supplied from Firebase.
*
* @method removeUser
* @param {string} email
* @param {string} password
*/
removeUser: function(email, password) {
this.auth.removeUser(email, password, function(error, success) {
if (!error) {
this.fire('removed-user');
this.fire('user-removed');
} else {
this.fire('error', {message: error});
this.fire('error', error);
}
}.bind(this));
}
Expand Down

0 comments on commit aa667d7

Please sign in to comment.