Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from guillaume-roy/master
Browse files Browse the repository at this point in the history
Implement changePassword feature
  • Loading branch information
EddyVerbruggen committed Apr 30, 2016
2 parents 4917d67 + f5bd366 commit 9ad84f3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,23 @@ You can expect more login mechanisms to be added in the future.
}).then(
function () {
// called when password reset was successful,
// you ccould now prompt the user to check his email
// you could now prompt the user to check his email
},
function (errorMessage) {
console.log(errorMessage);
}
)
```

#### Changing a password
```js
firebase.changePassword({
email: '[email protected]',
oldPassword: 'myOldPassword',
newPassword: 'myNewPassword'
}).then(
function () {
// called when password change was successful,
},
function (errorMessage) {
console.log(errorMessage);
Expand Down
24 changes: 24 additions & 0 deletions firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,30 @@ firebase.resetPassword = function (arg) {
});
};

firebase.changePassword = function (arg) {
return new Promise(function (resolve, reject) {
try {
var resultHandler = new com.firebase.client.Firebase.ResultHandler({
onSuccess: function () {
resolve();
},
onError: function (firebaseError) {
reject(firebaseError.getMessage());
}
});

if (!arg.email || !arg.oldPassword || !arg.newPassword) {
reject("Changing a password requires an email and an oldPassword and a newPassword arguments");
} else {
instance.changePassword(arg.email, arg.oldPassword, arg.newPassword, resultHandler);
}
} catch (ex) {
console.log("Error in firebase.changePassword: " + ex);
reject(ex);
}
});
};

firebase.createUser = function (arg) {
return new Promise(function (resolve, reject) {
try {
Expand Down
10 changes: 10 additions & 0 deletions firebase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,20 @@ declare module "nativescript-plugin-firebase" {
value: any;
}

/**
* The options object passed into the changePassword function.
*/
export interface ChangePasswordOptions {
email: string;
oldPassword: string;
newPassword: string
}

export function init(options: InitOptions): Promise<any>;
export function login(options: LoginOptions): Promise<LoginResult>;
export function createUser(options: CreateUserOptions): Promise<CreateUserResult>;
export function resetPassword(options: ResetPasswordOptions): Promise<any>;
export function changePassword(options: ChangePasswordOptions): Promise<any>;
export function push(path: string, value: any): Promise<PushResult>;
export function setValue(path: string, value: any): Promise<any>;
export function update(path: string, value: any): Promise<any>;
Expand Down
23 changes: 23 additions & 0 deletions firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ firebase.resetPassword = function (arg) {
});
};

firebase.changePassword = function (arg) {
return new Promise(function (resolve, reject) {
try {
var onCompletion = function(error) {
if (error) {
reject(error.localizedDescription);
} else {
resolve();
}
};

if (!arg.email || !arg.oldPassword || !arg.newPassword) {
reject("Changing a password requires an email and an oldPassword and a newPassword arguments");
} else {
instance.changePasswordForUserFromOldToNewWithCompletionBlock(arg.email, arg.oldPassword, arg.newPassword, onCompletion);
}
} catch (ex) {
console.log("Error in firebase.changePassword: " + ex);
reject(ex);
}
});
};

firebase.createUser = function (arg) {
return new Promise(function (resolve, reject) {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-plugin-firebase",
"version": "2.1.6",
"version": "2.1.7",
"description" : "Fire. Base. Firebase!",
"main" : "firebase.js",
"nativescript": {
Expand Down

0 comments on commit 9ad84f3

Please sign in to comment.