X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Flogin.js;h=d5cd3ac97b4458f2fa7f2dff3e0d773b3f83c5ae;hb=73609d3bc662cf4c8a21746c5d1ad736ea0eecbd;hp=4f70e19eed92346b3793524da403aaba4c2e1d05;hpb=b3540dbb5c169db3c7cf49a04e253ab3a6940916;p=qomet.git diff --git a/public/javascripts/login.js b/public/javascripts/login.js index 4f70e19..d5cd3ac 100644 --- a/public/javascripts/login.js +++ b/public/javascripts/login.js @@ -1,86 +1,87 @@ -window.onload = function() { +const messages = { + "login": "Go", + "register": "Send", +}; - const messages = { - "login": "Go", - "register": "Send", - }; +const ajaxUrl = { + "login": "/sendtoken", + "register": "/register", +}; - const ajaxUrl = { - "login": "/sendtoken", - "register": "/register", - }; +const ajaxMethod = { + "login": "PUT", + "register": "POST", +}; - const infos = { - "login": "Connection token sent. Check your emails!", - "register": "Registration complete! Please check your emails.", - }; +const infos = { + "login": "Connection token sent. Check your emails!", + "register": "Registration complete! Please check your emails.", +}; - const animationDuration = 300; //in milliseconds +const animationDuration = 300; //in milliseconds - // Basic anti-bot measure: force at least N seconds between arrival on page, and register form validation: - const enterTime = Date.now(); +// Basic anti-bot measure: force at least N seconds between arrival on page, and register form validation: +const enterTime = Date.now(); - new Vue({ - el: '#login', - data: { - messages: messages, - user: { - name: "", - email: "", - }, - stage: "login", //or "register" +new Vue({ + el: '#login', + data: { + messages: messages, + user: { + name: "", + email: "", }, - mounted: function() { - // https://laracasts.com/discuss/channels/vue/vuejs-set-focus-on-textfield - this.$refs.userEmail.focus(); + stage: "login", //or "register" + }, + mounted: function() { + // https://laracasts.com/discuss/channels/vue/vuejs-set-focus-on-textfield + this.$refs.userEmail.focus(); + }, + methods: { + toggleStage: function(stage) { + let $form = $("#form"); + $form.fadeOut(animationDuration); + setTimeout( () => { + this.stage = stage; + $form.show(0); + }, animationDuration); }, - methods: { - toggleStage: function(stage) { - let $form = $("#form"); - $form.fadeOut(animationDuration); - setTimeout( () => { - this.stage = stage; - $form.show(0); - }, animationDuration); - }, - submit: function() { - if (this.stage=="register") + submit: function() { + if (this.stage=="register") + { + if (Date.now() - enterTime < 5000) + return; + } + let error = Validator.checkObject({email: this.user.email}, "User"); + if (!error && this.stage == "register") + error = Validator.checkObject({name: this.user.name}, "User"); + let $dialog = $("#dialog"); + show($dialog); + setTimeout(() => {hide($dialog);}, 3000); + if (error.length > 0) + return showMsg($dialog, "error", error); + showMsg($dialog, "process", "Processing... Please wait"); + $.ajax(ajaxUrl[this.stage], { - if (Date.now() - enterTime < 5000) - return; - } - let error = Validator.checkObject({email: this.user.email}, "User"); - if (!error && this.stage == "register") - error = Validator.checkObject({name: this.user.name}, "User"); - let $dialog = $("#dialog"); - show($dialog); - setTimeout(() => {hide($dialog);}, 3000); - if (error.length > 0) - return showMsg($dialog, "error", error); - showMsg($dialog, "process", "Processing... Please wait"); - $.ajax(ajaxUrl[this.stage], + method: ajaxMethod[this.stage], + data: { - method: "GET", - data: + email: encodeURIComponent(this.user.email), + name: encodeURIComponent(this.user.name), //may be unused + }, + dataType: "json", + success: res => { + if (!res.errmsg) { - email: encodeURIComponent(this.user.email), - name: encodeURIComponent(this.user.name), //may be unused - }, - dataType: "json", - success: res => { - if (!res.errmsg) - { - this.user["name"] = ""; - this.user["email"] = ""; - showMsg($dialog, "info", infos[this.stage]); - } - else - showMsg($dialog, "error", res.errmsg); - }, - } - ); - }, - } - }); - -}; + this.user["name"] = ""; + this.user["email"] = ""; + showMsg($dialog, "info", infos[this.stage]); + } + else + showMsg($dialog, "error", res.errmsg); + }, + } + ); + }, + } +});