Fixes
authorBenjamin Auder <benjamin.auder@somewhere>
Sat, 29 Feb 2020 16:43:51 +0000 (17:43 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Sat, 29 Feb 2020 16:43:51 +0000 (17:43 +0100)
client/src/components/UpsertUser.vue
client/src/views/Game.vue
client/src/views/Hall.vue
client/src/views/Problems.vue
client/src/views/Variants.vue
server/utils/access.js

index 50b702d..ac15324 100644 (file)
@@ -14,22 +14,22 @@ div
       div(@keyup.enter="onSubmit()")
         div(v-show="stage!='Login'")
           fieldset
-            label(for="username") {{ st.tr["User name"] }}
-            input#username(
+            label(for="u_username") {{ st.tr["User name"] }}
+            input#u_username(
               type="text"
-              v-model="st.user.name"
+              v-model="user.name"
             )
           fieldset
-            label(for="useremail") {{ st.tr["Email"] }}
-            input#useremail(
+            label(for="u_useremail") {{ st.tr["Email"] }}
+            input#u_useremail(
               type="email"
-              v-model="st.user.email"
+              v-model="user.email"
             )
           fieldset
             label(for="notifyNew") {{ st.tr["Notifications by email"] }}
             input#notifyNew(
               type="checkbox"
-              v-model="st.user.notify"
+              v-model="user.notify"
             )
         div(v-show="stage=='Login'")
           fieldset
@@ -67,17 +67,18 @@ export default {
       logStage: "Login", //or Register
       infoMsg: "",
       enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
-      st: store.state
+      st: store.state,
+      user: {}
     };
   },
   watch: {
     nameOrEmail: function(newValue) {
       if (newValue.indexOf("@") >= 0) {
-        this.st.user.email = newValue;
-        this.st.user.name = "";
+        this.user.email = newValue;
+        this.user.name = "";
       } else {
-        this.st.user.name = newValue;
-        this.st.user.email = "";
+        this.user.name = newValue;
+        this.user.email = "";
       }
     }
   },
