Yes, how you handle promises and rc's might be part of the problem. Which is why I'm looking for the answer to my previous question. You *might* not be handling the promise or result of the ajax call properly.
On Sat, Mar 14, 2015 at 1:12 AM, Daniela Blanco <[email protected]> wrote: > Sorry, this part "next.$$route.authenticate", is with doble $$? what? > > I'm new to angular but I'm working with a very similar problem. > In muy case .run is: > > .run(function($state, Config, LoginServ) { > if (Config.configToken !== "undefined") { > LoginServ.LogInToken().success(function (json_rta) { > var acceso = json_rta.acceso; > var permisos = json_rta.permisos; > > if (acceso === true) { > LoginServ.SetLogueo(true); > if ($state.includes("login")) { > $state.go('app.ranking'); > } > } else { > LoginServ.LogOut(); > } > > }).error(function (response){ > }); > }; > }); > > .config(function($stateProvider, $urlRouterProvider, $provide) { > $provide.value('Config', { > configToken: "undefined", > configSector: "undefined", > configCategoria: "undefined", > configLogin: "undefined" > }) > )} > > .factory('LoginServ', function ($state, $http, Config) { > var loginAPI = {}; > > loginAPI.LogInToken = function(token) { > var token = Config.configToken; > > return $http({ > method : 'POST', > url: UrlRaiz + 'index.php/ingreso_logueado/', > data: { > token: token, > } > }); > } > > return loginAPI; > }); > > The problem of asynchronism is running the service "LoginServ" but without > this end, continued by routing. > I found articles that say to use "promise" in server and "resolve" in > routing. I can not even give a complete solution yet. > Some help? > > El viernes, 13 de marzo de 2015, 1:04:01 (UTC-3), Maxime Dubois escribió: > >> Hi everyone! >> >> I've been trying for too long now, I need your help! >> >> What I'm trying to achieve here is that I need to validate server-side >> (PHP) if the user is logged in or not. Then if he's not, I redirect to the >> login page. >> >> It's working good until I reach the point where it redirects to the login >> page. What I found is that even if I do event.preventDefault(), angular >> will still load my dashboard.html partial and then redirect to login. >> That's what is bothering right now.. If I want the user to be redirect, I >> don't want angular to load my partial view before redirecting.. >> >> I'm guessing that it's because of the async call.. But I don't know how >> to get around this problem! >> >> Here's my code >> >> sruApp.config(['$routeProvider', >> function($routeProvider) { >> $routeProvider. >> when('/', { >> templateUrl: './partials/home.html', >> controller: 'HomeCtrl', >> authenticate: false >> }). >> when('/login', { >> templateUrl: './partials/login.html', >> controller: 'LoginCtrl', >> authenticate: false >> }). >> when('/dashboard', { >> templateUrl: './partials/dashboard.html', >> controller: 'DashboardCtrl', >> authenticate: true >> }). >> when('/logout', { >> templateUrl: './partials/logout.html', >> controller: 'LogoutCtrl', >> authenticate: false >> }). >> when('/register', { >> templateUrl: './partials/register.html', >> controller: 'RegisterCtrl', >> authenticate: false >> }); >> }]); >> >> sruApp.run(["$rootScope", "$location", "user", function($rootScope, >> $location, user) { >> $rootScope.$on('$routeChangeStart', function (event, next, current) { >> user.isLoggedIn().then(function(res) { //async call to php api return if >> $_SESSION["isLoggedIn"] == true || false >> $rootScope.isLoggedIn = res.result; >> if(next.$$route.authenticate) { >> if(!res.result) { >> event.preventDefault(); >> $location.path("/login"); >> } >> } >> }); >> }); >> }]); >> >> user factory : >> sruApp.factory("user", ['$rootScope', '$http', function($rootScope, >> $http) { >> var appAPI = "./server/app/"; >> var obj = {}; >> obj.isLoggedIn = function() { >> return $http.get(appAPI + 'user/isLoggedIn'); >> }; >> obj.logout = function() { >> return $http.get(appAPI + 'user/logout'); >> }; >> return obj; >> }]); >> >> I hope someone will be able to help me with this! i'm struggling with >> this problem for hours now.. >> >> Thanks! >> > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
