message: Reduce duplication and simplify code
diff: @@ -31,7 +31,7 @@ exports.cutOffPoisonNullByte = str => {
  exports.isAuthorized = () => expressJwt({ secret: this.publicKey })
  exports.denyAll = () => expressJwt({ secret: '' + Math.random() })
  exports.authorize = (user = {}) => jwt.sign(user, privateKey, { expiresIn: 3600 * 5, algorithm: 'RS256' })
  -exports.verify = (token) => jwt.verify(token, publicKey, { algorithms: ['RS256'] })
  +exports.verify = (token) => jwt.verify(token, publicKey, { algorithms: ['RS256', 'HS256'] })
  exports.sanitizeHtml = html => sanitizeHtml(html)
  exports.sanitizeLegacy = (input = '') => input.replace(/<(?:\w+)\W+?[\w]/gi, '')
  @@ -125,8 +125,8 @@ exports.roles = {
  exports.isAccounting = () => {
  return (req, res, next) => {
  - const decodedToken = jwt.verify(utils.jwtFrom(req), publicKey, { algorithms: ['RS256'] })
  - if (decodedToken.data.role === exports.roles.accounting) {
  + const decodedToken = this.verify(utils.jwtFrom(req))
  + if (decodedToken && decodedToken.data && decodedToken.data.role === exports.roles.accounting) {
  next()
  } else {
  res.status(403).json({ error: 'Malicious activity detected' })
  @@ -134,6 +134,16 @@ exports.isAccounting = () => {
  }
  }
  +exports.isDeluxe = (req) => {
  + const decodedToken = this.verify(utils.jwtFrom(req))
  + return decodedToken && decodedToken.data && decodedToken.data.role === exports.roles.deluxe;
  +}
  +
  +exports.isCustomer = (req) => {
  + const decodedToken = this.verify(utils.jwtFrom(req))
  + return decodedToken && decodedToken.data && decodedToken.data.role === exports.roles.customer;
  +}
  +
  exports.appendUserId = () => {
  return (req, res, next) => {
  try {
  @@ -144,21 +154,3 @@ exports.appendUserId = () => {
  }
  }
  }
  -
  -exports.isDeluxe = (req) => {
  - const decodedToken = jwt.verify(utils.jwtFrom(req), publicKey, { algorithms: ['RS256'] })
  - if (decodedToken.data.role === exports.roles.deluxe) {
  - return true
  - } else {
  - return false
  - }
  -}
  -
  -exports.isCustomer = (req) => {
  - const decodedToken = jwt.verify(utils.jwtFrom(req), publicKey, { algorithms: ['RS256'] })
  - if (decodedToken.data.role === exports.roles.customer) {
  - return true
  - } else {
  - return false
  - }
  -}
  