@@ -102,6 +103,12 @@ export default {
       if (event.target.checked) {
         this.infoMsg = "";
         this.enterTime = Date.now();
+        document.getElementById("u_username").focus();
+        this.user = {
+          name: this.st.user.name,
+          email: this.st.user.email,
+          notify: this.st.user.notify
+        };
       }
     },
     toggleStage: function() {
@@ -149,7 +156,7 @@ export default {
       if (this.stage == "Login") {
         const type = this.nameOrEmail.indexOf("@") >= 0 ? "email" : "name";
         error = checkNameEmail({ [type]: this.nameOrEmail });
-      } else error = checkNameEmail(this.st.user);
+      } else error = checkNameEmail(this.user);
       if (error) {
         alert(this.st.tr[error]);
         return;
@@ -160,10 +167,15 @@ export default {
         this.ajaxMethod(),
         this.stage == "Login"
           ? { nameOrEmail: this.nameOrEmail }
-          : this.st.user,
+          : this.user,
         () => {
           this.infoMsg = this.infoMessage();
           if (this.stage != "Update") this.nameOrEmail = "";
+          else {
+            this.st.user.name = this.user.name;
+            this.st.user.email = this.user.email;
+            this.st.user.notify = this.user.notify;
+          }
         },
         err => {
           this.infoMsg = "";
index 709cccc..1675c30 100644 (file)
@@ -248,12 +248,12 @@ export default {
           break;
         case "killed":
           // I logged in elsewhere:
-          alert(this.st.tr["New connexion detected: tab now offline"]);
           // TODO: this fails. See https://github.com/websockets/ws/issues/489
           //this.conn.removeEventListener("message", this.socketMessageListener);
           //this.conn.removeEventListener("close", this.socketCloseListener);
           //this.conn.close();
           this.conn = null;
+          alert(this.st.tr["New connexion detected: tab now offline"]);
           break;
         case "askidentity": {
           // Request for identification (TODO: anonymous shouldn't need to reply)
index 7a7f911..5ceb7e3 100644 (file)
@@ -19,7 +19,10 @@ main
       .button-group#buttonsTchall
         button.acceptBtn(@click="decisionChallenge(true)") {{ st.tr["Accept challenge?"] }}
         button.refuseBtn(@click="decisionChallenge(false)") {{ st.tr["Refuse"] }}
-  input#modalNewgame.modal(type="checkbox")
+  input#modalNewgame.modal(
+    type="checkbox"
+    @change="cadenceFocusIfOpened($event)"
+  )
   div#newgameDiv(
     role="dialog"
     data-checkbox="modalNewgame"
@@ -316,6 +319,10 @@ export default {
   },
   methods: {
     // Helpers:
+    cadenceFocusIfOpened: function() {
+      if (event.target.checked)
+        document.getElementById("cadence").focus();
+    },
     send: function(code, obj) {
       if (this.conn) {
         this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
@@ -479,12 +486,12 @@ export default {
         }
         case "killed":
           // I logged in elsewhere:
-          alert(this.st.tr["New connexion detected: tab now offline"]);
           // TODO: this fails. See https://github.com/websockets/ws/issues/489
           //this.conn.removeEventListener("message", this.socketMessageListener);
           //this.conn.removeEventListener("close", this.socketCloseListener);
           //this.conn.close();
           this.conn = null;
+          alert(this.st.tr["New connexion detected: tab now offline"]);
           break;
         case "askidentity": {
           // Request for identification (TODO: anonymous shouldn't need to reply)
index 2d6ac69..7621fe3 100644 (file)
@@ -2,7 +2,7 @@
 main
   input#modalNewprob.modal(
     type="checkbox"
-    @change="infoMsg=''"
+    @change="fenFocusIfOpened($event)"
   )
   div#newprobDiv(
     role="dialog"
@@ -193,6 +193,12 @@ export default {
     }
   },
   methods: {
+    fenFocusIfOpened: function(event) {
+      if (event.target.checked) {
+        this.infoMsg = "";
+        document.getElementById("inputFen").focus();
+      }
+    },
     setVname: function(prob) {
       prob.vname = this.st.variants.find(v => v.id == prob.vid).name;
     },
index 3fccae5..2a3f6cf 100644 (file)
@@ -9,7 +9,7 @@ main
       )
     .variant.col-sm-12.col-md-5.col-lg-4(
       v-for="(v,idx) in filteredVariants"
-      :class="{'col-md-offset-1': idx%2==0, 'col-lg-offset-2': idx%2==0}"
+      :class="getVclasses(filteredVariants, idx)"
     )
       router-link(:to="getLink(v.name)")
         h4.boxtitle.text-center {{ v.name }}
@@ -54,7 +54,15 @@ export default {
     },
     getLink: function(vname) {
       return "/variants/" + vname;
-    }
+    },
+    getVclasses: function(varray, idx) {
+      const idxMod2 = idx % 2;
+      return {
+        'col-md-offset-1': idxMod2 == 0,
+        'col-lg-offset-2': idxMod2 == 0,
+        'last-noneighb': idxMod2 == 0 && idx == varray.length - 1
+      };
+    },
   }
 };
 </script>
@@ -79,4 +87,7 @@ input#prefixFilter
   .description
     @media screen and (max-width: 767px)
       margin-top: 0
+
+.last-noneighb
+  margin: 0 auto
 </style>
index 049e9eb..df86b75 100644 (file)
@@ -6,7 +6,7 @@ module.exports =
   logged: function(req, res, next) {
     const callback = () => {
       if (!loggedIn)
-        res.json({errmsg: "Not logged in"});
+        res.json({errmsg: "Error: please delete cookies and cross fingers"});
       else next();
     };
     let loggedIn = undefined;
@@ -40,7 +40,7 @@ module.exports =
     // Just a quick heuristic, which should be enough
     const loggedIn = !!req.cookies.token;
     if (loggedIn)
-      res.json({errmsg: "Already logged in"});
+      res.json({errmsg: "Error: please delete cookies and cross fingers"});
     else next();
   },