|
51 | 51 | $createUser: this.createUser.bind(this), |
52 | 52 | $changePassword: this.changePassword.bind(this), |
53 | 53 | $removeUser: this.removeUser.bind(this), |
54 | | - $sendPasswordResetEmail: this.sendPasswordResetEmail.bind(this) |
| 54 | + $resetPassword: this.resetPassword.bind(this), |
| 55 | + $sendPasswordResetEmail: this.resetPassword.bind(this) |
55 | 56 | }; |
56 | 57 |
|
57 | 58 | return this._object; |
|
196 | 197 | // Creates a new email/password user. Note that this function only creates the user, if you |
197 | 198 | // wish to log in as the newly created user, call $authWithPassword() after the promise for |
198 | 199 | // this method has been resolved. |
199 | | - createUser: function(email, password) { |
| 200 | + createUser: function(emailOrCredentials, password) { |
200 | 201 | var deferred = this._q.defer(); |
201 | 202 |
|
202 | | - this._ref.createUser({ |
203 | | - email: email, |
204 | | - password: password |
205 | | - }, function(error) { |
| 203 | + // Allow this method to take a single credentials argument or two separate string arguments |
| 204 | + var credentials = emailOrCredentials; |
| 205 | + if (typeof emailOrCredentials === "string") { |
| 206 | + credentials = { |
| 207 | + email: emailOrCredentials, |
| 208 | + password: password |
| 209 | + }; |
| 210 | + } |
| 211 | + |
| 212 | + this._ref.createUser(credentials, function(error) { |
206 | 213 | if (error !== null) { |
207 | 214 | deferred.reject(error); |
208 | 215 | } else { |
|
214 | 221 | }, |
215 | 222 |
|
216 | 223 | // Changes the password for an email/password user. |
217 | | - changePassword: function(email, oldPassword, newPassword) { |
| 224 | + changePassword: function(emailOrCredentials, oldPassword, newPassword) { |
218 | 225 | var deferred = this._q.defer(); |
219 | 226 |
|
220 | | - this._ref.changePassword({ |
221 | | - email: email, |
222 | | - oldPassword: oldPassword, |
223 | | - newPassword: newPassword |
224 | | - }, function(error) { |
225 | | - if (error !== null) { |
226 | | - deferred.reject(error); |
227 | | - } else { |
228 | | - deferred.resolve(); |
229 | | - } |
| 227 | + // Allow this method to take a single credentials argument or three separate string arguments |
| 228 | + var credentials = emailOrCredentials; |
| 229 | + if (typeof emailOrCredentials === "string") { |
| 230 | + credentials = { |
| 231 | + email: emailOrCredentials, |
| 232 | + oldPassword: oldPassword, |
| 233 | + newPassword: newPassword |
| 234 | + }; |
| 235 | + } |
| 236 | + |
| 237 | + this._ref.changePassword(credentials, function(error) { |
| 238 | + if (error !== null) { |
| 239 | + deferred.reject(error); |
| 240 | + } else { |
| 241 | + deferred.resolve(); |
230 | 242 | } |
231 | | - ); |
| 243 | + }); |
232 | 244 |
|
233 | 245 | return deferred.promise; |
234 | 246 | }, |
235 | 247 |
|
236 | 248 | // Removes an email/password user. |
237 | | - removeUser: function(email, password) { |
| 249 | + removeUser: function(emailOrCredentials, password) { |
238 | 250 | var deferred = this._q.defer(); |
239 | 251 |
|
240 | | - this._ref.removeUser({ |
241 | | - email: email, |
242 | | - password: password |
243 | | - }, function(error) { |
| 252 | + // Allow this method to take a single credentials argument or two separate string arguments |
| 253 | + var credentials = emailOrCredentials; |
| 254 | + if (typeof emailOrCredentials === "string") { |
| 255 | + credentials = { |
| 256 | + email: emailOrCredentials, |
| 257 | + password: password |
| 258 | + }; |
| 259 | + } |
| 260 | + |
| 261 | + this._ref.removeUser(credentials, function(error) { |
244 | 262 | if (error !== null) { |
245 | 263 | deferred.reject(error); |
246 | 264 | } else { |
|
252 | 270 | }, |
253 | 271 |
|
254 | 272 | // Sends a password reset email to an email/password user. |
255 | | - sendPasswordResetEmail: function(email) { |
| 273 | + resetPassword: function(emailOrCredentials) { |
256 | 274 | var deferred = this._q.defer(); |
257 | 275 |
|
258 | | - this._ref.resetPassword({ |
259 | | - email: email |
260 | | - }, function(error) { |
| 276 | + // Allow this method to take a single credentials argument or a single string argument |
| 277 | + var credentials = emailOrCredentials; |
| 278 | + if (typeof emailOrCredentials === "string") { |
| 279 | + credentials = { |
| 280 | + email: emailOrCredentials |
| 281 | + }; |
| 282 | + } |
| 283 | + |
| 284 | + this._ref.resetPassword(credentials, function(error) { |
261 | 285 | if (error !== null) { |
262 | 286 | deferred.reject(error); |
263 | 287 | } else { |
|
0 commit comments