Compare commits
No commits in common. "a9e9c5b0805092d037da6c4b16ddb38cbd6321f1" and "a12b82f4708d6325bb5d3d06732b233116db3a85" have entirely different histories.
a9e9c5b080
...
a12b82f470
|
@ -9,7 +9,7 @@ const resourceTypes = await getAllResources();
|
||||||
|
|
||||||
const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')));
|
const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')));
|
||||||
|
|
||||||
const planetId = new ObjectId(Astro.cookies.get('currentPlanet')?.value ?? '');
|
const planetId = new ObjectId(Astro.cookies.get('planetid')?.value ?? '');
|
||||||
|
|
||||||
const planet = locationManager.getPlanet(planetId);
|
const planet = locationManager.getPlanet(planetId);
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@ import { Lang } from "./mongodb";
|
||||||
export const getLang = async (language = "en") => {
|
export const getLang = async (language = "en") => {
|
||||||
const lang = await Lang(language);
|
const lang = await Lang(language);
|
||||||
return {
|
return {
|
||||||
general: (await lang[0].find({}).toArray()).map(({ _id, ...rest }) => rest),
|
general: await lang[0].find({}).toArray(),
|
||||||
buildings: (await lang[1].find({}).toArray()).map(({ _id, ...rest }) => rest),
|
buildings: await lang[1].find({}).toArray(),
|
||||||
ships: (await lang[2].find({}).toArray()).map(({ _id, ...rest }) => rest),
|
ships: await lang[2].find({}).toArray(),
|
||||||
resources: (await lang[3].find({}).toArray()).map(({ _id, ...rest }) => rest),
|
resources: await lang[3].find({}).toArray(),
|
||||||
research: (await lang[4].find({}).toArray()).map(({ _id, ...rest }) => rest),
|
research: await lang[4].find({}).toArray(),
|
||||||
structures: (await lang[5].find({}).toArray()).map(({ _id, ...rest }) => rest)
|
structures: await lang[5].find({}).toArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ const locale = Astro.cookies.get('language')?.value ?? await getHighestWeightedL
|
||||||
|
|
||||||
const lang = await getLocales(locale);
|
const lang = await getLocales(locale);
|
||||||
|
|
||||||
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
|
const planetId = Astro.cookies.get('planetid')?.value ?? "";
|
||||||
if(planetId === "") return "No planet selected";
|
if(planetId === "") return "No planet selected";
|
||||||
|
|
||||||
const planet = locationManager.getPlanet(new ObjectId(planetId));
|
const planet = locationManager.getPlanet(new ObjectId(planetId));
|
||||||
|
|
|
@ -19,7 +19,7 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect(
|
||||||
const user = locationManager.getUser(checkUser._id);
|
const user = locationManager.getUser(checkUser._id);
|
||||||
if(!user) return Astro.redirect('/logout');
|
if(!user) return Astro.redirect('/logout');
|
||||||
|
|
||||||
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
|
const planetId = Astro.cookies.get('planetid')?.value ?? "";
|
||||||
if(planetId === "") return "No planet selected";
|
if(planetId === "") return "No planet selected";
|
||||||
|
|
||||||
const planet = locationManager.getPlanet(new ObjectId(planetId));
|
const planet = locationManager.getPlanet(new ObjectId(planetId));
|
||||||
|
|
|
@ -13,8 +13,8 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout');
|
||||||
const checkUser = await getUserByAccessToken(loggedToken);
|
const checkUser = await getUserByAccessToken(loggedToken);
|
||||||
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
|
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
|
||||||
|
|
||||||
|
const currentPlanetId = Astro.cookies.get('planetid')?.value ?? null;
|
||||||
if(currentPlanetId === null) return Astro.redirect('/game/logout');
|
if(currentPlanetId === null) return Astro.redirect('/game/logout');
|
||||||
const currentPlanetId = Astro.cookies.get('currentPlanet')?.value ?? null;
|
|
||||||
const currentPlanet = locationManager.getPlanet(new ObjectId(currentPlanetId));
|
const currentPlanet = locationManager.getPlanet(new ObjectId(currentPlanetId));
|
||||||
if(currentPlanet === undefined) {
|
if(currentPlanet === undefined) {
|
||||||
Astro.cookies.delete('planetid');
|
Astro.cookies.delete('planetid');
|
||||||
|
|
|
@ -16,7 +16,7 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout');
|
||||||
const checkUser = await getUserByAccessToken(loggedToken);
|
const checkUser = await getUserByAccessToken(loggedToken);
|
||||||
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
|
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
|
||||||
|
|
||||||
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
|
const planetId = Astro.cookies.get('planetid')?.value ?? "";
|
||||||
if(planetId === "") return Astro.redirect('/logout');
|
if(planetId === "") return Astro.redirect('/logout');
|
||||||
|
|
||||||
if(Astro.request.method === "POST") {
|
if(Astro.request.method === "POST") {
|
||||||
|
|
|
@ -18,7 +18,7 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect(
|
||||||
|
|
||||||
const ships = await getAllShips();
|
const ships = await getAllShips();
|
||||||
|
|
||||||
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
|
const planetId = Astro.cookies.get('planetid')?.value ?? "";
|
||||||
if(planetId === "") {
|
if(planetId === "") {
|
||||||
console.error("No planet selected");
|
console.error("No planet selected");
|
||||||
return Astro.redirect('/logout');
|
return Astro.redirect('/logout');
|
||||||
|
|
|
@ -28,7 +28,7 @@ if(Astro.request.method === "POST") {
|
||||||
const selectedPlanetId = (await Astro.request.formData()).get('planetId') as string | null;
|
const selectedPlanetId = (await Astro.request.formData()).get('planetId') as string | null;
|
||||||
|
|
||||||
if(selectedPlanetId !== null) {
|
if(selectedPlanetId !== null) {
|
||||||
Astro.cookies.set('currentPlanet', selectedPlanetId, {
|
Astro.cookies.set('planetid', selectedPlanetId, {
|
||||||
path: '/',
|
path: '/',
|
||||||
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
|
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
|
||||||
sameSite: 'lax',
|
sameSite: 'lax',
|
||||||
|
|
|
@ -16,10 +16,16 @@ if(Astro.request.method === "POST") {
|
||||||
const username = data.get("username") as string | "";
|
const username = data.get("username") as string | "";
|
||||||
const password = data.get("password") as string | "";
|
const password = data.get("password") as string | "";
|
||||||
|
|
||||||
if(username === "") error = "username is required";
|
if(username === "") {
|
||||||
if(password === "") error = "password is required";
|
error = "username is required";
|
||||||
|
Astro.redirect("/login");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(password === "") {
|
||||||
|
error = "password is required";
|
||||||
|
Astro.redirect("/login");
|
||||||
|
}
|
||||||
|
|
||||||
if(error === "") {
|
|
||||||
const userDB = await getUserByNickOrEmail(username as string);
|
const userDB = await getUserByNickOrEmail(username as string);
|
||||||
|
|
||||||
if(userDB !== null && await verify(userDB.password, password as string)) {
|
if(userDB !== null && await verify(userDB.password, password as string)) {
|
||||||
|
@ -65,7 +71,7 @@ if(Astro.request.method === "POST") {
|
||||||
secure: true
|
secure: true
|
||||||
});
|
});
|
||||||
|
|
||||||
Astro.cookies.set("currentPlanet", user.mainPlanet._id, {
|
Astro.cookies.set("planetid", user.mainPlanet._id, {
|
||||||
path: "/",
|
path: "/",
|
||||||
maxAge: sessionTime,
|
maxAge: sessionTime,
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
|
@ -73,7 +79,9 @@ if(Astro.request.method === "POST") {
|
||||||
});
|
});
|
||||||
|
|
||||||
return Astro.redirect("/game");
|
return Astro.redirect("/game");
|
||||||
} else error = "invalid username or password";
|
} else {
|
||||||
|
error = "invalid username or password";
|
||||||
|
return Astro.redirect("/login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue