var User = require('../models/user');
var jwt = require('jsonwebtoken'); //used to create, sign and verify tokens
var config = require('../config.js');
//var Blog = require('../models/blog');
//var Entry = require('../models/entry');
//var Comment = require('../models/comment');
//var Post = require('../models/post');

exports.getToken = function(user) {
    return jwt.sign(user, config.secretKey, {
        expiresIn: 36000
    });
};

exports.verifyAdmin = function(req, res, next) {
    //check if verified ordinary user is an admin:
    var admin = req.decoded.admin;
    console.log("in verifyAdmin method");
    
    if(!admin) {
        var err = new Error('You are not authorized to perform this operation!');
        err.status = 403;
        return next(err);        
    } else {
        return next();
    }
};

exports.verifyOrdinaryUser = function(req, res, next) {
    //check header or url parameters or post parameters for token
    var token = req.body.token || req.query.token ||req.headers['x-access-token'];
    
    //decode token
    if(token) {
        //verifies secret and checks exp
        jwt.verify(token, config.secretKey, function(err, decoded) {
            if(err) {
                var err = new Error('You are not authenticated!');
                err.status = 401;
                return next(err);
            } else {
                //if everything is good, save to request for use in other routes:
                req.decoded = decoded;
                next();
            }
        });
    } else {
        //if there is no token return an error:
        var err = new Error('No token provided!');
        err.status = 403;
        return next(err);
    }
};
@@ -148,176 +148,8 @@
 s');
-%0A//var Blog = require('../models/blog');%0A//var Entry = require('../models/entry');%0A//var Comment = require('../models/comment');%0A//var Post = require('../models/post');
 %0A%0Aex

remove unused require statements