Browse Source

fix(Register): user is now always logged-in on successful register

Signed-off-by: Jonathan Graham <theflametrooper@gmail.com>
Jonathan Graham 3 years ago
parent
commit
9029469997

+ 1 - 0
backend/logic/actions/users.js

@@ -536,6 +536,7 @@ export default {
 				(hash, _id, next) => {
 					next(null, {
 						_id,
+						name: "",
 						username,
 						email: {
 							address: email,

+ 3 - 3
backend/logic/db/index.js

@@ -141,9 +141,9 @@ class _DBModule extends CoreClass {
 						return regex.emailSimple.test(email) && regex.ascii.test(email);
 					}, "Invalid email.");
 
-					this.schemas.user
-						.path("name")
-						.validate(name => isLength(name, 1, 64) && regex.name.test(name), "Invalid name.");
+					// this.schemas.user
+					// 	.path("name")
+					// 	.validate(name => isLength(name, 1, 64) && regex.name.test(name), "Invalid name.");
 
 					// Station
 					this.schemas.station

+ 12 - 3
frontend/src/api/auth.js

@@ -25,14 +25,18 @@ export default {
 									new Date().getTime() +
 										2 * 365 * 24 * 60 * 60 * 1000
 								);
+
 								const secure = cookie.secure
 									? "secure=true; "
 									: "";
+
+								let domain = "";
+								if (cookie.domain !== "localhost")
+									domain = ` domain=${cookie.domain};`;
+
 								document.cookie = `SID=${
 									res.SID
-								}; expires=${date.toGMTString()}; domain=${
-									cookie.domain
-								}; ${secure}path=/`;
+								}; expires=${date.toGMTString()}; ${domain}${secure}path=/`;
 
 								return resolve({
 									status: "success",
@@ -40,6 +44,7 @@ export default {
 								});
 							});
 						}
+
 						return reject(new Error("You must login"));
 					}
 
@@ -59,13 +64,17 @@ export default {
 						date.setTime(
 							new Date().getTime() + 2 * 365 * 24 * 60 * 60 * 1000
 						);
+
 						const secure = cookie.secure ? "secure=true; " : "";
+
 						let domain = "";
 						if (cookie.domain !== "localhost")
 							domain = ` domain=${cookie.domain};`;
+
 						document.cookie = `${cookie.SIDname}=${
 							res.data.SID
 						}; expires=${date.toGMTString()}; ${domain}${secure}path=/`;
+
 						return resolve({ status: "success" });
 					});
 				}

+ 1 - 1
frontend/src/components/modals/Register.vue

@@ -305,7 +305,7 @@ export default {
 				recaptchaToken: this.recaptcha.token
 			})
 				.then(res => {
-					if (res.status === "success") window.location.href = "/";
+					if (res.status === "success") window.location.reload();
 				})
 				.catch(err => new Toast(err.message));
 		},