diff --git a/www/addons/files/controllers/choosesite.js b/www/addons/files/controllers/choosesite.js index b74eef5309a..db2bd525cb1 100644 --- a/www/addons/files/controllers/choosesite.js +++ b/www/addons/files/controllers/choosesite.js @@ -21,7 +21,8 @@ angular.module('mm.addons.files') * @ngdoc controller * @name mmaFilesChooseSiteCtrl */ -.controller('mmaFilesChooseSiteCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmaFilesHelper, $ionicHistory) { +.controller('mmaFilesChooseSiteCtrl', function($scope, $stateParams, $mmSitesManager, $mmaFilesHelper, $ionicHistory, + $mmLoginHelper) { var fileEntry = $stateParams.file || {}; $scope.filename = fileEntry.name; @@ -35,7 +36,7 @@ angular.module('mm.addons.files') $ionicHistory.nextViewOptions({ disableBack: true }); - $state.go('site.mm_courses'); + $mmLoginHelper.goToSiteInitialPage(); }); }; }); diff --git a/www/core/components/login/controllers/credentials.js b/www/core/components/login/controllers/credentials.js index 6e8b99dd1b7..f0e2554d336 100644 --- a/www/core/components/login/controllers/credentials.js +++ b/www/core/components/login/controllers/credentials.js @@ -117,11 +117,11 @@ angular.module('mm.core.login') // Action should only have 1 site because we're filtering by username. action.action(action.sites[0]); } else { - $state.go('site.mm_courses'); + return $mmLoginHelper.goToSiteInitialPage(); } }); } else { - $state.go('site.mm_courses'); + return $mmLoginHelper.goToSiteInitialPage(); } }); }).catch(function(error) { diff --git a/www/core/components/login/controllers/init.js b/www/core/components/login/controllers/init.js index 0fdb66fede4..337ae82d67d 100644 --- a/www/core/components/login/controllers/init.js +++ b/www/core/components/login/controllers/init.js @@ -34,7 +34,7 @@ angular.module('mm.core.login') }); if ($mmSite.isLoggedIn()) { - $state.go('site.mm_courses'); + $mmLoginHelper.goToSiteInitialPage(); } else { $mmSitesManager.hasSites().then(function() { return $state.go('mm_login.sites'); diff --git a/www/core/components/login/controllers/reconnect.js b/www/core/components/login/controllers/reconnect.js index da6e588a431..f29464e6afe 100644 --- a/www/core/components/login/controllers/reconnect.js +++ b/www/core/components/login/controllers/reconnect.js @@ -21,7 +21,8 @@ angular.module('mm.core.login') * @ngdoc controller * @name mmLoginReconnectCtrl */ -.controller('mmLoginReconnectCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmApp, $mmUtil, $ionicHistory) { +.controller('mmLoginReconnectCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmApp, $mmUtil, $ionicHistory, + $mmLoginHelper) { var infositeurl = $stateParams.infositeurl; // Siteurl in site info. It might be different than siteurl (http/https). $scope.siteurl = $stateParams.siteurl; @@ -63,7 +64,7 @@ angular.module('mm.core.login') $mmSitesManager.updateSiteInfoByUrl(infositeurl, username).finally(function() { delete $scope.credentials; // Delete password from the scope. $ionicHistory.nextViewOptions({disableBack: true}); - $state.go('site.mm_courses'); + return $mmLoginHelper.goToSiteInitialPage(); }); }, function(error) { // Site deleted? Go back to login page. diff --git a/www/core/components/login/controllers/site.js b/www/core/components/login/controllers/site.js index 0c9be55a4bd..d8ac374c28e 100644 --- a/www/core/components/login/controllers/site.js +++ b/www/core/components/login/controllers/site.js @@ -60,7 +60,7 @@ angular.module('mm.core.login') $mmSitesManager.getUserToken(sitedata.url, sitedata.username, sitedata.password).then(function(data) { $mmSitesManager.newSite(data.siteurl, data.token).then(function() { $ionicHistory.nextViewOptions({disableBack: true}); - $state.go('site.mm_courses'); + return $mmLoginHelper.goToSiteInitialPage(); }, function(error) { $mmUtil.showErrorModal(error); }).finally(function() { diff --git a/www/core/components/login/controllers/sites.js b/www/core/components/login/controllers/sites.js index 28cc32b17ec..8963559097d 100644 --- a/www/core/components/login/controllers/sites.js +++ b/www/core/components/login/controllers/sites.js @@ -68,7 +68,7 @@ angular.module('mm.core.login') $mmSitesManager.loadSite(siteid).then(function() { $ionicHistory.nextViewOptions({disableBack: true}); - $state.go('site.mm_courses'); + return $mmLoginHelper.goToSiteInitialPage(); }, function(error) { $log.error('Error loading site '+siteid); error = error || 'Error loading site.'; diff --git a/www/core/components/login/main.js b/www/core/components/login/main.js index 10c5bade654..8adb9ec619b 100644 --- a/www/core/components/login/main.js +++ b/www/core/components/login/main.js @@ -136,7 +136,7 @@ angular.module('mm.core.login', []) disableAnimate: true, disableBack: true }); - $state.transitionTo('site.mm_courses'); + $mmLoginHelper.goToSiteInitialPage(); } }); @@ -202,7 +202,7 @@ angular.module('mm.core.login', []) $mmLoginHelper.validateBrowserSSOLogin(url).then(function(sitedata) { $mmLoginHelper.handleSSOLoginAuthentication(sitedata.siteurl, sitedata.token).then(function() { - $state.go('site.mm_courses'); + return $mmLoginHelper.goToSiteInitialPage(); }, function(error) { $mmUtil.showErrorModal(error); }).finally(function() { diff --git a/www/core/components/login/services/helper.js b/www/core/components/login/services/helper.js index 6bb980765bc..1cd1c8ef826 100644 --- a/www/core/components/login/services/helper.js +++ b/www/core/components/login/services/helper.js @@ -26,7 +26,7 @@ angular.module('mm.core.login') * @name $mmLoginHelper */ .factory('$mmLoginHelper', function($q, $log, $mmConfig, mmLoginSSOCode, mmLoginLaunchSiteURL, mmLoginLaunchPassport, - md5, $mmSite, $mmSitesManager, $mmLang, $mmUtil, $state, mmCoreConfigConstants) { + md5, $mmSite, $mmSitesManager, $mmLang, $mmUtil, $state, $mmAddonManager, mmCoreConfigConstants) { $log = $log.getInstance('$mmLoginHelper'); @@ -50,6 +50,26 @@ angular.module('mm.core.login') } }; + /** + * Go to the initial page of a site depending on 'userhomepage' setting. + * + * @module mm.core.login + * @ngdoc method + * @name $mmLoginHelper#goToSiteInitialPage + * @return {Promise} Promise resolved when the state changes. + */ + self.goToSiteInitialPage = function() { + if ($mmSite.getInfo() && $mmSite.getInfo().userhomepage === 0) { + // Configured to go to Site Home. Check if plugin is installed in the app. + var $mmaFrontpage = $mmAddonManager.get('$mmaFrontpage'); + if ($mmaFrontpage) { + return $state.go('site.mm_course-section'); + } + } + + return $state.go('site.mm_courses'); + }; + /** * Check if the app is configured to use a fixed URL. *