mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
FIX simpleauth for local dev
This commit is contained in:
parent
2499f78b6a
commit
a049ba5da1
6 changed files with 11 additions and 25 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# client
|
# client
|
||||||
|
|
||||||
FROM node:20 AS build
|
FROM node:18 AS build
|
||||||
|
|
||||||
WORKDIR /usr/src/app/client
|
WORKDIR /usr/src/app/client
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ const OAuthCallback: React.FC = () => {
|
||||||
if (user) {
|
if (user) {
|
||||||
apiService.saveToken(user);
|
apiService.saveToken(user);
|
||||||
apiService.saveUsername(username || "");
|
apiService.saveUsername(username || "");
|
||||||
navigate('/');
|
navigate('/teacher/dashboard');
|
||||||
} else {
|
} else {
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,16 @@ class AuthManager{
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// 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);
|
const tokenToSave = jwt.create(userInfo.email, userInfo._id,userInfo.roles);
|
||||||
res.redirect(`/auth/callback?user=${tokenToSave}&username=${userInfo.name}`);
|
res.redirect(`/auth/callback?user=${tokenToSave}&username=${userInfo.name}`);
|
||||||
console.info(`L'utilisateur '${userInfo.name}' vient de se connecter`)
|
console.info(`L'utilisateur '${userInfo.name}' vient de se connecter`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async register(userInfos){
|
async register(userInfos){
|
||||||
|
console.log(userInfos);
|
||||||
if (!userInfos.email || !userInfos.password) {
|
if (!userInfos.email || !userInfos.password) {
|
||||||
throw new AppError(MISSING_REQUIRED_PARAMETER);
|
throw new AppError(MISSING_REQUIRED_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class SimpleAuth {
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
password: req.body.password,
|
password: req.body.password,
|
||||||
roles: req.body.roles
|
roles: req.body.roles
|
||||||
}
|
};
|
||||||
let user = await self.authmanager.register(userInfos)
|
let user = await self.authmanager.register(userInfos)
|
||||||
if (user) res.redirect("/login")
|
if (user) res.redirect("/login")
|
||||||
}
|
}
|
||||||
|
|
@ -52,11 +52,8 @@ class SimpleAuth {
|
||||||
error.statusCode = 400;
|
error.statusCode = 400;
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userModel = self.authmanager.getUserModel();
|
await self.authmanager.login(email, password, req, res, next);
|
||||||
const user = userModel.login(email, password);
|
|
||||||
|
|
||||||
await self.authmanager.login(user, req, res, next);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const statusCode = error.statusCode || 500;
|
const statusCode = error.statusCode || 500;
|
||||||
const message = error.message || "An internal server error occurred";
|
const message = error.message || "An internal server error occurred";
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"simple-login": {
|
"simpleauth": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"name": "provider3",
|
"name": "provider3",
|
||||||
"SESSION_SECRET": "your_session_secret"
|
"SESSION_SECRET": "your_session_secret"
|
||||||
|
|
|
||||||
|
|
@ -53,20 +53,6 @@ class Users {
|
||||||
return user;
|
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) {
|
async login(email, password) {
|
||||||
try {
|
try {
|
||||||
await this.db.connect();
|
await this.db.connect();
|
||||||
|
|
@ -95,7 +81,7 @@ class Users {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
async resetPassword(email) {
|
async resetPassword(email) {
|
||||||
const newPassword = this.generatePassword();
|
const newPassword = this.generatePassword();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue