mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-25 20:16:53 +01:00
-Remove old user login handling way
-Read/write theme use in pesistent way
This commit is contained in:
parent
7918379dff
commit
a3bef880a0
@ -9,11 +9,20 @@
|
||||
</template>
|
||||
<script>
|
||||
import themes from './js/stores/theme.js';
|
||||
import * as localForage from "localforage";
|
||||
|
||||
export default (props, { $f7, $update }) => {
|
||||
export default (props, { $f7, $, $update, $onMounted }) => {
|
||||
|
||||
let theme = themes.getters.Name.value;
|
||||
|
||||
$onMounted(() => {
|
||||
localForage.getItem('theme').then( (value) => {
|
||||
theme = value;
|
||||
if (value != 'theme-dark'){ $("#app").removeClass("theme-dark"); }
|
||||
themes.dispatch('changeTheme', theme);
|
||||
});
|
||||
});
|
||||
|
||||
return $render;
|
||||
}
|
||||
</script>
|
||||
|
@ -1,94 +0,0 @@
|
||||
import AjaxHandler from '../api/AjaxHandler.js';
|
||||
import endpoint from '../api/ConnectionMode.js';
|
||||
|
||||
let User = {
|
||||
async getLogin (userdata, password){
|
||||
try{
|
||||
let params = {
|
||||
method : "POST",
|
||||
url : `${endpoint}/user/login`,
|
||||
data : {
|
||||
UserData : userdata,
|
||||
UserPassword : password,
|
||||
},
|
||||
dataType : "json",
|
||||
}
|
||||
var ajax = new AjaxHandler();
|
||||
let result = await ajax.request(params);
|
||||
return result;
|
||||
}
|
||||
catch(err){
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
async checkLogin(user, pass){
|
||||
if (user === "" || pass === ""){
|
||||
throw new Error ("Ingrese usuario/contraseña");
|
||||
}
|
||||
let result = await this.getLogin(user, pass);
|
||||
|
||||
if (result.data.status === false){
|
||||
throw new Error (userdata.message);
|
||||
}
|
||||
|
||||
let userData = result.data;
|
||||
let params = { //fixed
|
||||
url: "",
|
||||
method : "GET",
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
crossDomain: true,
|
||||
dataType: "json",
|
||||
headers: { "Authorization" : userData.data.token }
|
||||
};
|
||||
localStorage.setItem("request_params", JSON.stringify(params));
|
||||
delete userData.data.token;
|
||||
userData.data["userPermissions"] = [1, 4, 14, 15]; //Owner, Customer, Seller, Deliverer
|
||||
localStorage.setItem("userData",JSON.stringify(userData.data));
|
||||
|
||||
return true;
|
||||
},
|
||||
isLogged(){
|
||||
let x = ["userData"];
|
||||
let isLogged = true;
|
||||
for (var i=0; i<x.length; i++){
|
||||
if(localStorage.getItem(x[i]) === undefined || localStorage.getItem(x[i]) === null || localStorage.getItem(x[i]) === "0"){
|
||||
isLogged = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isLogged = this.checkLogOff();
|
||||
return isLogged;
|
||||
},
|
||||
checkLogOff(){
|
||||
let req = JSON.parse(localStorage.getItem("request_params"));
|
||||
if (req === undefined || req === null) return false;
|
||||
|
||||
let data = this.decodeJWT(req.headers.Authorization);
|
||||
var today = new Date(); //Current date
|
||||
var expirationDate = new Date(data.expiration);
|
||||
|
||||
if (today.getTime() > expirationDate.getTime()){
|
||||
return false;
|
||||
}
|
||||
else if (today < expirationDate){
|
||||
}
|
||||
else{
|
||||
}
|
||||
return true;
|
||||
},
|
||||
logOff (){
|
||||
localStorage.removeItem("userData");
|
||||
localStorage.removeItem("request_params");
|
||||
location.reload();
|
||||
},
|
||||
decodeJWT (token) {
|
||||
var base64Url = token.split('.')[1];
|
||||
var base64 = decodeURIComponent(atob(base64Url).split('').map(function(c) {
|
||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||
}).join(''));
|
||||
|
||||
return JSON.parse(base64);
|
||||
},
|
||||
};
|
||||
|
||||
export default User;
|
@ -126,11 +126,11 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import $ from 'dom7';
|
||||
import * as localForage from "localforage";
|
||||
import themes from '../../js/stores/theme.js';
|
||||
import user from '../../js/stores/user.js';
|
||||
|
||||
export default (props, { $f7, $on, $update, }) => {
|
||||
export default (props, { $f7, $, $onMounted, $update, }) => {
|
||||
let isLogged = user.getters.isLogged.value;
|
||||
let isSeller = false;
|
||||
let isCustomer = false;
|
||||
@ -139,13 +139,20 @@ export default (props, { $f7, $on, $update, }) => {
|
||||
const userRoles = user.getters.roles.value;
|
||||
|
||||
const onPanelOpen = () => {
|
||||
};
|
||||
|
||||
$onMounted(() => {
|
||||
localForage.getItem('theme').then( (value) => {
|
||||
if (value != 'theme-dark'){ $(".panel-left").removeClass("theme-dark"); }
|
||||
});
|
||||
|
||||
if (isLogged){
|
||||
isCustomer = userRoles.includes(4); //Customer,
|
||||
isSeller = userRoles.includes(14); //Seller,
|
||||
isDeliverer = userRoles.includes(15); //Deliverer,
|
||||
$update();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return $render;
|
||||
}
|
||||
|
@ -61,24 +61,25 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import $ from 'dom7';
|
||||
import * as localForage from "localforage";
|
||||
import themes from '../../js/stores/theme.js';
|
||||
import user from '../../js/stores/user.js';
|
||||
|
||||
export default (props, { $f7, $on, $update, $f7router }) => {
|
||||
export default (props, { $f7, $, $on, $onMounted, $update, $f7router }) => {
|
||||
let theme = themes.getters.Name.value;
|
||||
let isLogged = user.getters.isLogged.value;
|
||||
let displayName = user.getters.displayName.value['contactName'] || '';
|
||||
|
||||
const onPanelOpen = () => {
|
||||
localForage.getItem('theme').then((value)=>{
|
||||
//if (value != 'theme-dark'){$('#light-theme').click()}
|
||||
//$('#light-theme').prop('checked', (value != 'theme-dark') ? true : false );
|
||||
//$update();
|
||||
});
|
||||
};
|
||||
|
||||
$onMounted(() => {
|
||||
$('#light-theme').prop('checked', (theme != 'theme-dark') ? true : false );
|
||||
localForage.getItem('theme').then( (value) => {
|
||||
if (value != 'theme-dark'){ $(".panel-right").removeClass("theme-dark"); }
|
||||
});
|
||||
});
|
||||
|
||||
const logout = () => {
|
||||
user.dispatch('logOut').then( () => {
|
||||
$f7router.navigate('/');
|
||||
@ -95,8 +96,6 @@ export default (props, { $f7, $on, $update, $f7router }) => {
|
||||
}
|
||||
theme = !$("#light-theme").prop('checked') ? 'theme-dark' : '';
|
||||
localForage.setItem('theme', theme).then( (val) => {
|
||||
// console.log("... ", theme);
|
||||
// console.log(",,, ",val);
|
||||
themes.dispatch('changeTheme', theme);
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user