<commit_before>/*
 eslint-disable no-param-reassign, no-underscore-dangle
*/

import { Router } from 'express';
import cas from 'connect-cas';
import url from 'url';

export default (options) => {

  const router = new Router();

  // cas.ssout                    : handle logout requests directly from the CAS server
  // cas.serviceValidate()        : validate service tickets received from the CAS server
  // cas.authenticate()           : request an authentication if the user is not authenticated
  router.get('/', cas.ssout('/auth'), cas.serviceValidate(), cas.authenticate(), async (req, res) => {
    // 从query中获取客户端回调url
    let redirect_uri = req.query.redirect_uri || 'http://itrs-web.itrm.ynu.edu.cn:3000/callback';
    // 从cas的成功回调中获取用户基本信息
    let user = null;
    if (req.session.cas && req.session.cas.user) {
      user = req.session.cas.user;
    }
    res.redirect(301, redirect_uri);
    // res.json({cas: req.session.cas});
  });

  router.get('/logout', async (req, res) => {
    if (req.session.destroy) {
      req.session.destroy();
    } else {
      req.session = null;
    }
    // return res.json({message: 'ok'});
    var options = cas.configure();
    console.info("options", options);
    options.pathname = options.paths.logout;
    return res.redirect(url.format(options));
  });

  router.get('/user', async (req, res) => {
    let user = null;
    if (req.session.cas && req.session.cas.user) {
      user = req.session.cas.user;
    }
    res.json({username: user});
  });


  return router;
};<commit_msg>eslint 修正<commit_after>/*
 eslint-disable no-param-reassign, no-underscore-dangle
*/

import { Router } from 'express';
import cas from 'connect-cas';
import url from 'url';

export default (options) => {
  const router = new Router();

  // cas.ssout                    : handle logout requests directly from the CAS server
  // cas.serviceValidate()        : validate service tickets received from the CAS server
  // cas.authenticate()           : request an authentication if the user is not authenticated
  router.get('/', cas.ssout('/auth'), cas.serviceValidate(), cas.authenticate(), async (req, res) => {
    // 从query中获取客户端回调url
    const redirect_uri = req.query.redirect_uri || 'http://itrs-web.itrm.ynu.edu.cn:3000/callback';
    // 从cas的成功回调中获取用户基本信息
    let user = null;
    if (req.session.cas && req.session.cas.user) {
      user = req.session.cas.user;
    }
    res.redirect(301, redirect_uri);
    // res.json({cas: req.session.cas});
  });

  router.get('/logout', async (req, res) => {
    if (req.session.destroy) {
      req.session.destroy();
    } else {
      req.session = null;
    }
    // return res.json({message: 'ok'});
    const options = cas.configure();
    console.info('options', options);
    options.pathname = options.paths.logout;
    return res.redirect(url.format(options));
  });

  router.get('/user', async (req, res) => {
    let user = null;
    if (req.session.cas && req.session.cas.user) {
      user = req.session.cas.user;
    }
    res.json({ username: user });
  });


  return router;
};
{'fraction_non_alphanumeric': 0.15862738750404662, 'fraction_numerical': 0.004532211071544189, 'mean_word_length': 2.772893772893773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1272392', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1023, 'n_words': 230}