Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions www/core/components/contentlinks/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('mm.core.contentlinks')
*/
.factory('$mmContentLinksHelper', function($log, $ionicHistory, $state, $mmSite, $mmContentLinksDelegate, $mmUtil, $translate,
$mmCourseHelper, $mmSitesManager, $q, $mmLoginHelper, $mmText, mmCoreConfigConstants, $mmCourse, $mmApp,
$mmContentLinkHandlerFactory) {
$mmContentLinkHandlerFactory, $mmAddonManager, mmCoreNoSiteId) {

$log = $log.getInstance('$mmContentLinksHelper');

Expand Down Expand Up @@ -220,7 +220,13 @@ angular.module('mm.core.contentlinks')
return $mmSitesManager.checkSite(siteUrl).then(function(result) {
// Site exists. We'll allow to add it.
var promise,
ssoNeeded = $mmLoginHelper.isSSOLoginNeeded(result.code);
ssoNeeded = $mmLoginHelper.isSSOLoginNeeded(result.code),
hasRemoteAddonsLoaded = false,
stateParams = {
siteurl: result.siteurl,
username: username,
urltoopen: url
};

modal.dismiss(); // Dismiss modal so it doesn't collide with confirms.

Expand All @@ -231,6 +237,12 @@ angular.module('mm.core.contentlinks')
// Ask the user before changing site.
promise = $mmUtil.showConfirm($translate('mm.contentlinks.confirmurlothersite')).then(function() {
if (!ssoNeeded) {
hasRemoteAddonsLoaded = $mmAddonManager.hasRemoteAddonsLoaded();
if (hasRemoteAddonsLoaded) {
// Store the redirect since logout will restart the app.
$mmApp.storeRedirect(mmCoreNoSiteId, 'mm_login.credentials', stateParams);
}

return $mmSitesManager.logout().catch(function() {
// Ignore errors (shouldn't happen).
});
Expand All @@ -242,12 +254,8 @@ angular.module('mm.core.contentlinks')
if (ssoNeeded) {
$mmLoginHelper.confirmAndOpenBrowserForSSOLogin(
result.siteurl, result.code, result.service, result.config && result.config.launchurl);
} else {
$state.go('mm_login.credentials', {
siteurl: result.siteurl,
username: username,
urltoopen: url
});
} else if (!hasRemoteAddonsLoaded) {
$state.go('mm_login.credentials', stateParams);
}
});

Expand Down
25 changes: 16 additions & 9 deletions www/core/components/login/controllers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ angular.module('mm.core.login')
* @ngdoc controller
* @name mmLoginInitCtrl
*/
.controller('mmLoginInitCtrl', function($log, $ionicHistory, $state, $mmSitesManager, $mmSite, $mmApp, $mmLoginHelper) {
.controller('mmLoginInitCtrl', function($log, $ionicHistory, $state, $mmSitesManager, $mmSite, $mmApp, $mmLoginHelper,
mmCoreNoSiteId) {

$log = $log.getInstance('mmLoginInitCtrl');

Expand All @@ -41,14 +42,20 @@ angular.module('mm.core.login')

// Only accept the redirect if it was stored less than 20 seconds ago.
if (new Date().getTime() - redirectData.timemodified < 20000) {
return $mmSitesManager.loadSite(redirectData.siteid).then(function() {
if (!$mmLoginHelper.isSiteLoggedOut(redirectData.state, redirectData.params)) {
$state.go(redirectData.state, redirectData.params);
}
}).catch(function() {
// Site doesn't exist.
loadCurrent();
});
if (redirectData.siteid != mmCoreNoSiteId) {
// The redirect is pointing to a site, load it.
return $mmSitesManager.loadSite(redirectData.siteid).then(function() {
if (!$mmLoginHelper.isSiteLoggedOut(redirectData.state, redirectData.params)) {
$state.go(redirectData.state, redirectData.params);
}
}).catch(function() {
// Site doesn't exist.
loadCurrent();
});
} else {
// No site to load, just open the state.
return $state.go(redirectData.state, redirectData.params);
}
}
}

Expand Down
24 changes: 15 additions & 9 deletions www/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ angular.module('mm.core', ['pascalprecht.translate'])
.constant('mmCoreSecondsHour', 3600)
.constant('mmCoreSecondsMinute', 60)
.constant('mmCoreDontShowError', 'mmCoreDontShowError') // Pass it to reject functions to indicate that no error should be shown.
.constant('mmCoreNoSiteId', 'NoSite')

// States for downloading files/modules.
.constant('mmCoreDownloaded', 'downloaded')
Expand Down Expand Up @@ -96,19 +97,24 @@ angular.module('mm.core', ['pascalprecht.translate'])
cache: false,
template: '<ion-view><ion-content mm-state-class><mm-loading class="mm-loading-center"></mm-loading></ion-content></ion-view>',
controller: function($scope, $state, $stateParams, $mmSite, $mmSitesManager, $ionicHistory, $mmAddonManager, $mmApp,
$mmLoginHelper) {
$mmLoginHelper, mmCoreNoSiteId) {

$ionicHistory.nextViewOptions({disableBack: true});

function loadSiteAndGo() {
$mmSitesManager.loadSite($stateParams.siteid).then(function() {
if (!$mmLoginHelper.isSiteLoggedOut($stateParams.state, $stateParams.params)) {
$state.go($stateParams.state, $stateParams.params);
}
}, function() {
// Site doesn't exist.
$state.go('mm_login.sites');
});
if ($stateParams.siteid == mmCoreNoSiteId) {
// No site to load, just go to the state.
$state.go($stateParams.state, $stateParams.params);
} else {
$mmSitesManager.loadSite($stateParams.siteid).then(function() {
if (!$mmLoginHelper.isSiteLoggedOut($stateParams.state, $stateParams.params)) {
$state.go($stateParams.state, $stateParams.params);
}
}, function() {
// Site doesn't exist.
$state.go('mm_login.sites');
});
}
}

$scope.$on('$ionicView.enter', function() {
Expand Down