Skip to content

Commit

Permalink
responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu777 committed Apr 15, 2021
2 parents 3ec4a47 + cb7cfa2 commit edd0310
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .eslintcache

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ app.use('/app/changeName', authController.withAuth, (req, res, next) => {
try {
let doc = await User.findOneAndUpdate({ _id: decoded.userId }, { pseudo: req.body.newName });
console.log(doc.pseudo)
res.status(200)
res.status(200).send({ message: 'OK' })
} catch (err) {
res.status(401).json({ err })
}
Expand Down Expand Up @@ -248,7 +248,6 @@ app.post('/app/newfriend', authController.withAuth, (req, res, next) => {
req.cookies.token;

User.findOne({ pseudo: req.body.new_friend }, function(err, docs) {

if (err) {
console.log(err)
} else if (docs == null) {
Expand All @@ -260,7 +259,7 @@ app.post('/app/newfriend', authController.withAuth, (req, res, next) => {
if (err) {
res.status(401).send({ error: "invalide token" });
} else {
User.findOne({ _id: decoded.userId, "friends._pseudo": req.body.new_friend }, function(err, docs) {
User.findOne({ _id: decoded.userId, "friends._id": friendID }, function(err, docs) {
if (err) {
console.log(err)
} else if (docs == null) {
Expand Down Expand Up @@ -307,10 +306,6 @@ app.post('/app/newfriend', authController.withAuth, (req, res, next) => {
membres: [
{ _id: friendID },
{ _id: userID }
],
message: [
{ text: "wesh", author: "david" },
{ text: "wesh david", author: "thierry" }
]
})
groupe.save()
Expand Down
38 changes: 32 additions & 6 deletions controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const User = require('../models/user');
const Groupe = require('../models/groupe')
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');

Expand All @@ -15,22 +16,47 @@ exports.signup = (req, res, next) => {
pseudo: pseudo,
email: email,
mdp: hash,
//test
/*friends: [{
user_id: "test",
_pseudo: "test"
}]*/
friends: {
_id: "6076e163d47a913b0c2b0b0f",
_pseudo: "Equipe iChat"
}
});

user.save()
// crétion de la session qui exprire dans 1h
.then(() => {
const token = jwt.sign({ userId: user._id }, secret, {
expiresIn: '1h'
});
return res.cookie('token', token, { httpOnly: true }).status(200).json({ message: 'utilisateur créer' });
User.updateOne({ _id: "6076e163d47a913b0c2b0b0f" }, {
$push: {
friends: {
_id: user._id,
_pseudo: req.body.pseudo
}
}
}, function(err, docs) {
if (err) {
console.log(err)
} else {
const groupe = new Groupe({
membres: [
{ _id: user._id },
{ _id: "6076e163d47a913b0c2b0b0f" }
],
message: [
{ text: "Bienvenue dans iChat, vous pouvez désormais ajoutez des amis dans la section dédiée et vous partagez vos plus belles histoires !", author: "Equipe iChat" }
]
})
groupe.save()
return res.cookie('token', token, { httpOnly: true }).status(200).json({ message: 'utilisateur créer' });
}
})

})
// renvois éventuelles érreurs
.catch(error => res.status(400).json({ message: "Nom du'ilisateur ou mot de passe ou Pseudo déjà utilisé" }));

});
}

Expand Down
182 changes: 182 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
"mongoose-unique-validator": "^2.0.3",
"nodemon": "^2.0.6",
"react": "^17.0.1",
"react-cookie": "^4.0.3",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"react-scroll": "^1.8.2",
"react-scroll-to-bottom": "^4.1.0",
"react-scrollable-feed": "^1.3.0",
"socket.io": "^3.1.2",
"socket.io-client": "^3.1.2",
"web-vitals": "^0.2.4"
Expand Down
Loading

0 comments on commit edd0310

Please sign in to comment.