Skip to content

Commit d6ab4a0

Browse files
committed
MOBILE-1806 autologin: Prevent consecutive calls to get autologin key WS
1 parent 0f6c3d1 commit d6ab4a0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

www/core/lib/sitesfactory.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ angular.module('mm.core')
118118
this.$get = function($http, $q, $mmWS, $mmDB, $log, md5, $mmApp, $mmLang, $mmUtil, $mmFS, mmCoreWSCacheStore,
119119
mmCoreWSPrefix, mmCoreSessionExpired, $mmEvents, mmCoreEventSessionExpired, mmCoreUserDeleted, mmCoreEventUserDeleted,
120120
$mmText, $translate, mmCoreConfigConstants, mmCoreUserPasswordChangeForced, mmCoreEventPasswordChangeForced,
121-
mmCoreLoginTokenChangePassword) {
121+
mmCoreLoginTokenChangePassword, mmCoreSecondsMinute) {
122122

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

@@ -907,26 +907,31 @@ angular.module('mm.core')
907907
* @return {Promise} Promise resolved when done, rejected otherwise.
908908
*/
909909
Site.prototype.openWithAutoLogin = function(inApp, url, options) {
910-
if (!this.privateToken || !this.wsAvailable('tool_mobile_get_autologin_key')) {
911-
// No private token or WS not available, open the final URL without auto-login.
910+
if (!this.privateToken || !this.wsAvailable('tool_mobile_get_autologin_key') ||
911+
(this.lastAutoLogin && $mmUtil.timestamp() - this.lastAutoLogin < 6 * mmCoreSecondsMinute)) {
912+
// No private token, WS not available or last auto-login was less than 6 minutes ago.
913+
// Open the final URL without auto-login.
912914
open(url);
913915
return $q.when();
914916
}
915917

916-
var userId = this.getUserId(),
918+
var that = this,
919+
userId = that.getUserId(),
917920
params = {
918-
privatetoken: this.privateToken
921+
privatetoken: that.privateToken
919922
},
920923
modal = $mmUtil.showModalLoading();
921924

922925
// Use write to not use cache.
923-
return this.write('tool_mobile_get_autologin_key', params).then(function(data) {
926+
return that.write('tool_mobile_get_autologin_key', params).then(function(data) {
924927
if (!data.autologinurl || !data.key) {
925928
// Not valid data, open the final URL without auto-login.
926929
open(url);
927930
return;
928931
}
929932

933+
that.lastAutoLogin = $mmUtil.timestamp();
934+
930935
open(data.autologinurl + '?userid=' + userId + '&key=' + data.key + '&urltogo=' + url);
931936
}).catch(function() {
932937
// Couldn't get autologin key, open the final URL without auto-login.

0 commit comments

Comments
 (0)