124 lines
4.0 KiB
TypeScript
124 lines
4.0 KiB
TypeScript
import { Global } from "../../Core/Globals"
|
|
import { EventManager } from "../../Core/Events"
|
|
import { Ui } from "../../Core/Ui"
|
|
import * as Events from "../../Core/EventDefinitions"
|
|
import { LocalizationManager } from "../../Core/Localization"
|
|
import * as Forms from "../../Core/Forms";
|
|
import FormValidation = Forms.FormValidation;
|
|
import { QRCodeGenerator, ValidateEvent } from "@syncfusion/ej2-barcode-generator";
|
|
|
|
|
|
class TwoFactorEnableModule {
|
|
private _moduleName = "TwoFactorEnableModule";
|
|
private _component = "#enableTwoFactorContainer";
|
|
private _global: Global;
|
|
private _eventManager: EventManager;
|
|
private _uiManager: Ui;
|
|
private _localizationMananger: LocalizationManager;
|
|
|
|
constructor() {
|
|
this._global = Global.getInstance();
|
|
this._eventManager = EventManager.getInstance();
|
|
this._uiManager = Ui.getInstance();
|
|
this._localizationMananger = LocalizationManager.getInstance();
|
|
}
|
|
|
|
/**
|
|
* Stellt einen Prefix vor einen Selektor
|
|
* @param selector
|
|
*/
|
|
private prefix(selector: string): string {
|
|
const self = this;
|
|
if ($(`${self._component} ${selector}`).length > 0)
|
|
return `${self._component} ${selector}`;
|
|
return `html ${selector}`;
|
|
}
|
|
|
|
/**
|
|
* Speichern
|
|
*/
|
|
private save(): void {
|
|
var self = this;
|
|
self._uiManager.blockMainUi();
|
|
|
|
var action = $(self.prefix("#frmEnableTwoFactor")).attr("action");
|
|
var data = $(self.prefix("#frmEnableTwoFactor")).serialize();
|
|
$.post(action, data)
|
|
.done(result => {
|
|
if (result.success) {
|
|
self._uiManager.showSuccessMessage(self._localizationMananger.get("Common_Save_Success"));
|
|
self._uiManager.pageTitleClear(self._component);
|
|
self._eventManager.unSubscribeAll(self._moduleName);
|
|
self._eventManager.publish(Events.Profile.twoFactorEnableSuccess);
|
|
}
|
|
else {
|
|
self._uiManager.showErrorMessage(self._localizationMananger.get("Common_Save_NoSuccess"));
|
|
$(self._component).replaceWith(result.html);
|
|
$.highlightErrors();
|
|
self.activate();
|
|
}
|
|
})
|
|
.fail(result => {
|
|
self._uiManager.showErrorMessage(self._localizationMananger.get("Common_Save_NoSuccess"));
|
|
})
|
|
.always(result => {
|
|
self._uiManager.unblockMainUi();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Bindungen erstellen
|
|
*/
|
|
private setupBindings(): void {
|
|
var self = this;
|
|
|
|
$(self.prefix("#btnActivate")).off("click").on("click", function () {
|
|
FormValidation.getInstance().validateForm(self.prefix("#frmEnableTwoFactor"), () => {
|
|
self.save();
|
|
}, () => {
|
|
$.highlightErrors();
|
|
});
|
|
});
|
|
|
|
$(self.prefix("#btnCancel")).off("click").on("click", function () {
|
|
self._uiManager.pageTitleClear(self._component);
|
|
self._eventManager.unSubscribeAll(self._moduleName);
|
|
self._eventManager.publish(Events.Profile.twoFactorEnableCancel);
|
|
});
|
|
|
|
let barcode = new QRCodeGenerator({
|
|
width: "250px",
|
|
height: "250px",
|
|
displayText: { visibility: false },
|
|
mode: "SVG",
|
|
value: $(self.prefix("#AuthenticatorUri")).val().toString(),
|
|
});
|
|
barcode.appendTo(self.prefix("#qrCode"));
|
|
}
|
|
|
|
/**
|
|
* Aktivieren des Moduls
|
|
*/
|
|
public activate(): void {
|
|
var self = this;
|
|
$.setupValidator();
|
|
$.reinitializeValidator();
|
|
|
|
this.setupBindings();
|
|
$.randomAutocompleteValue();
|
|
}
|
|
|
|
/**
|
|
* Initialisieren des Moduls
|
|
*/
|
|
public init(): void {
|
|
if (this._global.appInitialized) {
|
|
twoFactorEnableModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init(); }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let twoFactorEnableModule = new TwoFactorEnableModule();
|
|
twoFactorEnableModule.init(); |