当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript composable-middleware.default函数代码示例

本文整理汇总了TypeScript中composable-middleware.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: hasRole

  /**
   * Checks if the user role meets the minimum requirements of the route
   */
  public static hasRole(roleRequired: string) {
    if (!roleRequired) {
      throw new Error('Required role needs to be set');
    } 
    var meetsRequirements = (req: express.Request, res: express.Response, next: Function) => {
      if (config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf(roleRequired)) {
        next();
      }
      else {
        res.send(403);
      }
    }

    return compose()
      .use(AuthService.isAuthenticated())
      .use(meetsRequirements);
  }
开发者ID:pgrm,项目名称:logtank,代码行数:20,代码来源:auth.service.ts

示例2: isAuthenticated

export function isAuthenticated() {
  return compose()
    // Validate jwt
    .use((req, res, next) => {
      // allow access_token to be passed through query parameter as well
      if (req.query && req.query.hasOwnProperty('access_token')) {
        req.headers.authorization = 'Bearer ' + req.query.access_token;
      }
      return validateJwt(req, res, next);
    })
    // Attach user to request
    .use((req, res, next) => {
      return User.findById(req.user.id)
        .then(user => {
          if (!user) {
            return res.status(401).json({ message: 'Invalid Token' });
          }
          req.user = user;
          next();
          // runnaway promise to remove node warning
          return null;
        })
        .catch(err => next(err));
    });
}
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:25,代码来源:auth.service.ts

示例3: isAuthenticated

export function isAuthenticated() {
  return compose()
    // Validate jwt
    .use((req, res, next) => {
      // allow access_token to be passed through query parameter as well
      if (req.query && req.query.hasOwnProperty('access_token')) {
        req.headers.authorization = 'Bearer ' + req.query.access_token;
      }
      return validateJwt(req, res, next);
    })
    // Attach user to request
    .use((req, res, next) => {
      let user;
      return UserModel.userByEmail(req.user.email)
        .then(result => {
          user = result.rows[0];
          if (!user || user > 1)
            res.status(401).json({ message: 'Invalid Token' });

          req.user = user;
          next();
        })
        .catch(err => next(err));
    });
}
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:25,代码来源:auth.service.ts

示例4: hasRole

    /**
     * Checks if the user role meets the minimum requirements of the route
     */
    static hasRole(roleRequired) {
        if (!roleRequired) throw new Error('Required role needs to be set');

        return compose()
            .use(AuthService.isAuthenticated())
            .use(function meetsRequirements(req, res, next) {
                if (config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf(roleRequired)) {
                    next();
                }
                else {
                    res.status(200).json({status: 'FORBIDDEN'});
                }
            });
    }
开发者ID:suvetig,项目名称:ppt,代码行数:17,代码来源:auth-service.ts

示例5: hasRole

export function hasRole(roleRequired) {
  if (!roleRequired) {
    throw new Error('Required role needs to be set');
  }

  return compose()
    .use(isAuthenticated())
    .use(function meetsRequirements(req, res, next) {
      if (config.userRoles.indexOf(req.user.role) >=
        config.userRoles.indexOf(roleRequired)) {
        next();
      } else {
        res.status(403).send('Forbidden');
      }
    });
}
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:16,代码来源:auth.service.ts

示例6: compose

    isAuthenticated: function () {
        return compose()
            .use(function(req, res, next) {
                validateJwt(req, res, next);
            })
            .use(function(req, res, next) {
                User.findById(req.user._id, function (err, user) {
                    if (err)
                        return next(err);

                    if (!user)
                        return res.send(401);

                    req.user = user;
                    next();
                });
            });
    },
开发者ID:NovaeWorkshop,项目名称:Nova,代码行数:18,代码来源:auth.service.ts

示例7: isAuthenticated

  /**
   * Attaches the user object to the request if authenticated
   * Otherwise returns 403
   */
  public static isAuthenticated() {
    return compose()
      // Validate jwt
      .use(function(req, res, next) {
        // allow access_token to be passed through query parameter as well
        if(req.query && req.query.hasOwnProperty('access_token')) {
          req.headers.authorization = 'Bearer ' + req.query.access_token;
        }
        validateJwt(req, res, next);
      })
      // Attach user to request
      .use(function(req, res, next) {
        user.Model.findById(req.user._id, function (err, user) {
          if (err) return next(err);
          if (!user) return res.send(401);

          req.user = user;
          next();
        });
      });
  }
开发者ID:pgrm,项目名称:logtank,代码行数:25,代码来源:auth.service.ts


注:本文中的composable-middleware.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。