diff --git a/client/Dockerfile b/client/Dockerfile index 9e8ec7a..f1021e6 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,6 +1,6 @@ # client -FROM node:20 AS build +FROM node:18 AS build WORKDIR /usr/src/app/client diff --git a/client/src/pages/AuthManager/callback/AuthCallback.tsx b/client/src/pages/AuthManager/callback/AuthCallback.tsx index 6206294..f05083d 100644 --- a/client/src/pages/AuthManager/callback/AuthCallback.tsx +++ b/client/src/pages/AuthManager/callback/AuthCallback.tsx @@ -15,7 +15,7 @@ const OAuthCallback: React.FC = () => { if (user) { apiService.saveToken(user); apiService.saveUsername(username || ""); - navigate('/'); + navigate('/teacher/dashboard'); } else { navigate('/login'); } diff --git a/server/auth/auth-manager.js b/server/auth/auth-manager.js index c38c44d..e09b8c4 100644 --- a/server/auth/auth-manager.js +++ b/server/auth/auth-manager.js @@ -50,13 +50,16 @@ class AuthManager{ } // eslint-disable-next-line no-unused-vars - async login(userInfo,req,res,next){ //passport and simpleauth use next + async login(email,pswd,req,res,next){ //passport and simpleauth use next + + const userInfo = await this.simpleregister.login(email, pswd); const tokenToSave = jwt.create(userInfo.email, userInfo._id,userInfo.roles); res.redirect(`/auth/callback?user=${tokenToSave}&username=${userInfo.name}`); console.info(`L'utilisateur '${userInfo.name}' vient de se connecter`) } async register(userInfos){ + console.log(userInfos); if (!userInfos.email || !userInfos.password) { throw new AppError(MISSING_REQUIRED_PARAMETER); } diff --git a/server/auth/modules/simpleauth.js b/server/auth/modules/simpleauth.js index b40f55d..b8628b5 100644 --- a/server/auth/modules/simpleauth.js +++ b/server/auth/modules/simpleauth.js @@ -32,7 +32,7 @@ class SimpleAuth { email: req.body.email, password: req.body.password, roles: req.body.roles - } + }; let user = await self.authmanager.register(userInfos) if (user) res.redirect("/login") } @@ -52,11 +52,8 @@ class SimpleAuth { error.statusCode = 400; throw error; } - - const userModel = self.authmanager.getUserModel(); - const user = userModel.login(email, password); - - await self.authmanager.login(user, req, res, next); + + await self.authmanager.login(email, password, req, res, next); } catch (error) { const statusCode = error.statusCode || 500; const message = error.message || "An internal server error occurred"; diff --git a/server/auth_config.json.example b/server/auth_config.json.example index 2a8fb11..ba8c10c 100644 --- a/server/auth_config.json.example +++ b/server/auth_config.json.example @@ -14,7 +14,7 @@ } } ], - "simple-login": { + "simpleauth": { "enabled": true, "name": "provider3", "SESSION_SECRET": "your_session_secret" diff --git a/server/models/users.js b/server/models/users.js index f18e708..d048d9f 100644 --- a/server/models/users.js +++ b/server/models/users.js @@ -53,20 +53,6 @@ class Users { return user; } - async login(userid) { - await this.db.connect(); - const conn = this.db.getConnection(); - - const userCollection = conn.collection("users"); - const user = await userCollection.findOne({ _id: userid }); - - if (!user) { - return false; - } - - return user; - } -/* async login(email, password) { try { await this.db.connect(); @@ -95,7 +81,7 @@ class Users { throw error; } } -*/ + async resetPassword(email) { const newPassword = this.generatePassword();