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> <h4 class="txtConfirm"></h4>
</div> </div>
</div> </div>
<script src="js/sweetalert2.js"></script>
<script src="config.js" type="text/javascript"></script> <script src="config.js" type="text/javascript"></script>
<script src="js/main.js" type="text/javascript"></script> <script src="js/main.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script> <script src="js/index.js" type="text/javascript"></script>

View File

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

View File

@ -1,5 +1,7 @@
var pin = ""; var pin = "";
var datoUsuario = ""; var datoUsuario = "";
var user = "";
var pass = "";
$(document).ready(function () { $(document).ready(function () {
FastClick.attach(document.body); FastClick.attach(document.body);
@ -9,9 +11,25 @@ $(document).ready(function () {
function setEvents() { function setEvents() {
const heartEl = document.querySelector('body > h1 > span'); const heartEl = document.querySelector('body > h1 > span');
heartEl.addEventListener('click', function() { heartEl.addEventListener('click', function() {
const key = prompt('Introduce la clave'); Swal.fire({
if (key === null) return title: 'Iniciar sesión',
localStorage.setItem('vnKey', key); 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 () { $(".btnnum").on("click", function () {
@ -36,8 +54,8 @@ function setEvents() {
function login() { function login() {
$.post({ $.post({
urlPath: 'login', urlPath: 'WorkerTimeControls/login',
jsonData: [pin], jsonData: {pin},
processData: false, processData: false,
success: function (data) { success: function (data) {
localStorage.setItem("userData", JSON.stringify(data)); localStorage.setItem("userData", JSON.stringify(data));
@ -48,5 +66,16 @@ function login() {
pin = ""; 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) { $.ajaxPrefilter(function(xhr) {
var orgErrorHandler = xhr.error; var orgErrorHandler = xhr.error;
var token = localStorage.getItem('token')
var key = localStorage.getItem('vnKey');
if (key) {
xhr.jsonData.push(key)
}
Object.assign(xhr, { Object.assign(xhr, {
url: `api/WorkerTimeControls/${xhr.urlPath}`, url: `api/${xhr.urlPath}`,
headers: { headers: {
//Authorization : token Authorization : token
}, },
timeout: 1000, timeout: 1000,
contentType: 'application/json; charset=utf-8', 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", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"fastclick": "^1.0.6", "fastclick": "^1.0.6",
"jquery": "^3.7.0", "jquery": "^3.7.0"
"sweetalert2": "^11.6.13"
}, },
"devDependencies": { "devDependencies": {
"express": "^4.18.2", "express": "^4.18.2",
@ -865,15 +864,6 @@
"node": ">= 0.8" "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": { "node_modules/to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",

View File

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