SHARE
TWEET

Untitled

a guest Jun 5th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by Thierry on 28/05/2017.
  3.  */
  4. var express = require('express');
  5. var router = express.Router();
  6. var connection = require('../config/db');
  7. var ObjectId = require('mongodb').ObjectID;
  8. var User = require('../client/User');
  9.  
  10. var monUser;
  11. var sha256 = require('../node_modules/sha256');
  12.  
  13. router.post('/getUser', function(req,res,next){
  14.     var user= req.body;
  15.  
  16. });
  17.  
  18. router.get('/getPseudo', function(req,res,next){
  19.     res.json(monUser);
  20. });
  21.  
  22. router.post('/showProfilContact/:pseudo', function(req,res,next){
  23.     var contactPseudo= req.params.pseudo;
  24.     test : User;
  25.     var contactFind;
  26.     console.log("dans contactFind profil.js");
  27.     connection(function(err,db){
  28.         var collectionDB = db.collection('usercollection');
  29.         console.log("dans la db de contactFind profil.js"+contactPseudo);
  30.  
  31.         collectionDB.findOne({pseudo: contactPseudo},function (err,result) {
  32.             console.log("dans findOne de profil.js: "+result);
  33.             if(err){
  34.                 res.send(err);
  35.             }
  36.             if(result){
  37.                 contactFind = result;
  38.                 res.json(contactFind);
  39.             }else{
  40.                 console.log("ca an pas marché: "+contactPseudo)
  41.             }
  42.  
  43.         });
  44.     });
  45. });
  46.  
  47. router.post('/modifyUser', function(req,res,next){
  48.     var user= req.body;
  49.  
  50.     var userModify;
  51.     console.log("req.body profil.js "+req.body._id);
  52.  
  53.     connection(function(err,db){
  54.         console.log("debut post profil.js");
  55.         var collectionDB = db.collection('usercollection');
  56.         console.log("dans la db de profil.js");
  57.  
  58.         collectionDB.findOne({_id: ObjectId(user._id)},function (err,result) {
  59.             console.log("dans findOne de profil.js: "+result.pseudo);
  60.             if(err){
  61.                 res.send(err);
  62.             }
  63.  
  64.             if(result != null){
  65.  
  66.                 if((user.password == undefined) || (sha256(user.password) == result.password)){
  67.                     user.password = result.password;
  68.                 }else if(user.password != result.password){
  69.                     user.password = sha256(req.body.password);
  70.                 }
  71.  
  72.  
  73.                 userModify = user;
  74.                 userModify._id = ObjectId(user._id);
  75.                 console.log("userModify de profil.js: " + userModify._id);
  76.                 collectionDB.remove({_id: ObjectId(user._id)});
  77.                 collectionDB.save(userModify);
  78.                 res.json(userModify);
  79.             }else {
  80.                 res.json(user);
  81.             }
  82.         });
  83.  
  84.     });
  85.  
  86. });
  87.  
  88. module.exports = router;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top