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
1 change: 1 addition & 0 deletions www/addons/mod/wiki/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ angular.module('mm.addons.mod_wiki')
moduleid: module.id,
courseid: courseId,
pagetitle: page.title,
pageid: null,
wikiid: wiki.id,
subwikiid: page.subwikiid,
action: 'page'
Expand Down
2 changes: 1 addition & 1 deletion www/core/components/courses/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ angular.module('mm.core.courses')
if (message) {
$mmUtil.showErrorModal(message);
} else {
$mmUtil.showErrorModal('mma.searchcourses.errorsearching', true);
$mmUtil.showErrorModal('mm.courses.errorsearching', true);
}
return $q.reject();
});
Expand Down
6 changes: 3 additions & 3 deletions www/core/components/login/controllers/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ angular.module('mm.core.login')
});
};

$scope.login = function(siteid) {
$scope.login = function(siteId) {
var modal = $mmUtil.showModalLoading();

$mmSitesManager.loadSite(siteid).then(function() {
$mmSitesManager.loadSite(siteId).then(function() {
$ionicHistory.nextViewOptions({disableBack: true});
return $mmLoginHelper.goToSiteInitialPage();
}, function(error) {
$log.error('Error loading site '+siteid);
$log.error('Error loading site ' + siteId);
error = error || 'Error loading site.';
$mmUtil.showErrorModal(error);
}).finally(function() {
Expand Down
29 changes: 21 additions & 8 deletions www/core/components/login/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

angular.module('mm.core.login', [])

.constant('mmCoreLoginTokenChangePassword', '*changepassword*')

.config(function($stateProvider, $urlRouterProvider, $mmInitDelegateProvider, mmInitDelegateMaxAddonPriority) {

$stateProvider
Expand Down Expand Up @@ -96,11 +98,12 @@ angular.module('mm.core.login', [])

.run(function($log, $state, $mmUtil, $translate, $mmSitesManager, $rootScope, $mmSite, $mmURLDelegate, $ionicHistory, $timeout,
$mmEvents, $mmLoginHelper, mmCoreEventSessionExpired, $mmApp, $ionicPlatform, mmCoreConfigConstants,
mmCoreEventPasswordChangeForced) {
mmCoreEventPasswordChangeForced, mmCoreLoginTokenChangePassword) {

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

var isSSOConfirmShown,
var isSSOConfirmShown = false,
isChangePasswordConfirmShown = false,
waitingForBrowser = false;

// Listen for sessionExpired event to reconnect the user.
Expand Down Expand Up @@ -230,19 +233,29 @@ angular.module('mm.core.login', [])
}

// Expire user token for the site.
$mmSitesManager.updateSiteToken(siteUrl, site.infos.username, 'expired');
$log.debug('Expiring token for site ' + siteId);
$mmSitesManager.updateSiteTokenBySiteId(siteId, mmCoreLoginTokenChangePassword);

// Site that triggered the event is not current site.
if (siteId !== $mmSite.getId()) {
return;
}

// User password change forced, invalidate all site caches.
site.invalidateWsCache();
if (!isChangePasswordConfirmShown && !waitingForBrowser) {
isChangePasswordConfirmShown = true;

// User password change forced, invalidate all site caches.
site.invalidateWsCache();

$mmEvents.trigger(mmCoreEventSessionExpired, siteId);
// Session expired, trigger event.
$mmUtil.openChangePassword(siteUrl, $translate.instant('mm.core.nopasswordchangeforced'));
$mmEvents.trigger(mmCoreEventSessionExpired, siteId);

// Session expired, trigger event.
$mmLoginHelper.openChangePassword(siteUrl, $translate.instant('mm.core.nopasswordchangeforced')).then(function() {
waitingForBrowser = true;
}).finally(function() {
isChangePasswordConfirmShown = false;
});
}
});

}
Expand Down
20 changes: 19 additions & 1 deletion www/core/components/login/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,29 @@ angular.module('mm.core.login')
if (typeof error == 'string') {
$mmUtil.showErrorModal(error);
} else if (error.errorcode == 'forcepasswordchangenotice') {
$mmUtil.openChangePassword(siteurl, error.error);
self.openChangePassword(siteurl, error.error);
} else {
$mmUtil.showErrorModal(error.error);
}
};

/**
* Convenient helper to open change password page.
*
* @module mm.core.login
* @ngdoc method
* @name $mmLoginHelper#openChangePassword
* @param {String} siteurl Site URL to construct change password URL.
* @param {String} error Error message.
*/
self.openChangePassword = function(siteurl, error) {
var message = error + "<br>" + $translate.instant('mm.login.visitchangepassword');
return $mmUtil.showConfirm(message, $translate.instant('mm.core.notice')).then(function() {
var changepasswordurl = siteurl + "/login/change_password.php";
$mmUtil.openInApp(changepasswordurl);
return $q.when();
});
};

return self;
});
7 changes: 7 additions & 0 deletions www/core/components/question/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ li.mm-question-answer-correct,
.mm-question-comment,
.mm-question-comment p {
color: $mm-question-correct-color;
-webkit-text-fill-color: $mm-question-correct-color; /* Override iOS / Android font color change */
background-color: #dff0d8;
}

Expand All @@ -53,6 +54,7 @@ li.mm-question-answer-incorrect,
.mm-question-incorrect,
.mm-question-incorrect p {
color: $mm-question-incorrect-color;
-webkit-text-fill-color: $mm-question-incorrect-color; /* Override iOS / Android font color change */
background-color: #f2dede;
}

Expand All @@ -62,6 +64,11 @@ li.mm-question-answer-incorrect,
border-color: $mm-question-incorrect-color;
}

.mm-question-answer-correct input:disabled,
.mm-question-answer-incorrect input:disabled {
opacity: 1;
}

.mm-question-feedback-container {
background-color: #fcf8e3;
color: #8a6d3b;
Expand Down
6 changes: 4 additions & 2 deletions www/core/directives/richtexteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,16 @@ angular.module('mm.core')
editorHeightWithoutResize = editorInitialHeight + toolbarHeight,
contentVisibleHeight,
editorContentNewHeight,
screenSmallerThanEditor;
screenSmallerThanEditor,
editorMaximized;

if (typeof fixedBarsHeight == 'undefined') {
fixedBarsHeight = calculateFixedBarsHeight(editorEl);
}

editorMaximized = !!editorEl.querySelector('.cke_maximized');
contentVisibleHeight = $window.innerHeight - fixedBarsHeight;
screenSmallerThanEditor = contentVisibleHeight > 0 && contentVisibleHeight < editorHeightWithoutResize;
screenSmallerThanEditor = !editorMaximized && contentVisibleHeight > 0 && contentVisibleHeight < editorHeightWithoutResize;
editorContentNewHeight = contentVisibleHeight - toolbarHeight;

if (resized && !screenSmallerThanEditor) {
Expand Down
19 changes: 18 additions & 1 deletion www/core/lib/sitesfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ angular.module('mm.core')

this.$get = function($http, $q, $mmWS, $mmDB, $log, md5, $mmApp, $mmLang, $mmUtil, $mmFS, mmCoreWSCacheStore,
mmCoreWSPrefix, mmCoreSessionExpired, $mmEvents, mmCoreEventSessionExpired, mmCoreUserDeleted, mmCoreEventUserDeleted,
$mmText, $translate, mmCoreConfigConstants, mmCoreUserPasswordChangeForced, mmCoreEventPasswordChangeForced) {
$mmText, $translate, mmCoreConfigConstants, mmCoreUserPasswordChangeForced, mmCoreEventPasswordChangeForced,
mmCoreLoginTokenChangePassword) {

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

Expand Down Expand Up @@ -254,6 +255,15 @@ angular.module('mm.core')
this.token = token;
};

/**
* Check if token is already expired using local data.
*
* @return {Boolean} is token is expired or not.
*/
Site.prototype.isTokenExpired = function() {
return this.token == mmCoreLoginTokenChangePassword;
};

/**
* Set site info.
*
Expand Down Expand Up @@ -425,6 +435,13 @@ angular.module('mm.core')
initialToken = site.token;
data = data || {};

// Prevent calls with expired tokens.
if (site.isTokenExpired()) {
$log.debug('Token expired, rejecting.');
$mmEvents.trigger(mmCoreEventSessionExpired, site.id);
return $mmLang.translateAndReject('mm.login.reconnectdescription');
}

// Get the method to use based on the available ones.
method = site.getCompatibleFunction(method);

Expand Down
48 changes: 34 additions & 14 deletions www/core/lib/sitesmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ angular.module('mm.core')
}
return $mmLang.translateAndReject('mm.login.checksiteversion');
});
});;
});
}
};

Expand Down Expand Up @@ -159,7 +159,7 @@ angular.module('mm.core')
return {siteurl: siteurl, code: data.code, warning: data.warning};
});
});
};
}

/**
* Check if a site exists.
Expand Down Expand Up @@ -410,23 +410,29 @@ angular.module('mm.core')
* @module mm.core
* @ngdoc method
* @name $mmSitesManager#loadSite
* @param {String} siteid ID of the site to load.
* @param {String} siteId ID of the site to load.
* @return {Promise} Promise to be resolved when the site is loaded.
*/
self.loadSite = function(siteid) {
$log.debug('Load site '+siteid);
self.loadSite = function(siteId) {
$log.debug('Load site ' + siteId);

return self.getSite(siteid).then(function(site) {
return self.getSite(siteId).then(function(site) {
currentSite = site;
self.login(siteid);
self.login(siteId);

if (site.isTokenExpired()) {
$log.debug('Token expired, rejecting.');
$mmEvents.trigger(mmCoreEventSessionExpired, siteId);
return $mmLang.translateAndReject('mm.login.reconnectdescription');
}

// Check if local_mobile was installed to Moodle.
return site.checkIfLocalMobileInstalledAndNotUsed().then(function() {
// Local mobile was added. Throw invalid session to force reconnect and create a new token.
$mmEvents.trigger(mmCoreEventSessionExpired, siteid);
$mmEvents.trigger(mmCoreEventSessionExpired, siteId);
}, function() {
// Update site info. We don't block the UI.
self.updateSiteInfo(siteid).finally(function() {
self.updateSiteInfo(siteId).finally(function() {
var infos = site.getInfo(),
validation = validateSiteInfo(infos);
if (validation !== true) {
Expand Down Expand Up @@ -670,18 +676,32 @@ angular.module('mm.core')
* @module mm.core
* @ngdoc method
* @name $mmSitesManager#updateSiteToken
* @param {String} siteurl Site's URL.
* @param {String} siteUrl Site's URL.
* @param {String} username Username.
* @param {String} token User's new token.
* @return {Promise} A promise to be resolved when the site is updated.
*/
self.updateSiteToken = function(siteurl, username, token) {
var siteid = self.createSiteID(siteurl, username);
return self.getSite(siteid).then(function(site) {
self.updateSiteToken = function(siteUrl, username, token) {
var siteId = self.createSiteID(siteUrl, username);
return self.updateSiteTokenBySiteId(siteId, token);
};

/**
* Updates a site's token usign siteId.
*
* @module mm.core
* @ngdoc method
* @name $mmSitesManager#updateSiteTokenBySiteId
* @param {String} siteId Site Id.
* @param {String} token User's new token.
* @return {Promise} A promise to be resolved when the site is updated.
*/
self.updateSiteTokenBySiteId = function(siteId, token) {
return self.getSite(siteId).then(function(site) {
site.token = token;

return $mmApp.getDB().insert(mmCoreSitesStore, {
id: siteid,
id: siteId,
siteurl: site.getURL(),
token: token,
infos: site.getInfo()
Expand Down
17 changes: 0 additions & 17 deletions www/core/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,23 +1652,6 @@ angular.module('mm.core')
return error && localErrors.indexOf(error) == -1;
};

/**
* Convenient helper to open change password page.
*
* @module mm.core
* @ngdoc method
* @name $mmUtil#openChangePassword
* @param {String} siteurl Site URL to construct change password URL.
* @param {String} error Error message.
*/
self.openChangePassword = function(siteurl, error) {
var message = error + "<br>" + $translate.instant('mm.login.visitchangepassword');
self.showConfirm(message, $translate.instant('mm.core.notice')).then(function() {
var changepasswordurl = siteurl + "/login/change_password.php";
self.openInApp(changepasswordurl);
});
};

/**
* Focus an element and open keyboard.
*
Expand Down
1 change: 1 addition & 0 deletions www/core/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ mm-format-text {
border-bottom: 1px solid #ddd;
margin-bottom: 10px;
padding: 5px;
background-color: white;

input {
font-size: 20px;
Expand Down