Merge pull request #4233 from dpalou/MOBILE-4679
MOBILE-4679 dev: Display auto login info and part of tokens in dev pagemain
commit
1afe19639c
|
@ -378,7 +378,7 @@ export class CoreSite extends CoreAuthenticatedSite {
|
|||
*/
|
||||
fixPluginfileURL(url: string): string {
|
||||
const accessKey = this.tokenPluginFileWorks || this.tokenPluginFileWorks === undefined ?
|
||||
this.infos && this.infos.userprivateaccesskey : undefined;
|
||||
this.getFilesAccessKey() : undefined;
|
||||
|
||||
return CoreUrl.fixPluginfileURL(url, this.token || '', this.siteUrl, accessKey);
|
||||
}
|
||||
|
@ -685,12 +685,9 @@ export class CoreSite extends CoreAuthenticatedSite {
|
|||
}
|
||||
|
||||
if (this.lastAutoLogin > 0) {
|
||||
const timeBetweenRequests = await CoreUtils.ignoreErrors(
|
||||
this.getConfig('tool_mobile_autologinmintimebetweenreq'),
|
||||
CoreConstants.SECONDS_MINUTE * 6,
|
||||
);
|
||||
const timeBetweenRequests = await this.getAutoLoginMinTimeBetweenRequests();
|
||||
|
||||
if (CoreTimeUtils.timestamp() - this.lastAutoLogin < Number(timeBetweenRequests)) {
|
||||
if (CoreTimeUtils.timestamp() - this.lastAutoLogin < timeBetweenRequests) {
|
||||
// Not enough time has passed since last auto login.
|
||||
return url;
|
||||
}
|
||||
|
@ -775,7 +772,7 @@ export class CoreSite extends CoreAuthenticatedSite {
|
|||
* @returns Promise resolved with boolean: whether it works or not.
|
||||
*/
|
||||
checkTokenPluginFile(url: string): Promise<boolean> {
|
||||
if (!CoreUrl.canUseTokenPluginFile(url, this.siteUrl, this.infos && this.infos.userprivateaccesskey)) {
|
||||
if (!CoreUrl.canUseTokenPluginFile(url, this.siteUrl, this.getFilesAccessKey())) {
|
||||
// Cannot use tokenpluginfile.
|
||||
return Promise.resolve(false);
|
||||
} else if (this.tokenPluginFileWorks !== undefined) {
|
||||
|
@ -872,6 +869,39 @@ export class CoreSite extends CoreAuthenticatedSite {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the access key to use to fetch files.
|
||||
*
|
||||
* @returns Access key.
|
||||
*/
|
||||
getFilesAccessKey(): string | undefined {
|
||||
return this.infos?.userprivateaccesskey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get auto-login time between requests.
|
||||
*
|
||||
* @returns Time between requests.
|
||||
*/
|
||||
async getAutoLoginMinTimeBetweenRequests(): Promise<number> {
|
||||
const timeBetweenRequests = await CoreUtils.ignoreErrors(
|
||||
this.getConfig('tool_mobile_autologinmintimebetweenreq'),
|
||||
CoreConstants.SECONDS_MINUTE * 6,
|
||||
);
|
||||
|
||||
return Number(timeBetweenRequests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last auto login time.
|
||||
* This time is stored in memory, so restarting the app will reset it.
|
||||
*
|
||||
* @returns Last auto login time.
|
||||
*/
|
||||
getLastAutoLoginTime(): number {
|
||||
return this.lastAutoLogin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,6 +88,53 @@
|
|||
</ion-item>
|
||||
|
||||
<ng-container *ngIf="siteId">
|
||||
<ion-item class="ion-text-wrap">
|
||||
<ion-label>
|
||||
<p class="item-heading">WebService token</p>
|
||||
<p>{{ token }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap">
|
||||
<ion-label>
|
||||
<p class="item-heading">Private token</p>
|
||||
@if (privateToken) {
|
||||
<p>{{ privateToken }}</p>
|
||||
} @else {
|
||||
<p>---</p>
|
||||
}
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap">
|
||||
<ion-label>
|
||||
<p class="item-heading">Files access key</p>
|
||||
@if (filesAccessKey) {
|
||||
<p>{{ filesAccessKey }}</p>
|
||||
} @else {
|
||||
<p>---</p>
|
||||
}
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
@if (privateToken) {
|
||||
<ion-item class="ion-text-wrap" *ngIf="autoLoginTimeBetweenRequests">
|
||||
<ion-label>
|
||||
<p class="item-heading">Minimum time between auto-login requests</p>
|
||||
<p>{{ autoLoginTimeBetweenRequests | coreDuration }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap">
|
||||
<ion-label>
|
||||
<p class="item-heading">Last auto login in this device</p>
|
||||
@if (lastAutoLoginTime && lastAutoLoginTime > 0) {
|
||||
<p>{{ lastAutoLoginTime | coreTimeAgo }}</p>
|
||||
<ion-note class="core-text-sm">This value will reset when the app is restarted.</ion-note>
|
||||
} @else {
|
||||
<p>---</p>
|
||||
}
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
}
|
||||
|
||||
<ion-item-divider>
|
||||
<ion-label>
|
||||
<h2>Disabled features</h2>
|
||||
|
|
|
@ -62,6 +62,13 @@ export class CoreSettingsDevPage implements OnInit {
|
|||
|
||||
siteId: string | undefined;
|
||||
|
||||
token?: string;
|
||||
privateToken?: string;
|
||||
filesAccessKey?: string;
|
||||
|
||||
autoLoginTimeBetweenRequests?: number;
|
||||
lastAutoLoginTime?: number;
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.rtl = CorePlatform.isRTL;
|
||||
this.RTLChanged();
|
||||
|
@ -69,7 +76,8 @@ export class CoreSettingsDevPage implements OnInit {
|
|||
this.forceSafeAreaMargins = document.documentElement.classList.contains('force-safe-area-margins');
|
||||
this.safeAreaChanged();
|
||||
|
||||
this.siteId = CoreSites.getCurrentSite()?.getId();
|
||||
const currentSite = CoreSites.getCurrentSite();
|
||||
this.siteId = currentSite?.getId();
|
||||
|
||||
this.stagingSitesCount = CoreConstants.CONFIG.sites.filter((site) => site.staging).length;
|
||||
|
||||
|
@ -79,7 +87,7 @@ export class CoreSettingsDevPage implements OnInit {
|
|||
}
|
||||
this.alwaysShowLoginForm = Boolean(await CoreConfig.get(ALWAYS_SHOW_LOGIN_FORM, 0));
|
||||
|
||||
if (!this.siteId) {
|
||||
if (!currentSite) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -91,6 +99,15 @@ export class CoreSettingsDevPage implements OnInit {
|
|||
|
||||
this.userToursEnabled = !CoreUserTours.isDisabled();
|
||||
|
||||
const privateToken = currentSite.getPrivateToken();
|
||||
const filesAccessKey = currentSite.getFilesAccessKey();
|
||||
this.token = '...' + currentSite.getToken().slice(-3);
|
||||
this.privateToken = privateToken && ('...' + privateToken.slice(-3));
|
||||
this.filesAccessKey = filesAccessKey && ('...' + filesAccessKey.slice(-3));
|
||||
|
||||
this.autoLoginTimeBetweenRequests = await currentSite.getAutoLoginMinTimeBetweenRequests();
|
||||
this.lastAutoLoginTime = currentSite.getLastAutoLoginTime();
|
||||
|
||||
document.head.querySelectorAll('style').forEach((style) => {
|
||||
if (this.siteId && style.id.endsWith(this.siteId)) {
|
||||
if (style.innerHTML.length > 0) {
|
||||
|
@ -113,7 +130,7 @@ export class CoreSettingsDevPage implements OnInit {
|
|||
version: plugin.version,
|
||||
}));
|
||||
|
||||
const disabledFeatures = (await CoreSites.getCurrentSite()?.getPublicConfig())?.tool_mobile_disabledfeatures;
|
||||
const disabledFeatures = (await currentSite.getPublicConfig())?.tool_mobile_disabledfeatures;
|
||||
|
||||
this.disabledFeatures = disabledFeatures?.split(',').filter(feature => feature.trim().length > 0) ?? [];
|
||||
}
|
||||
|
@ -183,7 +200,12 @@ export class CoreSettingsDevPage implements OnInit {
|
|||
* Copies site info.
|
||||
*/
|
||||
copyInfo(): void {
|
||||
CoreText.copyToClipboard(JSON.stringify({ disabledFeatures: this.disabledFeatures, sitePlugins: this.sitePlugins }));
|
||||
CoreText.copyToClipboard(JSON.stringify({
|
||||
disabledFeatures: this.disabledFeatures,
|
||||
sitePlugins: this.sitePlugins,
|
||||
autoLoginTimeBetweenRequests: this.autoLoginTimeBetweenRequests,
|
||||
lastAutoLoginTime: this.lastAutoLoginTime,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,6 +42,16 @@ a {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.core-text-sm {
|
||||
font: var(--mdl-typography-body-font-sm);
|
||||
}
|
||||
.core-text-md {
|
||||
font: var(--mdl-typography-body-font-md);
|
||||
}
|
||||
.core-text-lg {
|
||||
font: var(--mdl-typography-body-font-lg);
|
||||
}
|
||||
|
||||
.img-responsive {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
|
|
Loading…
Reference in New Issue