signup.page.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. parasails.registerPage('signup', {
  2. // ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
  3. // ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
  4. // ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
  5. data: {
  6. // Form data
  7. formData: { /* … */ },
  8. // For tracking client-side validation errors in our form.
  9. // > Has property set to `true` for each invalid property in `formData`.
  10. formErrors: { /* … */ },
  11. // Syncing / loading state
  12. syncing: false,
  13. // Server error state
  14. cloudError: '',
  15. // Success state when form has been submitted
  16. cloudSuccess: false,
  17. },
  18. // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
  19. // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
  20. // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
  21. beforeMount: function() {
  22. // Attach any initial data from the server.
  23. _.extend(this, SAILS_LOCALS);
  24. },
  25. mounted: function() {
  26. this.$focus('[autofocus]');
  27. },
  28. // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
  29. // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
  30. // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
  31. methods: {
  32. submittedForm: function() {
  33. if(this.isEmailVerificationRequired) {
  34. // If email confirmation is enabled, show the success message.
  35. this.cloudSuccess = true;
  36. }
  37. else {
  38. // Otherwise, redirect to the logged-in dashboard.
  39. // > (Note that we re-enable the syncing state here. This is on purpose--
  40. // > to make sure the spinner stays there until the page navigation finishes.)
  41. this.syncing = true;
  42. window.location = '/';
  43. }
  44. },
  45. handleParsingForm: function() {
  46. // Clear out any pre-existing error messages.
  47. this.formErrors = {};
  48. var argins = this.formData;
  49. // Validate full name:
  50. if(!argins.fullName) {
  51. this.formErrors.fullName = true;
  52. }
  53. // Validate email:
  54. var isValidEmailAddress = parasails.require('isValidEmailAddress');
  55. if(!argins.emailAddress || !isValidEmailAddress(argins.emailAddress)) {
  56. this.formErrors.emailAddress = true;
  57. }
  58. // Validate password:
  59. if(!argins.password) {
  60. this.formErrors.password = true;
  61. }
  62. // Validate password confirmation:
  63. if(argins.password && argins.password !== argins.confirmPassword) {
  64. this.formErrors.confirmPassword = true;
  65. }
  66. // Validate ToS agreement:
  67. if(!argins.agreed) {
  68. this.formErrors.agreed = true;
  69. }
  70. // If there were any issues, they've already now been communicated to the user,
  71. // so simply return undefined. (This signifies that the submission should be
  72. // cancelled.)
  73. if (Object.keys(this.formErrors).length > 0) {
  74. return;
  75. }
  76. return argins;
  77. }
  78. }
  79. });