login.page.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. parasails.registerPage('login', {
  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 any initial data from the server.
  21. _.extend(this, SAILS_LOCALS);
  22. },
  23. mounted: function() {
  24. this.$focus('[autofocus]');
  25. },
  26. // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
  27. // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
  28. // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
  29. methods: {
  30. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  31. // Note:
  32. // To see what this would look like as a completely custom form, without relying on as many
  33. // built-in features of the <ajax-form> component, see:
  34. // https://github.com/sailshq/caviar/commit/512eb41c347f9bcdebc2d1bca8b15d8a0acd80f1
  35. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  36. submittedForm: function() {
  37. // Redirect to the logged-in dashboard on success.
  38. // > (Note that we re-enable the syncing state here. This is on purpose--
  39. // > to make sure the spinner stays there until the page navigation finishes.)
  40. this.syncing = true;
  41. window.location = '/';
  42. },
  43. handleParsingForm: function() {
  44. // Clear out any pre-existing error messages.
  45. this.formErrors = {};
  46. var argins = this.formData;
  47. // Validate email:
  48. if(!argins.emailAddress) {
  49. this.formErrors.emailAddress = true;
  50. }
  51. // Validate password:
  52. if(!argins.password) {
  53. this.formErrors.password = true;
  54. }
  55. // If there were any issues, they've already now been communicated to the user,
  56. // so simply return undefined. (This signifies that the submission should be
  57. // cancelled.)
  58. if (Object.keys(this.formErrors).length > 0) {
  59. return;
  60. }
  61. return argins;
  62. },
  63. }
  64. });