Compare commits
No commits in common. "4bf48b9538c61a412a9270ab23b4f935d9913ced" and "956faf2e3c929b60cce717d764082322d01a0f58" have entirely different histories.
4bf48b9538
...
956faf2e3c
@ -28,14 +28,7 @@ import ListSecrets from "./components/ListSecrets.vue";
|
||||
</el-dialog>
|
||||
|
||||
<div class="container">
|
||||
<HomePage
|
||||
msg="You did it!"
|
||||
@loggedin="
|
||||
loggedin = true;
|
||||
showSecrets = true;
|
||||
"
|
||||
v-if="!loggedin"
|
||||
/>
|
||||
<HomePage msg="You did it!" @loggedin="loggedin = true" v-if="!loggedin" />
|
||||
<el-button @click="showSecrets = true" v-if="loggedin"> Show secrets </el-button>
|
||||
<el-button @click="showSecrets = false" v-if="showSecrets && loggedin">
|
||||
Hide secrets
|
||||
@ -53,12 +46,11 @@ export default {
|
||||
showSecrets: false,
|
||||
creationDialog: false,
|
||||
listUpdated: 1,
|
||||
apiBaseUrl: "http://localhost:8000",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
logout() {
|
||||
sessionStorage.removeItem("token");
|
||||
localStorage.removeItem("token");
|
||||
this.loggedin = false;
|
||||
},
|
||||
|
||||
@ -68,47 +60,6 @@ export default {
|
||||
this.listUpdated += 1;
|
||||
console.log("after update", this.listUpdated);
|
||||
},
|
||||
|
||||
async validateToken() {
|
||||
const url = `${this.apiBaseUrl}/validate-token`;
|
||||
const token = sessionStorage.getItem("token");
|
||||
const requestOptions = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
};
|
||||
|
||||
const response = await fetch(url, requestOptions)
|
||||
.then((response) => response.json())
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
return false;
|
||||
}
|
||||
if ("message" in response) {
|
||||
if (response["message"] === "authenticated") {
|
||||
console.log("token validated");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
if ("token" in sessionStorage) {
|
||||
const tokenValid = await this.validateToken();
|
||||
|
||||
if (tokenValid) {
|
||||
this.loggedin = true;
|
||||
this.showSecrets = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -46,7 +46,7 @@ export default {
|
||||
methods: {
|
||||
async createSecret() {
|
||||
const url = `${this.apiBaseUrl}/secret`;
|
||||
const token = sessionStorage.getItem("token");
|
||||
const token = localStorage.getItem("token");
|
||||
const requestOptions = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -49,7 +49,7 @@ export default {
|
||||
if ("message" in response) {
|
||||
if (response.message === "authenticated") {
|
||||
const token = response.accessToken;
|
||||
sessionStorage.setItem("token", token);
|
||||
localStorage.setItem("token", token);
|
||||
this.$emit("loggedin", true);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<br />
|
||||
<el-button-group>
|
||||
<el-button
|
||||
type="success"
|
||||
v-for="band in filterBands"
|
||||
:key="band"
|
||||
@click="filterTable(band)"
|
||||
>
|
||||
{{ band }}
|
||||
</el-button>
|
||||
<el-button type="success">Clear</el-button>
|
||||
</el-button-group>
|
||||
</div>
|
||||
<el-table :data="filteredSecretsList" style="width: 100vw">
|
||||
<el-table :data="secretsList" style="width: 100vw">
|
||||
<el-table-column type="expand">
|
||||
<template #default="props">
|
||||
<div style="margin-left: 3rem">
|
||||
@ -53,23 +39,13 @@ export default {
|
||||
message: "Hello List Secret",
|
||||
apiBaseUrl: "http://localhost:8000",
|
||||
secretsList: [],
|
||||
filteredSecretsList: [],
|
||||
filterBands: ["A-C", "D-I", "J-O", "P-S", "T-Z"],
|
||||
filterBandsVals: {
|
||||
"A-C": ["A", "B", "C"],
|
||||
"D-I": ["D", "E", "F", "G", "H", "I"],
|
||||
"J-O": ["J", "K", "L", "M", "N", "O"],
|
||||
"P-S": ["P", "Q", "R", "S"],
|
||||
"T-Z": ["T", "U", "V", "W", "X", "Y", "Z"],
|
||||
},
|
||||
currentFilter: [],
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
async listSecrets() {
|
||||
const url = `${this.apiBaseUrl}/secret`;
|
||||
const token = sessionStorage.getItem("token");
|
||||
const token = localStorage.getItem("token");
|
||||
const requestOptions = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
@ -109,28 +85,6 @@ export default {
|
||||
handleClick(scope) {
|
||||
console.log(scope);
|
||||
},
|
||||
|
||||
filterTable(band) {
|
||||
const letters = this.filterBandsVals[band];
|
||||
this.currentFilter = letters;
|
||||
console.log(letters);
|
||||
},
|
||||
|
||||
checkFirstLetter(row) {
|
||||
const firstLetter = row.issuer[0].toUpperCase();
|
||||
if (this.currentFilter.indexOf(firstLetter) > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
currentFilter: function (newFilter, oldFilter) {
|
||||
// console.log("filter", newFilter, oldFilter);
|
||||
const filteredList = this.secretsList.filter(this.checkFirstLetter);
|
||||
this.filteredSecretsList = filteredList;
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
|
12
main.py
12
main.py
@ -167,14 +167,4 @@ async def list_secret(current_user: dict = Depends(get_current_user)):
|
||||
decrypted_data = fernet_decrypt(cur_data, encryption_key)
|
||||
secret['data'] = decrypted_data
|
||||
|
||||
return user_secrets
|
||||
|
||||
|
||||
@app.get('/validate-token')
|
||||
async def validate_token(current_user: dict = Depends(get_current_user)):
|
||||
user_id = current_user['id']
|
||||
print("user_id: ", user_id)
|
||||
if user_id is not None:
|
||||
return {'message': 'authenticated'}
|
||||
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
return user_secrets
|
Loading…
Reference in New Issue
Block a user