parasails.registerPage('login', { // ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗ // ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣ // ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝ data: { // Main syncing/loading state for this page. syncing: false, // Form data formData: { /* … */ }, // For tracking client-side validation errors in our form. // > Has property set to `true` for each invalid property in `formData`. formErrors: { /* … */ }, // Server error state for the form cloudError: '', }, // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗ // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣ // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝ beforeMount: function() { // Attach any initial data from the server. _.extend(this, SAILS_LOCALS); }, mounted: function() { this.$focus('[autofocus]'); }, // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗ // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗ // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝ methods: { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Note: // To see what this would look like as a completely custom form, without relying on as many // built-in features of the component, see: // https://github.com/sailshq/caviar/commit/512eb41c347f9bcdebc2d1bca8b15d8a0acd80f1 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - submittedForm: function() { // Redirect to the logged-in dashboard on success. // > (Note that we re-enable the syncing state here. This is on purpose-- // > to make sure the spinner stays there until the page navigation finishes.) this.syncing = true; window.location = '/'; }, handleParsingForm: function() { // Clear out any pre-existing error messages. this.formErrors = {}; var argins = this.formData; // Validate email: if(!argins.emailAddress) { this.formErrors.emailAddress = true; } // Validate password: if(!argins.password) { this.formErrors.password = true; } // If there were any issues, they've already now been communicated to the user, // so simply return undefined. (This signifies that the submission should be // cancelled.) if (Object.keys(this.formErrors).length > 0) { return; } return argins; }, } });