Last active
August 29, 2015 14:20
-
-
Save CocaColaCat/d76ab10a4ebf08782a99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('app',[]) | |
| .config([, function(){ | |
| //项目列表路由 | |
| .state('projects',{ | |
| url:'/projects', | |
| templateUrl:"app/project/ProjectList.html", | |
| controller:"ProjectListCtrl", | |
| access:{requireLogin:true} | |
| }) | |
| .state('get_wechat_token',{ | |
| url:"/get_wechat_token?code", | |
| controller:"WechatAuthCtrl", | |
| access:{requireLogin:false} | |
| }) | |
| }]) | |
| .run(["$rootScope", "$window", "$state", "AuthService", | |
| function($rootScope, $window, $state, AuthServic) { | |
| $rootScope.$on("$stateChangeStart", | |
| function(event, nextRoute, currentRoute){ | |
| // 请求的路径要求登录同时没有授权令牌 | |
| if( nextRoute.access.requireLogin && | |
| !AuthService.is_logined() && | |
| !AuthService.initCheckToken()) { | |
| event.preventDefault(); | |
| // 只针对微信浏览器 | |
| if (AuthService.isWechatBrowser()){ | |
| // 尝试通过 openid 换取用户登录令牌 | |
| $window.location.href = AuthService.getWechatAuthorizeUrl(); | |
| }else{ | |
| $location.path("/login"); | |
| } | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment