'use strict';

module.exports = function ($scope, $location, $service) {
    console.log('CartOauthCtrl');

    $scope.hasBeenInited = false;

    $scope.startOauthProcess = function() {
        $service.getOauthUrl().then(function(result) {
            window.location.href = result.url;
        });
    };

    $service.isBlogAuthed().then(function(result) {
        if (result.isAuthed) {
            $location.url('/master');
        } else {
            $scope.hasBeenInited = true;
        }
    });
};
'use strict';

module.exports = function ($scope, $location, $accessService) {
    console.log('CartOauthCtrl');

    $scope.hasBeenInited = false;

    $scope.startOauthProcess = function() {
        $accessService.getOauthUrl().then(function(result) {
            window.location.href = result.url;
        });
    };

    $accessService.isBlogAuthed().then(function(result) {
        var isMaster = $accessService.isMaster();
        if (result.isAuthed && isMaster) {
            $location.url('/master');
        } else if (result.isAuthed && !isMaster) {
            $location.url('/login');
        } else {
            $scope.hasBeenInited = true;
        }
    });
};
Fix oauth page response, redirect user to login page, if site already authed, not throw user into error page.