<commit_before>_path = require("path")
_bijou = require("bijou")
_async = require 'async'
_fs = require 'fs-extra'
_ = require 'lodash'
_moment = require 'moment'

_common = require './common'
_entity = require './entity'
_memberBiz = require './biz/member'
_realtime = require './notification/realtime'
_cache = require './cache'
_staticRouter = require './config/routers/static'

getMemberWithToken = (token, cb)->
  _entity.token.findMemberId token, (err, member)->
    member =
      member_id: member?.id
      role: member?.role

    member.isLogin = Boolean(member.member_id)
    cb member

#记住用户密码
getMemberWithRemember = (req, cb)->
  member = member_id: 0, isLogin: false
  member_id = req.cookies.member_id
  return cb member if not member_id

  #从数据库中查找
  _entity.member.findById member_id, (err, result)->
    return cb member if err or not result

    _memberBiz.setSession req, result
    member.member_id = result.id
    member.role = result.role
    member.isLogin = true
    cb member

#从session中获取member
getMemberWithSession = (req, cb)->
  #从session中读取token
  member_id = req.session.member_id || -1

  #如果用户没有登录，则判断是否有记住密码
  if not member_id
    return getMemberWithRemember req, cb if req.cookies.remember and req.cookies.member_id

  #直接从session获取
  member =
    role: req.session.role
    member_id: member_id
    isLogin: Boolean(member_id)
    gitlab_token: req.session.gitlab_token<commit_msg>isLogin考虑匿名用户的情况<commit_after>_path = require("path")
_bijou = require("bijou")
_async = require 'async'
_fs = require 'fs-extra'
_ = require 'lodash'
_moment = require 'moment'

_common = require './common'
_entity = require './entity'
_memberBiz = require './biz/member'
_realtime = require './notification/realtime'
_cache = require './cache'
_staticRouter = require './config/routers/static'

getMemberWithToken = (token, cb)->
  _entity.token.findMemberId token, (err, member)->
    member =
      member_id: member?.id
      role: member?.role

    member.isLogin = member.member_id > 0
    cb member

#记住用户密码
getMemberWithRemember = (req, cb)->
  member = member_id: 0, isLogin: false
  member_id = req.cookies.member_id
  return cb member if not member_id

  #从数据库中查找
  _entity.member.findById member_id, (err, result)->
    return cb member if err or not result

    _memberBiz.setSession req, result
    member.member_id = result.id
    member.role = result.role
    member.isLogin = true
    cb member

#从session中获取member
getMemberWithSession = (req, cb)->
  #从session中读取token
  member_id = req.session.member_id || -1

  #如果用户没有登录，则判断是否有记住密码
  if not member_id
    return getMemberWithRemember req, cb if req.cookies.remember and req.cookies.member_id

  #直接从session获取
  member =
    role: req.session.role
    member_id: member_id
    isLogin: member_id > 0
    gitlab_token: req.session.gitlab_token
{'fraction_non_alphanumeric': 0.10660077656194847, 'fraction_numerical': 0.002117896223085069, 'mean_word_length': 3.7630252100840336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1420446', 'n_tokens_mistral': 1007, 'n_tokens_neox': 1027, 'n_words': 241}