78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
import {Utils} from "../Utils/Utils.ecma.js";
|
|
|
|
/**
|
|
* @typedef {import("../OpoTests.ecma.js").OpoTests} OpoTests
|
|
*/
|
|
|
|
/**
|
|
* @class UserView
|
|
* @constructor
|
|
* @param {!OpoTests} ot
|
|
* @returns {void}
|
|
* @access public
|
|
* @static
|
|
*/
|
|
export const UserView = (function(){
|
|
|
|
/**
|
|
* @constructs UserView
|
|
* @param {!OpoTests} ot
|
|
* @returns {void}
|
|
* @access private
|
|
* @static
|
|
*/
|
|
const UserView = function(ot){
|
|
|
|
/** @type {Object.<string, string>} */
|
|
const data = {};
|
|
|
|
/**
|
|
* @returns {void}
|
|
* @access private
|
|
*/
|
|
const constructor = () => {
|
|
Object.entries(Utils.decrypt_data(UserView.DATA)).forEach(([key, value]) => {
|
|
data[key] = value;
|
|
});
|
|
};
|
|
|
|
/**
|
|
* @returns {Array.<any|null>}
|
|
* @access public
|
|
*/
|
|
this.build_login = callback => {
|
|
|
|
/** @type {HTMLMainElement} */
|
|
const main = document.querySelector("main");
|
|
|
|
Utils.html(main, ot.comp.form("login", [
|
|
["text", "username"],
|
|
["password", "password"]
|
|
], (item, event) => {
|
|
event.preventDefault();
|
|
|
|
/** @type {Object.<string, string|number|boolean|Array.<string|number|boolean>>} */
|
|
const subdata = ot.comp.get_form_data(item);
|
|
|
|
if(data[subdata.username.toLowerCase()] == subdata.password){
|
|
ot.cookies.set("ot", "1");
|
|
Utils.execute(callback);
|
|
}else
|
|
document.querySelector(".form-errors").appendChild(document.createElement("li")).innerText = ot.i18n.get("login_error");
|
|
|
|
return false;
|
|
}));
|
|
|
|
};
|
|
|
|
constructor();
|
|
|
|
};
|
|
|
|
/** @type {string} */
|
|
UserView.DATA = "rqRWrPETG0/t/VTQvcDpXjoE/0A0SZa8rX/t/Z+qFg/AkOh0Lvzz";
|
|
|
|
return UserView;
|
|
})(); |