From 3038ca95cb8c08db221bbcd2ba51d9cfaf082a70 Mon Sep 17 00:00:00 2001 From: steven feaster Date: Mon, 30 Jun 2014 12:29:19 -0700 Subject: [PATCH] Adding password provider specific functions --- firebase-login.html | 78 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/firebase-login.html b/firebase-login.html index d1711ea..ed5085a 100644 --- a/firebase-login.html +++ b/firebase-login.html @@ -34,6 +34,30 @@ * @event error */ + /** + * Fired when user is created (password provider type) + * + * @event user-created + */ + + /** + * Fired when user changes their password (password provider type) + * + * @event password-changed + */ + + /** + * Fired when password reset email is sent (password provider type) + * + * @event password-reset + */ + + /** + * Fired when user is removed (password provider type) + * + * @event removed-user + */ + /** * Firebase location URL (must have simple login enabled via Forge interface). * @attribute location @@ -78,6 +102,13 @@ */ 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 @@ -143,7 +174,52 @@ this.login(this.queuedLogin.provider, this.queuedLogin.params); this.queuedLogin = null; } - } + }, + + create: function(email, password) { + if (this.passwordRequired && email != "" && password == "") { + this.fire('error', {message:{message:"Password required"}}) + return; + } + + this.auth.createUser(email, password, function(error, user) { + if (!error) { + this.fire('user-created', {user: user}); + } else { + this.fire('error', {message: error}); + } + }.bind(this)); + }, + + 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}); + } + }.bind(this)); + }, + + sendPasswordResetEmail: function(email) { + this.auth.sendPasswordResetEmail(email, function(error, success) { + if (!error) { + this.fire('password-reset'); + } else { + this.fire('error', {message: error}); + } + }.bind(this)); + }, + + removeUser: function(email, password) { + this.auth.removeUser(email, password, function(error, success) { + if (!error) { + this.fire('removed-user'); + } else { + this.fire('error', {message: error}); + } + }.bind(this)); + } });