123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- parasails.registerPage('signup', {
- // ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
- // ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
- // ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
- data: {
- // Form data
- formData: { /* … */ },
- // For tracking client-side validation errors in our form.
- // > Has property set to `true` for each invalid property in `formData`.
- formErrors: { /* … */ },
- // Syncing / loading state
- syncing: false,
- // Server error state
- cloudError: '',
- // Success state when form has been submitted
- cloudSuccess: false,
- },
- // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
- // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
- // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
- beforeMount: function() {
- // Attach any initial data from the server.
- _.extend(this, SAILS_LOCALS);
- },
- mounted: function() {
- this.$focus('[autofocus]');
- },
- // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
- // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
- // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
- methods: {
- submittedForm: function() {
- if(this.isEmailVerificationRequired) {
- // If email confirmation is enabled, show the success message.
- this.cloudSuccess = true;
- }
- else {
- // Otherwise, redirect to the logged-in dashboard.
- // > (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 full name:
- if(!argins.fullName) {
- this.formErrors.fullName = true;
- }
- // Validate email:
- var isValidEmailAddress = parasails.require('isValidEmailAddress');
- if(!argins.emailAddress || !isValidEmailAddress(argins.emailAddress)) {
- this.formErrors.emailAddress = true;
- }
- // Validate password:
- if(!argins.password) {
- this.formErrors.password = true;
- }
- // Validate password confirmation:
- if(argins.password && argins.password !== argins.confirmPassword) {
- this.formErrors.confirmPassword = true;
- }
- // Validate ToS agreement:
- if(!argins.agreed) {
- this.formErrors.agreed = 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;
- }
- }
- });
|