<commit_before>var con  = require('./database').connection;


module.exports = {
	isLoggedIn:function(req,res,next){
		if (req.isAuthenticated()){
      return next();
		}else{
      res.redirect('/login');
    }
	},

  isAdmin:function(req,res,next){
    if (req.isAuthenticated()){
      con.query("SELECT * FROM admins WHERE email=?",[req.user.email],
        function(error, row){
          if (row !== undefined && row.length > 0){
            req.user.isAdmin = true;
            req.user.isStudent = false;
            req.user.isTeacher = true;
            req.user.local = row;
            return next(); 
          }else{
            res.redirect('/student');
          }
        }
      );
    }else{
      res.redirect('/auth/google');
    }

  },

  isStudent:function(req,res,next){
    if (req.isAuthenticated()){
      con.query("SELECT * FROM students WHERE email=?",[req.user.email],
        function(error, row){
          if (row !== undefined && row.length > 0){
            // TODO: should run a query to verify if this student is also an admin
            req.user.isAdmin = false;
            req.user.isStudent = true;
            req.user.isTeacher = false;
            req.user.local = row;
            return next(); 
          }else{
            res.redirect('/teacher');
          }
        }
      );
    }else{
      res.redirect('/auth/google');
    }
  },



  isTeacher:function(req,res,next){
    console.log("TEACHER AUTH");
    if (req.isAuthenticated()){
      con.query("SELECT * FROM teachers WHERE teacher_email=?",[req.user.email],function(error,row){
        console.log("ROW");
        console.log(row);
        if (row !== undefined && row.length > 0){
          console.log("SUCCESS!");
          // TODO should run a query to verify if this teacher is also an admin
          req.user.isAdmin = false;
          req.user.isStudent = false;
          req.user.isTeacher = true;
          req.user.local = row;
          return next();
        }else{
          console.log("FAIL
          res.redirect('/student');
        }
      });
    }else{
      res.redirect('/auth/google');
    }
  }


 }<commit_msg>testing<commit_after>var con  = require('./database').connection;


module.exports = {
	isLoggedIn:function(req,res,next){
		if (req.isAuthenticated()){
      return next();
		}else{
      res.redirect('/login');
    }
	},

  isAdmin:function(req,res,next){
    if (req.isAuthenticated()){
      con.query("SELECT * FROM admins WHERE email=?",[req.user.email],
        function(error, row){
          if (row !== undefined && row.length > 0){
            req.user.isAdmin = true;
            req.user.isStudent = false;
            req.user.isTeacher = true;
            req.user.local = row;
            return next(); 
          }else{
            res.redirect('/student');
          }
        }
      );
    }else{
      res.redirect('/auth/google');
    }

  },

  isStudent:function(req,res,next){
    if (req.isAuthenticated()){
      con.query("SELECT * FROM students WHERE email=?",[req.user.email],
        function(error, row){
          if (row !== undefined && row.length > 0){
            // TODO: should run a query to verify if this student is also an admin
            req.user.isAdmin = false;
            req.user.isStudent = true;
            req.user.isTeacher = false;
            req.user.local = row;
            return next(); 
          }else{
            res.redirect('/teacher');
          }
        }
      );
    }else{
      res.redirect('/auth/google');
    }
  },



  isTeacher:function(req,res,next){
    console.log("TEACHER AUTH");
    if (req.isAuthenticated()){
      con.query("SELECT * FROM teachers WHERE teacher_email=?",[req.user.email],function(error,row){
        console.log("ROW");
        console.log(row);
        if (row !== undefined && row.length > 0){
          console.log("SUCCESS!");
          // TODO should run a query to verify if this teacher is also an admin
          req.user.isAdmin = false;
          req.user.isStudent = false;
          req.user.isTeacher = true;
          req.user.local = row;
          return next();
        }else{
          console.log("FAIL");
          res.redirect('/student');
        }
      });
    }else{
      res.redirect('/auth/google');
    }
  }


 }
{'fraction_non_alphanumeric': 0.15168408826945412, 'fraction_numerical': 0.0013937282229965157, 'mean_word_length': 1.8125408229915088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '578830', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1271, 'n_words': 260}