<commit_before>/**
 * React Starter Kit (https://www.reactstarterkit.com/)
 *
 * Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import 'babel-polyfill';
import path from 'path';
import express from 'express';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import expressJwt from 'express-jwt';
import expressGraphQL from 'express-graphql';
import jwt from 'jsonwebtoken';
import ReactDOM from 'react-dom/server';
import PrettyError from 'pretty-error';
import passport from './core/passport';
import schema from './data/schema';
import Router from './routes';
import assets from './assets';
import { port, auth, analytics } from './config';

//config and test
import {connect, disconnect, SUCCESS, FAIL} from './servers/config'
import {home, test_login} from './servers/test/testController';
//services
import {saveUser, login, register} from './servers/service/LoginService';
import {getFlowListData, getCountData, getLangListData, getCoverData} from './servers/service/HomeService'
import {addLang, getAllLanguage} from './servers/service/LanguageService'
import {evaluateRecommend} from './servers/service/UserService'
import {addAReopSet, addARepoToSet} from './servers/service/RepoService'
import {searchRepo} from './servers/api/github_search'
//others
import {starRepo, followUser} from './servers/api/github_user'

var session = require('express-session');
connect();

const server = global.server = express();
const ret_success = 'success';

//
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known.
// -----------------------------------------------------------------------------
global.navigator = global.navigator || {};
global.navigator.userAgent = global.navigator.userAgent || 'all';

//
// Register Node.js middleware
// -----------------------------------------------------------------------------
server.use(express.static(path.join(__dirname, 'public')));
server.use(cookieParser());
server.use(bodyParser.urlencoded({extended: true}));
server.use(bodyParser.json());
server.use(session({
  secret: 'keyboard cat',
  resave: true,
  saveUninitialized: true,
  cookie: {maxAge: 60000}
}));

//
// Authentication
// -----------------------------------------------------------------------------
server.use(expressJwt({
  secret: auth.jwt.secret,
  credentialsRequired: false,
  /* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
  getToken: req => req.cookies.id_token,
  /* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */
}));
server.use(passport.initialize());

server.get('/login/facebook',
  passport.authenticate('facebook', {scope: ['email', 'user_location'], session: false})
);
server.get('/login/facebook/return',
  passport.authenticate('facebook', {failureRedirect: '/login', session: false}),
  (req, res) => {
    const expiresIn = 60 * 60 * 24 * 180; // 180 days
    const token = jwt.sign(req.user, auth.jwt.secret, {expiresIn});
    res.cookie('id_token', token, {maxAge: 1000 * expiresIn, httpOnly: true});
    res.redirect('/');
  }
);

//
// Register API middleware
// ------------------------------------------------------------------------------
server.use('/graphql', expressGraphQL(req => ({
  schema,
  graphiql: true,
  rootValue: {request: req},
  pretty: process.env.NODE_ENV !== 'production',
})));

// ---------------------------------------------------------------------------------------------------------------my part

//test
//server.get('/api/test', (req, res) => {
//  res.send({res:1});
//});

//login success
server.get('/api/login/success', (req, res)=> {
  saveUser(req.query.code, (ress) => {
    if (ress == 1) {
      res.redirect('/register');
    }
    else res.redirect('/login');
  });
});
//login
server.get('/api/login', (req, res) => {
  login(req.query.username, req.query.password, (res2) => {
    if (res2 == SUCCESS) {
      req.session.username = req.query.username;
      res.send(ret_success);
    } else
      res.send({res: res2});
  })
});
//register
server.get('/api/register', (req, res) => {
  register(req.query.username, req.query.password, (res2) => {
    if (res2 == SUCCESS) {
      res.send(ret_success);
    } else
      res.send({res: res2});
  })
});
//test login
//server.get('/api/test_login', test_login);

