var User = require('../models/user');
var express = require('express');
var router = express.Router();

router.route('/auth').get(getAuth);
router.route('/auth').post(login);
router.route('/auth').delete(logout);
module.exports = router;

function getAuth(req, res)
{
    if(req.session.userId == null)
        res.json(null);
    else
        User.findById(req.session.userId, function(err, user) { res.json(user); });
}

function login(req, res)
{
    var user = User.findOne({username : req.body.username, passwordHash : encryptPassword(req.body.password)}, function(err, user)
    {
        if(user != null)
        {
            console.log("login");
            req.session.userId = user._id;
            req.session.save();
        }
        
        res.json(user);
    });
    
}

function logout(req, res)
{
    console.log("logout");
    req.session.destroy(function(){res.json(true);});
}


function encryptPassword(password)
{
    return '098f6bcd4621d373cade4e832627b4f6';
}
@@ -27,24 +27,72 @@
 els/user');%0A
+var Response = require('../modules/response');%0A%0A
 var express 
@@ -254,16 +254,17 @@
 ogout);%0A
+%0A
 module.e
@@ -357,21 +357,58 @@
     
-res.json(
+Response(res, %22Error : Not Authenticated%22, 
 null
+, 0
 );%0A 
@@ -479,31 +479,78 @@
 user) %7B 
-res.json(user);
+%0A            Response(res, %22Authenticated%22, user, 1); %0A       
  %7D);%0A%7D%0A%0A
@@ -635,16 +635,46 @@
 ername, 
+%0A                             
 password
@@ -717,16 +717,45 @@
 word)%7D, 
+%0A                            
 function
@@ -780,16 +780,70 @@
         
+if (err) Response(res, %22Error%22, err, 0);%0A        else 
 if(user 
@@ -978,17 +978,75 @@
         
-%7D
+    Response(res, %22Authentification successfull%22, user, 1);
 %0A       
@@ -1046,16 +1046,17 @@
         
+%7D
 %0A       
@@ -1060,21 +1060,81 @@
     
-res.json(user
+else%0A            Response(res, %22Error : Authentification failed%22, null, 0
 );%0A 
@@ -1242,23 +1242,61 @@
 n()%7B
-res.json(true);
+%0A        Response(res, %22Disconnected%22, null, 1);%0A    
 %7D);%0A

Use Response module to send JSON return messages