{"size": 452, "ext": "js", "max_stars_repo_path": "packages/iioo-app-mark-live/src/server/http/handles/login.js", "max_stars_repo_name": "big-wheel/iioo", "max_stars_repo_stars_event_min_datetime": "2018-06-07T14:15:42.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-09T14:38:20.000Z", "max_issues_repo_path": "packages/iioo-app-mark-live/src/server/http/handles/login.js", "max_issues_repo_name": "big-wheel/iioo", "max_issues_repo_issues_event_min_datetime": "2018-01-19T13:29:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-27T02:47:09.000Z", "max_forks_repo_path": "packages/iioo-app-mark-live/src/server/http/handles/login.js", "max_forks_repo_name": "big-wheel/hawkeyee", "max_forks_repo_forks_event_min_datetime": "2018-05-08T06:27:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-08T06:27:46.000Z"}
{"max_stars_count": 2, "max_issues_count": 8, "max_forks_count": 1, "avg_line_length": 18.08, "max_line_length": 57, "alphanum_fraction": 0.5575221239}
/**
 * @file login
 * @author Cuttle Cong
 * @date 2018/5/4
 * @description
 */
const User = require('../../model/User')
const wrap = require('../../util/wrapHandle')

module.exports = function (msg = 'please login in!') {
  return wrap(async (req, res, next) => {
    if (!req.session.userId) {
      res.fail(msg)
      return
    }
    if (!await User.exists({ id: req.session.userId })) {
      res.fail(msg)
      return
    }

    next()
  })

}
