Guest User

Untitled

a guest
Jan 18th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. cognitoUser.forgotPassword({
  2. onSuccess: function (result) {
  3. console.log('call result: ' + result);
  4. },
  5. onFailure: function(err) {
  6. alert(err);
  7. },
  8. inputVerificationCode() {
  9. var verificationCode = prompt('Please input verification code ' ,'');
  10. var newPassword = prompt('Enter new password ' ,'');
  11. cognitoUser.confirmPassword(verificationCode, newPassword, this);
  12. }
  13. });
  14.  
  15. export function resetPassword(username) {
  16. // const poolData = { UserPoolId: xxxx, ClientId: xxxx };
  17. // userPool is const userPool = new AWSCognito.CognitoUserPool(poolData);
  18.  
  19. // setup cognitoUser first
  20. cognitoUser = new AWSCognito.CognitoUser({
  21. Username: username,
  22. Pool: userPool
  23. });
  24.  
  25. // call forgotPassword on cognitoUser
  26. cognitoUser.forgotPassword({
  27. onSuccess: function(result) {
  28. console.log('call result: ' + result);
  29. },
  30. onFailure: function(err) {
  31. alert(err);
  32. },
  33. inputVerificationCode() { // this is optional, and likely won't be implemented as in AWS's example (i.e, prompt to get info)
  34. var verificationCode = prompt('Please input verification code ', '');
  35. var newPassword = prompt('Enter new password ', '');
  36. cognitoUser.confirmPassword(verificationCode, newPassword, this);
  37. }
  38. });
  39. }
  40.  
  41. // confirmPassword can be separately built out as follows...
  42. export function confirmPassword(username, verificationCode, newPassword) {
  43. cognitoUser = new AWSCognito.CognitoUser({
  44. Username: username,
  45. Pool: userPool
  46. });
  47.  
  48. return new Promise((resolve, reject) => {
  49. cognitoUser.confirmPassword(verificationCode, newPassword, {
  50. onFailure(err) {
  51. reject(err);
  52. },
  53. onSuccess() {
  54. resolve();
  55. },
  56. });
  57. });
  58. }
  59.  
  60. //validation of input from form
  61. req.checkBody('email', 'Username is required').notEmpty();
  62. req.checkBody('password', 'Password is required').notEmpty();
  63. req.checkBody('confirmationcode', 'Confirmation Code is required').notEmpty();
  64.  
  65.  
  66. var confirmationCode = req.body.confirmationcode;
  67. var password = req.body.password;
  68. var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
  69.  
  70.  
  71. var userData = {
  72. Username: req.body.email,
  73. Pool: userPool
  74. };
  75. var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
  76.  
  77. cognitoUser.confirmPassword(confirmationCode, password, {
  78. onFailure(err) {
  79. console.log(err);
  80. },
  81. onSuccess() {
  82. console.log("Success");
  83. },
  84. });
Add Comment
Please, Sign In to add comment