<commit_before>'use strict';

import express from 'express';
import passport from 'passport';
import User from "../../api/user/user.model";
import {signToken} from '../auth.service';

var router = express.Router();

router.post('/', function(req, res, next) {
  var studentOnly = req.query.studentOnly;
  var instructorOnly = req.query.instructorOnly;
  passport.authenticate('local', function(err, user, info) {
    var error = err || info;
    if (error) {
      return res.status(401).json(error);
    }
    if (!user) {
      return res.status(404).json({message: 'Something went wrong, please try again.'});
    }

    var profile = user.profile;
    User.findById(profile._id).then((user) => {
      if (studentOnly === true && profile.isInstructor){
        res.status(401).json({"message": "user is not a student"});
      }else if (instructorOnly === true && !profile.isInstructor){
        res.status(401).json({"message": "user is not an instructor"});
      }
      var token = signToken(user._id, user.role);
      res.json({ token, profile });
    });
  })(req, res, next)
});

export default router;<commit_msg>fixed double response problem<commit_after>'use strict';

import express from 'express';
import passport from 'passport';
import User from "../../api/user/user.model";
import {signToken} from '../auth.service';

var router = express.Router();

router.post('/', function(req, res, next) {
  var studentOnly = req.query.studentOnly;
  var instructorOnly = req.query.instructorOnly;
  passport.authenticate('local', function(err, user, info) {
    var error = err || info;
    if (error) {
      return res.status(401).json(error);
    }
    if (!user) {
      return res.status(404).json({message: 'Something went wrong, please try again.'});
    }

    var profile = user.profile;
    User.findById(profile._id).then((user) => {
      if (studentOnly === true && profile.isInstructor){
        res.status(401).json({"message": "user is not a student"});
        return;
      }else if (instructorOnly === true && !profile.isInstructor){
        res.status(401).json({"message": "user is not an instructor"});
        return;
      }
      var token = signToken(user._id, user.role);
      res.json({ token, profile });
    });
  })(req, res, next)
});

export default router;
{'fraction_non_alphanumeric': 0.16695652173913045, 'fraction_numerical': 0.010434782608695653, 'mean_word_length': 3.325187969924812, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, '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': '7456641', 'n_tokens_mistral': 714, 'n_tokens_neox': 686, 'n_words': 186}