/* * Copyright (c) 2010, 2026 BSI Business Systems Integration AG * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 */ import {AjaxSettings, Box, Device, InitModelOf, LoginAppModel, strings, TextMap} from '../index'; import $ from 'jquery'; export class LoginBox extends Box { declare model: LoginAppModel; ajaxOptions: AjaxSettings; authUrl: string; onPostDoneFunc: (data: Record) => void; redirectUrl: string; userDataKey: string; passwordDataKey: string; tokenDataKey: string; additionalData: Record; prepareRedirectUrlFunc: (url: string) => string; messageKey: string; texts: TextMap; $message: JQuery; $form: JQuery; $user: JQuery; $password: JQuery; $token: JQuery; $button: JQuery; constructor() { super(); this.ajaxOptions = { method: 'POST' }; this.authUrl = 'auth'; this.onPostDoneFunc = this.checkTwoFactorResponse.bind(this); this.redirectUrl = null; this.logoUrl = 'logo.png'; this.userDataKey = 'user'; this.passwordDataKey = 'password'; this.tokenDataKey = 'token'; this.additionalData = {}; this.prepareRedirectUrlFunc = LoginBox.prepareRedirectUrl; this.messageKey = null; this.texts = null; this.$message = null; this.$form = null; this.$user = null; this.$password = null; this.$token = null; this.$button = null; } init(options: InitModelOf) { options = options || {} as InitModelOf; let allTexts = $.extend({ 'ui.Login': 'Login', 'ui.LoginFailed': 'Login failed', 'ui.User': 'Username', 'ui.Password': 'Password', 'ui.Token': 'Token' }, options.texts); delete options.texts; options.ajaxOptions = $.extend(this.ajaxOptions, options.ajaxOptions); $.extend(this, options); this.texts = new TextMap(allTexts); } protected override _render() { super._render(); this.$container.addClass('login-box'); this.$content.addClass('login-box-content '); this.$form = $('
') .attr('action', this.authUrl) .attr('method', 'post') .on('submit', this._onLoginFormSubmit.bind(this)) .appendTo(this.$content); if (this.messageKey) { this.$message = $('
') .attr('id', 'message-box') .addClass('message-box') .html(strings.nl2br(this.texts.get(this.messageKey))) .appendTo(this.$form); } const userText = this.texts.get('ui.User'); this.$user = $('') .attr('type', 'text') .attr('autocomplete', 'username') .attr('autocapitalize', 'off') .attr('autocorrect', 'off') .attr('spellcheck', 'false') .attr('aria-label', userText) .placeholder(userText) .appendTo(this.$form); this.$password = this._createPasswortField() .appendTo(this.$form); this.$button = $('