This commit is contained in:
@@ -6,45 +6,7 @@ import store from "../store";
|
|||||||
//import auth0 from 'auth0-js';
|
//import auth0 from 'auth0-js';
|
||||||
//import Router from 'vue-router';
|
//import Router from 'vue-router';
|
||||||
//import Auth0Lock from 'auth0-lock';
|
//import Auth0Lock from 'auth0-lock';
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/15551652/javascript-enum-flag-check
|
|
||||||
const AuthorizationRoles = {
|
|
||||||
///<summary>No role set</summary>
|
|
||||||
NoRole: 0,
|
|
||||||
///<summary>BizAdminLimited</summary>
|
|
||||||
BizAdminLimited: 1,
|
|
||||||
///<summary>BizAdminFull</summary>
|
|
||||||
BizAdminFull: 2,
|
|
||||||
///<summary>DispatchLimited</summary>
|
|
||||||
DispatchLimited: 4,
|
|
||||||
///<summary>DispatchFull</summary>
|
|
||||||
DispatchFull: 8,
|
|
||||||
///<summary>InventoryLimited</summary>
|
|
||||||
InventoryLimited: 16,
|
|
||||||
///<summary>InventoryFull</summary>
|
|
||||||
InventoryFull: 32,
|
|
||||||
///<summary>AccountingFull</summary>
|
|
||||||
AccountingFull: 64, //No limited role, not sure if there is a need
|
|
||||||
///<summary>TechLimited</summary>
|
|
||||||
TechLimited: 128,
|
|
||||||
///<summary>TechFull</summary>
|
|
||||||
TechFull: 256,
|
|
||||||
///<summary>SubContractorLimited</summary>
|
|
||||||
SubContractorLimited: 512,
|
|
||||||
///<summary>SubContractorFull</summary>
|
|
||||||
SubContractorFull: 1024,
|
|
||||||
///<summary>ClientLimited</summary>
|
|
||||||
ClientLimited: 2048,
|
|
||||||
///<summary>ClientFull</summary>
|
|
||||||
ClientFull: 4096,
|
|
||||||
///<summary>OpsAdminLimited</summary>
|
|
||||||
OpsAdminLimited: 8192,
|
|
||||||
///<summary>OpsAdminFull</summary>
|
|
||||||
OpsAdminFull: 16384
|
|
||||||
}; //end AuthorizationRoles
|
|
||||||
|
|
||||||
const TOKEN_KEY = "apitoken";
|
const TOKEN_KEY = "apitoken";
|
||||||
const USER_ROLES = AuthorizationRoles.NoRole;
|
|
||||||
|
|
||||||
export function processLogin(response) {
|
export function processLogin(response) {
|
||||||
//is token present?
|
//is token present?
|
||||||
@@ -123,14 +85,3 @@ function isTokenExpired(token) {
|
|||||||
const expirationDate = getTokenExpirationDate(token);
|
const expirationDate = getTokenExpirationDate(token);
|
||||||
return expirationDate < new Date();
|
return expirationDate < new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
//================ ROLES =================
|
|
||||||
//https://stackoverflow.com/questions/39359740/what-are-enum-flags-in-typescript
|
|
||||||
export function hasRole(role) {
|
|
||||||
return role === (USER_ROLES & role);
|
|
||||||
// if ((role & flags.ERROR) == flags.ERROR) {
|
|
||||||
// alert("ERROR IS SET");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Auth JWT needs to return roles as an int enum
|
|
||||||
|
|||||||
48
app/ayanova/src/utils/roles.js
Normal file
48
app/ayanova/src/utils/roles.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import store from "../store";
|
||||||
|
export default {
|
||||||
|
AuthorizationRoles: {
|
||||||
|
///<summary>No role set</summary>
|
||||||
|
NoRole: 0,
|
||||||
|
///<summary>BizAdminLimited</summary>
|
||||||
|
BizAdminLimited: 1,
|
||||||
|
///<summary>BizAdminFull</summary>
|
||||||
|
BizAdminFull: 2,
|
||||||
|
///<summary>DispatchLimited</summary>
|
||||||
|
DispatchLimited: 4,
|
||||||
|
///<summary>DispatchFull</summary>
|
||||||
|
DispatchFull: 8,
|
||||||
|
///<summary>InventoryLimited</summary>
|
||||||
|
InventoryLimited: 16,
|
||||||
|
///<summary>InventoryFull</summary>
|
||||||
|
InventoryFull: 32,
|
||||||
|
///<summary>AccountingFull</summary>
|
||||||
|
AccountingFull: 64, //No limited role, not sure if there is a need
|
||||||
|
///<summary>TechLimited</summary>
|
||||||
|
TechLimited: 128,
|
||||||
|
///<summary>TechFull</summary>
|
||||||
|
TechFull: 256,
|
||||||
|
///<summary>SubContractorLimited</summary>
|
||||||
|
SubContractorLimited: 512,
|
||||||
|
///<summary>SubContractorFull</summary>
|
||||||
|
SubContractorFull: 1024,
|
||||||
|
///<summary>ClientLimited</summary>
|
||||||
|
ClientLimited: 2048,
|
||||||
|
///<summary>ClientFull</summary>
|
||||||
|
ClientFull: 4096,
|
||||||
|
///<summary>OpsAdminLimited</summary>
|
||||||
|
OpsAdminLimited: 8192,
|
||||||
|
///<summary>OpsAdminFull</summary>
|
||||||
|
OpsAdminFull: 16384
|
||||||
|
},
|
||||||
|
hasRole(role) {
|
||||||
|
if (!store.state.roles || store.state.roles === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return role === (store.state.roles & role);
|
||||||
|
//https://stackoverflow.com/questions/39359740/what-are-enum-flags-in-typescript
|
||||||
|
//https://stackoverflow.com/questions/15551652/javascript-enum-flag-check
|
||||||
|
// if ((role & flags.ERROR) == flags.ERROR) {
|
||||||
|
// alert("ERROR IS SET");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</v-flex>
|
</v-flex>
|
||||||
<v-flex class="text-xs-center" mt-5>
|
<v-flex class="text-xs-center" mt-5>
|
||||||
<v-btn color="primary" v-on:click="login()">Login</v-btn>
|
<v-btn color="primary" v-on:click="login()">Login</v-btn>
|
||||||
<v-btn color="primary" v-on:click="showlog()">Log</v-btn>
|
<v-btn color="primary" v-on:click="showlog()">Show log in console</v-btn>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
</v-layout>
|
</v-layout>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user