text: 'use strict';
  
  var express = require('express');
  var passport = require('passport');
  var auth = require('../auth.service');
  var translations = require('../../config/translations');
  
  var router = express.Router();
  
  router.post('/', function(req, res, next) {
    passport.authenticate('local', function (err, user, info) {
      var error = err || info;
      var language = (req&&req.cookies&&req.cookies.language ? req.cookies.language : (user&&user.language?user.language:'en'));
      if (error) return res.status(401).json(error);
      if (!user) return res.status(404).json({message: translations.get(language,'TRY_AGAIN'), translationKey: 'TRY_AGAIN'});
  
      var token = auth.signToken(user._id, user.role);
      res.json({token: token});
    })(req, res, next)
  });
  
  module.exports = router;
  