IronRouter授权控制器 [英] IronRouter authorisation controller

查看:89
本文介绍了IronRouter授权控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以演示如何在处理用户身份验证并根据结果显示适当的路由/模板的路由器控制器类上使用全局之前操作。

I'm wondering if anyone could demonstrate how to use a global 'before' action on a router controller class that handles user authentication and displays the appropriate route/template based on the result.

我的用例是有一个AppController充当身份验证防火墙,并在用户注销时阻止所有子控制器操作。例如,

My use case is to have an AppController that acts as an authentication firewall and blocks any child controller actions when a user is logged out. E.g.

// Create a primary app controller stub with the auth firewall
AppController = RouteController.extend({});

// Extend the AppController with all the other app routes
MainController = AppController.extend({});

任何帮助将不胜感激!

推荐答案

在我用流星写的博客中,我使用代码:

In my blog written in meteor I use code :

AppController = RouteController.extend({
  before:function(){
    if(_.isNull(Meteor.user())){
      Router.go(Router.path('home'));
    }
  }
})

AdminPostController = AppController.extend({
  waitOn: function() { return App.subs.posts}
});

Router.map(function(){
  this.route('submitPost', {
    path: '/submitPost',
    controller:'AdminPostController',
    template:'postCreate'
  });
  this.route('editPost', {
    path: '/post/:slug/edit',
    controller:'AdminPostController',
    template:'postEdit'
  });
})

这篇关于IronRouter授权控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