3 input#modalUser.modal(type="checkbox" @change="trySetEnterTime")
4 div(role="dialog" data-checkbox="modalUser")
6 label.modal-close(for="modalUser")
8 form#userForm(@submit.prevent="onSubmit()" @keyup.enter="onSubmit")
9 div(v-show="stage!='Login'")
11 label(for="username") {{ st.tr["Name"] }}
12 input#username(type="text" v-model="st.user.name")
14 label(for="useremail") {{ st.tr["Email"] }}
15 input#useremail(type="email" v-model="st.user.email")
17 label(for="notifyNew") {{ st.tr["Notifications by email"] }}
18 input#notifyNew(type="checkbox" v-model="st.user.notify")
19 div(v-show="stage=='Login'")
21 label(for="nameOrEmail") {{ st.tr["Name or Email"] }}
22 input#nameOrEmail(type="text" v-model="nameOrEmail")
24 button#submit(type="button" @click="onSubmit()")
25 span {{ st.tr[submitMessage] }}
26 button(v-if="stage!='Update'" @click="toggleStage()")
27 span {{ st.tr[stage=="Login" ? "Register" : "Login"] }}
28 button#logoutBtn(v-else @click="doLogout()")
29 span {{ st.tr["Logout"] }}
30 #dialog(:style="{display: displayInfo}") {{ st.tr[infoMsg] }}
34 import { store } from "@/store";
35 import { checkNameEmail } from "@/data/userCheck";
36 import { ajax } from "@/utils/ajax";
38 name: 'my-upsert-user',
41 nameOrEmail: "", //for login
42 logStage: "Login", //or Register
44 enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
49 nameOrEmail: function(newValue) {
50 if (newValue.indexOf('@') >= 0)
52 this.st.user.email = newValue;
53 this.st.user.name = "";
57 this.st.user.name = newValue;
58 this.st.user.email = "";
63 submitMessage: function() {
74 displayInfo: function() {
75 return (this.infoMsg.length > 0 ? "block" : "none");
78 return this.st.user.id > 0 ? "Update" : this.logStage;
82 trySetEnterTime: function(event) {
83 if (!!event.target.checked)
84 this.enterTime = Date.now();
86 toggleStage: function() {
87 // Loop login <--> register (update is for logged-in users)
88 this.logStage = (this.logStage == "Login" ? "Register" : "Login");
101 ajaxMethod: function() {
112 infoMessage: function() {
116 return "Connection token sent. Check your emails!";
118 return "Registration complete! Please check your emails";
120 return "Modifications applied!";
123 onSubmit: function() {
124 // Basic anti-bot strategy:
125 const exitTime = Date.now();
126 if (this.stage == "Register" && exitTime - this.enterTime < 5000)
127 return; //silently return, in (curious) case of it was legitimate
128 let error = undefined;
129 if (this.stage == 'Login')
131 const type = (this.nameOrEmail.indexOf('@') >= 0 ? "email" : "name");
132 error = checkNameEmail({[type]: this.nameOrEmail});
135 error = checkNameEmail(this.st.user);
138 this.infoMsg = "Processing... Please wait";
139 ajax(this.ajaxUrl(), this.ajaxMethod(),
140 this.stage == "Login" ? { nameOrEmail: this.nameOrEmail } : this.st.user,
142 this.infoMsg = this.infoMessage();
143 if (this.stage != "Update")
144 this.nameOrEmail = "";
147 document.getElementById("modalUser").checked = false;
156 doLogout: function() {
157 document.getElementById("modalUser").checked = false;
158 this.$router.push("/logout");