refs #6274 login modal, salix requests & proxy
gitea/worker-time-control/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2023-11-28 14:50:11 +01:00
parent 388fc57404
commit 4566368d10
7 changed files with 58 additions and 31 deletions

View File

@ -88,6 +88,7 @@ and open the template in the editor.
<h4 class="txtConfirm"></h4>
</div>
</div>
<script src="js/sweetalert2.js"></script>
<script src="config.js" type="text/javascript"></script>
<script src="js/main.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>

View File

@ -1,7 +1,7 @@
var userData = "";
$(document).ready(function () {
userData = $.parseJSON(localStorage.getItem("userData"));
userData = JSON.parse(localStorage.getItem("userData"));
FastClick.attach(document.body);
setView();
setEvents();
@ -43,9 +43,14 @@ function setView() {
}
function fichar(direction) {
const data = {
workerFk: userData['userFk'],
direction
}
$.post({
urlPath: 'clockIn',
jsonData: [userData['userFk'], direction],
urlPath: 'WorkerTimeControls/clockIn',
jsonData: data,
processData: false,
success: function (msg) {
if (msg[0].error){
@ -81,9 +86,10 @@ function setView() {
}
function getInfo() {
$.post({
urlPath: 'getClockIn',
jsonData: [userData['userFk']],
const queryString = $.param({ workerFk: userData['userFk'] });
$.get({
urlPath: `WorkerTimeControls/getClockIn?${queryString}`,
processData: false,
success: function (data) {
$('.footer').show();

View File

@ -1,5 +1,7 @@
var pin = "";
var datoUsuario = "";
var user = "";
var pass = "";
$(document).ready(function () {
FastClick.attach(document.body);
@ -9,9 +11,25 @@ $(document).ready(function () {
function setEvents() {
const heartEl = document.querySelector('body > h1 > span');
heartEl.addEventListener('click', function() {
const key = prompt('Introduce la clave');
if (key === null) return
localStorage.setItem('vnKey', key);
Swal.fire({
title: 'Iniciar sesión',
html:
'<input id="user" class="swal2-input" placeholder="Usuario">' +
'<input id="pass" class="swal2-input" type="password" placeholder="Contraseña">',
confirmButtonText: 'Login',
showCloseButton: true,
showCancelButton: false,
}).then(async (result) => {
if(result.isConfirmed) {
const user =$('#user').val();
const pass = $('#pass').val();
signIn(user,pass);
}
});
let token;
if (token === null) return
localStorage.setItem('token', token);
});
$(".btnnum").on("click", function () {
@ -36,8 +54,8 @@ function setEvents() {
function login() {
$.post({
urlPath: 'login',
jsonData: [pin],
urlPath: 'WorkerTimeControls/login',
jsonData: {pin},
processData: false,
success: function (data) {
localStorage.setItem("userData", JSON.stringify(data));
@ -48,5 +66,16 @@ function login() {
pin = "";
}
});
}
function signIn(user, password) {
$.post({
urlPath: 'vnUsers/sign-in',
jsonData: {user, password},
processData: false,
success: function (data) {
localStorage.setItem("token", data.token);
localStorage.setItem("ttl", data.ttl);
},
})
}

View File

@ -16,16 +16,12 @@ function printError(msg){
$.ajaxPrefilter(function(xhr) {
var orgErrorHandler = xhr.error;
var key = localStorage.getItem('vnKey');
if (key) {
xhr.jsonData.push(key)
}
var token = localStorage.getItem('token')
Object.assign(xhr, {
url: `api/WorkerTimeControls/${xhr.urlPath}`,
url: `api/${xhr.urlPath}`,
headers: {
//Authorization : token
Authorization : token
},
timeout: 1000,
contentType: 'application/json; charset=utf-8',

6
js/sweetalert2.js Normal file

File diff suppressed because one or more lines are too long

12
package-lock.json generated
View File

@ -10,8 +10,7 @@
"license": "GPL-3.0",
"dependencies": {
"fastclick": "^1.0.6",
"jquery": "^3.7.0",
"sweetalert2": "^11.6.13"
"jquery": "^3.7.0"
},
"devDependencies": {
"express": "^4.18.2",
@ -865,15 +864,6 @@
"node": ">= 0.8"
}
},
"node_modules/sweetalert2": {
"version": "11.10.1",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.10.1.tgz",
"integrity": "sha512-qu145oBuFfjYr5yZW9OSdG6YmRxDf8CnkgT/sXMfrXGe+asFy2imC2vlaLQ/L/naZ/JZna1MPAY56G4qYM0VUQ==",
"funding": {
"type": "individual",
"url": "https://github.com/sponsors/limonte"
}
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",

View File

@ -17,8 +17,7 @@
},
"dependencies": {
"fastclick": "^1.0.6",
"jquery": "^3.7.0",
"sweetalert2": "^11.6.13"
"jquery": "^3.7.0"
},
"devDependencies": {
"express": "^4.18.2",