Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxencee authored Mar 22, 2024
2 parents 81761fb + bb2a606 commit 851412f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Créez un fichier `.env` dans le dossier `server` et ajoutez les variables d'env

```env
PORT=3001
MONGODB_URI=your_mongodb_uri_here
MONGO_URI=your_mongodb_uri_here
```

### 4. Configuration du Frontend
Expand Down Expand Up @@ -63,4 +63,4 @@ L'application sera accessible à l'adresse http://localhost:5173 dans votre navi

## Comment Installer MongoDB

Suivez les instructions sur le site officiel de MongoDB pour installer la base de données : [MongoDB Installation Guide](https://www.mongodb.com/docs/manual/installation/)
Suivez les instructions sur cette vidéo pour installer MongoDB : [MongoDB Installation Guide](https://www.youtube.com/watch?v=gB6WLkSrtJk)
File renamed without changes.
62 changes: 37 additions & 25 deletions client/src/pages/map/MapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,44 @@ const MapPage = () => {
};

const getFlamiLocation = useCallback(() => {
APIHandler<FlamiData>("/my/flami?trail", false, "GET", undefined, token).then(
async (res) => {
if (!res.data.my_flami?.location?.latitude ||
!res.data.my_flami?.location?.longitude) {
return setFlamiLocation(null);
} else {
setFlamiTrail(res.data.my_flami?.trail?.map(e => [e.latitude, e.longitude]));
setFlamiPosition(res.data.my_flami?.location);
await fetch(`https://api-adresse.data.gouv.fr/reverse/?lat=${res.data.my_flami.location.latitude}&lon=${res.data.my_flami.location.longitude}`).then((res) =>
res.json().then((data) => {
if (data.features?.length > 0) {
const context =
data.features[0]["properties"]["context"].split(", ");
setFlamiLocation({
ville: data.features[0]["properties"]["city"],
dept: `${context[1]} (${context[0]})`,
region: context[2],
});
} else {
setFlamiLocation(null);
}
})
).catch(() => setFlamiLocation(null));
}
APIHandler<FlamiData>(
"/my/flami?trail",
false,
"GET",
undefined,
token
).then(async (res) => {
if (
!res.data.my_flami?.location?.latitude ||
!res.data.my_flami?.location?.longitude
) {
return setFlamiLocation(null);
} else {
setFlamiTrail(
res.data.my_flami?.trail?.map((e) => [e.latitude, e.longitude])
);
setFlamiPosition(res.data.my_flami?.location);
await fetch(
`https://api-adresse.data.gouv.fr/reverse/?lat=${res.data.my_flami.location.latitude}&lon=${res.data.my_flami.location.longitude}`
)
.then((res) =>
res.json().then((data) => {
if (data.features?.length > 0) {
const context =
data.features[0]["properties"]["context"].split(", ");
setFlamiLocation({
ville: data.features[0]["properties"]["city"],
dept: `${context[1]} (${context[0]})`,
region: context[2],
});
} else {
setFlamiLocation(null);
}
})
)
.catch(() => setFlamiLocation(null));
}
);
});
}, [token]);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions client/src/utils/api/api-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import toast from "react-hot-toast";

type HTTPMethod = "GET" | "POST" | "PATCH";

const apiURLFlami = "http://localhost:3001/api";
const apiURLFlami = "https://flami-api.onrender.com/api";
const apiURLMap = "https://maksance.alwaysdata.net/api-jo";

export const APIHandler = <T>(
Expand Down Expand Up @@ -47,8 +47,8 @@ export const APIHandler = <T>(
},
});
});
if(res.status === 401) {

if (res.status === 401) {
localStorage.clear();
window.location.pathname = "/sign-in";
}
Expand Down
7 changes: 7 additions & 0 deletions server/__test__/Api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it, expect } from "vitest";

describe("Simple test :D", () => {
it("should pass", () => {
expect(true).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion server/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const authController = {

if (isValid) {
let token = auth.encode({ email: user.email });
req.brute.reset(); // reset brute counter
// req.brute.reset();
return res.status(200).json({
data: {
message: "Bienvenue sur l'application Flami !",
Expand Down
16 changes: 8 additions & 8 deletions server/routes/auth.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.ENVIRONMENT == "dev") {
store = new ExpressBrute.MemoryStore(); // stores state locally, don't use this in production
} else {
// stores state with memcached
store = new MemcachedStore(["127.0.0.1"], {
store = new MemcachedStore(["127.0.0.1:11211"], {
prefix: "NoConflicts",
});
}
Expand All @@ -38,21 +38,21 @@ let handleStoreError = function (error) {
};

let bruteforce = new ExpressBrute(store, {
freeRetries: 1000,
freeRetries: 5,
minWait: 5 * 60 * 1000, // 5 minutes
maxWait: 10 * 60 * 1000, // 1 hour,
failCallback: failCallback,
handleStoreError: handleStoreError,
});

router.post("/signin", bruteforce.prevent, authController.signin);
router.post("/signup", bruteforce.prevent, authController.signup);
router.post("/signin", authController.signin);
router.post("/signup", authController.signup);

router.get("/token", auth.require, authController.token);

router.post("/send-otp", bruteforce.prevent, otpController.sendOTP);
router.post("/verify-otp", bruteforce.prevent, otpController.verifyOTP);
router.post("/forget-password", bruteforce.prevent, forgetPasswordController.forgetPassword);
router.post("/reset-password/:token", bruteforce.prevent, forgetPasswordController.resetPassword);
router.post("/send-otp", otpController.sendOTP);
router.post("/verify-otp", otpController.verifyOTP);
router.post("/forget-password", forgetPasswordController.forgetPassword);
router.post("/reset-password/:token", forgetPasswordController.resetPassword);

export default router;
2 changes: 0 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cookieParser from "cookie-parser";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
Expand All @@ -16,7 +15,6 @@ dotenv.config();
const app = express();

app.use(express.json());
app.use(cookieParser());
app.use(cors());


Expand Down

0 comments on commit 851412f

Please sign in to comment.