//star repo
server.get('/api/repo/star', (req, res)=> {
  starRepo(req.query.user, req.query.repo, resa => {
    if (resa == SUCCESS) res.send({res: SUCCESS});
    else res.send({res: FAIL});
  });
});
//follow user
server.get('/api/user/follow', (req, res)=> {
  followUser(req.query.user, req.query.follow, resa => {
    if (resa == SUCCESS) res.send({res: SUCCESS});
    else res.send({res: FAIL});
  });
});
<commit_msg>modify api<commit_after>/**
 * React Starter Kit (https://www.reactstarterkit.com/)
 *
 * Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import 'babel-polyfill';
import path from 'path';
import express from 'express';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import expressJwt from 'express-jwt';
import expressGraphQL from 'express-graphql';
import jwt from 'jsonwebtoken';
import ReactDOM from 'react-dom/server';
import PrettyError from 'pretty-error';
import passport from './core/passport';
import schema from './data/schema';
import Router from './routes';
import assets from './assets';
import { port, auth, analytics } from './config';

//config and test
import {connect, disconnect, SUCCESS, FAIL} from './servers/config'
import {home, test_login} from './servers/test/testController';
//services
import {saveUser, login, register} from './servers/service/LoginService';
import {getFlowListData, getCountData, getLangListData, getCoverData} from './servers/service/HomeService'
import {addLang, getAllLanguage} from './servers/service/LanguageService'
import {evaluateRecommend} from './servers/service/UserService'
import {addAReopSet, addARepoToSet} from './servers/service/RepoService'
import {searchRepo} from './servers/api/github_search'
//others
import {starRepo, followUser} from './servers/api/github_user'

var session = require('express-session');
connect();

const server = global.server = express();
const ret_success = 'success';

//
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known.
// -----------------------------------------------------------------------------
global.navigator = global.navigator || {};
global.navigator.userAgent = global.navigator.userAgent || 'all';

//
// Register Node.js middleware
// -----------------------------------------------------------------------------
server.use(express.static(path.join(__dirname, 'public')));
server.use(cookieParser());
server.use(bodyParser.urlencoded({extended: true}));
server.use(bodyParser.json());
server.use(session({
  secret: 'keyboard cat',
  resave: true,
  saveUninitialized: true,
  cookie: {maxAge: 60000}
}));

//
// Authentication
// -----------------------------------------------------------------------------
server.use(expressJwt({
  secret: auth.jwt.secret,
  credentialsRequired: false,
  /* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
  getToken: req => req.cookies.id_token,
  /* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */
}));
server.use(passport.initialize());

server.get('/login/facebook',
  passport.authenticate('facebook', {scope: ['email', 'user_location'], session: false})
);
server.get('/login/facebook/return',
  passport.authenticate('facebook', {failureRedirect: '/login', session: false}),
  (req, res) => {
    const expiresIn = 60 * 60 * 24 * 180; // 180 days
    const token = jwt.sign(req.user, auth.jwt.secret, {expiresIn});
    res.cookie('id_token', token, {maxAge: 1000 * expiresIn, httpOnly: true});
    res.redirect('/');
  }
);

//
// Register API middleware
// ------------------------------------------------------------------------------
server.use('/graphql', expressGraphQL(req => ({
  schema,
  graphiql: true,
  rootValue: {request: req},
  pretty: process.env.NODE_ENV !== 'production',
})));

// ---------------------------------------------------------------------------------------------------------------my part

//test
//server.get('/api/test', (req, res) => {
//  res.send({res:1});
//});

//login success
server.get('/api/login/success', (req, res)=> {
  saveUser(req.query.code, (ress) => {
    if (ress == 1) {
      res.redirect('/register');
    }
    else res.redirect('/login');
  });
});
//login
server.get('/api/login', (req, res) => {
  login(req.query.username, req.query.password, (res2) => {
    if (res2 == SUCCESS) {
      req.session.username = req.query.username;
      res.send({res: SUCCESS});
    } else
      res.send({res: res2});
  })
});
//register
server.get('/api/register', (req, res) => {
  register(req.query.username, req.query.password, (res2) => {
    if (res2 == SUCCESS) {
      res.send({res: SUCCESS});
    } else
      res.send({res: res2});
  })
});
//test login
//server.get('/api/test_login', test_login);

//star repo
server.get('/api/repo/star', (req, res)=> {
  starRepo(req.query.user, req.query.repo, resa => {
    if (resa == SUCCESS) res.send({res: SUCCESS});
    else res.send({res: FAIL});
  });
});
//follow user
server.get('/api/user/follow', (req, res)=> {
  followUser(req.query.user, req.query.follow, resa => {
    if (resa == SUCCESS) res.send({res: SUCCESS});
    else res.send({res: FAIL});
  });
});

{'fraction_non_alphanumeric': 0.24761318139821373, 'fraction_numerical': 0.007596755979878862, 'mean_word_length': 2.793613707165109, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2916809', 'n_tokens_mistral': 2949, 'n_tokens_neox': 2888, 'n_words': 711}