change-password.page.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. parasails.registerPage('change-password', {
  2. // ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
  3. // ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
  4. // ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
  5. data: {
  6. // Main syncing/loading state for this page.
  7. syncing: false,
  8. // Form data
  9. formData: { /* … */ },
  10. // For tracking client-side validation errors in our form.
  11. // > Has property set to `true` for each invalid property in `formData`.
  12. formErrors: { /* … */ },
  13. // Server error state for the form
  14. cloudError: '',
  15. },
  16. // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
  17. // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
  18. // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
  19. beforeMount: function() {
  20. // Attach raw data exposed by the server.
  21. _.extend(this, SAILS_LOCALS);
  22. },
  23. mounted: function() {
  24. this.$focus('[autofocus]');
  25. },
  26. // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
  27. // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
  28. // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
  29. methods: {
  30. handleParsingForm: function() {
  31. // Clear out any pre-existing error messages.
  32. this.formErrors = {};
  33. var argins = { password: this.formData.password };
  34. // Validate password:
  35. if(!argins.password) {
  36. this.formErrors.password = true;
  37. }
  38. // Validate password confirmation:
  39. if(argins.password && argins.password !== this.formData.confirmPassword) {
  40. this.formErrors.confirmPassword = true;
  41. }
  42. // If there were any issues, they've already now been communicated to the user,
  43. // so simply return undefined. (This signifies that the submission should be
  44. // cancelled.)
  45. if (Object.keys(this.formErrors).length > 0) {
  46. return;
  47. }
  48. return argins;
  49. },
  50. submittedForm: function() {
  51. // Redirect to the logged-in dashboard on success.
  52. // > (Note that we re-enable the syncing state here. This is on purpose--
  53. // > to make sure the spinner stays there until the page navigation finishes.)
  54. this.syncing = true;
  55. window.location = '/account';
  56. },
  57. }
  58. });