i.material-icons send
button(v-if="stage!='Update'" @click="toggleStage()")
span {{ stage=="Login" ? "Register" : "Login" }}
- button(v-else onClick="location.replace('/logout')")
+ button(v-else @click="doLogout()")
span Logout
#dialog(:style="{display: displayInfo}") {{ infoMsg }}
</template>
name: 'my-upsert-user',
data: function() {
return {
- user: Object.assign({}, store.state.user),
+ user: store.state.user,
nameOrEmail: "", //for login
- stage: (store.state.user.id > 0 ? "Update" : "Login"), //TODO?
+ logStage: "Login", //or Register
infoMsg: "",
enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
};
displayInfo: function() {
return (this.infoMsg.length > 0 ? "block" : "none");
},
+ stage: function() {
+ return this.user.id > 0 ? "Update" : this.logStage;
+ },
},
methods: {
trySetEnterTime: function(event) {
},
toggleStage: function() {
// Loop login <--> register (update is for logged-in users)
- this.stage = (this.stage == "Login" ? "Register" : "Login");
+ this.logStage = (this.logStage == "Login" ? "Register" : "Login");
},
ajaxUrl: function() {
switch (this.stage)
}
);
},
+ doLogout: function() {
+ ajax(
+ "/logout",
+ "GET",
+ () => {
+ this.user.id = 0;
+ this.user.name = "";
+ this.user.email = "";
+ this.user.notify = false;
+ }
+ );
+ },
},
};
</script>
path: "/authenticate/:token",
name: "authenticate",
beforeEnter: (to, from, next) => {
- console.log("ajax call authenticate");
ajax(
"/authenticate",
"GET",
{token: to.params["token"]},
(res) => {
- console.log(res);
store.state.user.id = res.id;
store.state.user.name = res.name;
store.state.user.email = res.email;
}
);
},
- redirect: "/",
- },
- {
- path: "/logout",
- name: "logout",
- beforeEnter: (to, from, next) => {
- ajax(
- "/logout",
- "GET",
- () => {
- store.state.user.id = 0;
- store.state.user.name = "";
- store.state.user.email = "";
- store.state.user.notify = false;
- next();
- }
- );
- },
- redirect: "/",
+ component: Hall,
+ //redirect: "/", //problem: redirection before end of AJAX request
},
// {
// path: "/about",
}
xhr.open(method, params.serverUrl + url, true);
xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest");
- // Next line because logout and authenticate set (cross-domain in dev mode) cookies
- if (url.startsWith("/authenticate") || url.startsWith("/logout"))
- xhr.withCredentials = true;
+ // Next line to allow cross-domain cookies in dev mode (TODO: if...)
+ xhr.withCredentials = true;
if (["POST","PUT"].includes(method))
{
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
var router = require("express").Router();
+var access = require("../utils/access");
+
+// To avoid a weird preflight AJAX request error in dev mode...
+router.get("/", access.ajax, (req,res) => {
+ res.json({});
+});
router.use("/", require("./challenges"));
//router.use("/", require("./games"));
});
};
const anonymous = {name:"", email:"", id:0, notify:false};
- console.log(req.cookies); //TODO: cookie not found after authenticate ?
if (!req.cookies.token)
return callback(anonymous);
UserModel.getOne("sessionToken", req.cookies.token, function(err, user) {
params.siteURL + "/#/authenticate/" + token + "\\n" +
"Token will expire in " + params.token.expire/(1000*60) + " minutes."
sendEmail(params.mail.noreply, to.email, subject, body, err => {
- // "id" is generally the only info missing on client side,
- // but the name is also unknown if log-in with the email.
- res.json(err || {id: to.id, name: to.name});
+ res.json(err || {});
});
});
}