我希望通过外部服务为我的路由创建一个简单的身份验证检查.
我定义了路由对象的访问要求:
$routeProvider
.when('/', {
templateUrl: 'src/app/views/index.html',
controller: 'indexCtrl',
authenticated: true
})
.when('/login', {
templateUrl: 'src/app/views/login.html',
controller: 'loginCtrl',
anonymous: true
})
.otherwise({
redirectTo: '/'
})
;
Run Code Online (Sandbox Code Playgroud)
然后,我检查我是否在$routeChangeStart
活动中获得了许可.
$rootScope.$on('$routeChangeStart', function (event, next) {
if(next.authenticated && !$myService.isLoggedin())
$location.path("/login");
else if(next.anonymous && $myService.isLoggedin())
$location.path("/secured");
});
Run Code Online (Sandbox Code Playgroud)
实际上,它是有效的 -
如果未经过身份验证的用户将他移动到登录页面,如果他已经过身份验证但路由仅供匿名用户使用,则将其移至另一个页面等.
但是 - 这个重定向实际上是在加载控制器和模板之后发生的! 它导致我的控制器对我的REST API做了一些不必要的请求,即使我没有经过身份验证.
如何在处理之前处理路线?
javascript authentication angularjs angularjs-routing angularjs-authentication
我在我的笔记本电脑上运行 Drupal 7.16(Windows7 x64 和 6GB RAM over EasyPHP12.1)。
目前,drupal 运行非常缓慢!
我已经尝试:
realpath_cache_size
增加到24M
innodb_flush_log_at_trx_commit
为0
hosts
文件以解决 ipv6 错误..SELECT uid FROM users
) 时,phpMyAdmin 返回一个快速响应(0.0009s)。谢谢
~Almog
*我也尝试过 UniformServer,但它仍然很慢,并且更改了 my.ini 跟随这里的帖子(stackexchange 网站)和 follwing drupal.org
**似乎 wordpress 加载速度很快,所以似乎问题仅在于 drupal ?