FastAuth/frontend/src/components/ListSecrets.vue

141 lines
3.6 KiB
Vue
Raw Normal View History

2024-06-11 18:15:29 +00:00
<template>
<div>
2024-06-14 18:42:26 +00:00
<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">
2024-06-13 17:54:48 +00:00
<el-table-column type="expand">
<template #default="props">
<div style="margin-left: 3rem">
{{ props.row.notes }}
</div>
</template>
</el-table-column>
<el-table-column prop="id" label="Id" />
<el-table-column prop="issuer" label="Issuer" />
<el-table-column prop="username" label="Username" />
<el-table-column label="Secret">
<template #default="scope">
<div>
{{ generateTotp(scope.row.secret) }}
</div>
</template>
</el-table-column>
2024-06-13 17:54:48 +00:00
<!-- <el-table-column prop="notes" label="Notes" /> -->
<el-table-column fixed="right" label="Operations" width="120">
<template #default="scope">
<el-button link type="primary" size="small" @click="handleClick(scope)">
Edit
</el-button>
</template>
</el-table-column>
</el-table>
</div>
2024-06-11 18:15:29 +00:00
</template>
<script>
import { TOTP } from "totp-generator";
2024-06-11 18:15:29 +00:00
export default {
data() {
return {
message: "Hello List Secret",
apiBaseUrl: "http://localhost:8000",
secretsList: [],
2024-06-14 18:42:26 +00:00
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: [],
2024-06-11 18:15:29 +00:00
};
},
methods: {
async listSecrets() {
const url = `${this.apiBaseUrl}/secret`;
2024-06-14 18:42:26 +00:00
const token = sessionStorage.getItem("token");
const requestOptions = {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
};
console.log(requestOptions);
const response = await fetch(url, requestOptions)
.then((response) => response.json())
.then((data) => {
2024-06-13 17:54:48 +00:00
console.log(data);
return data;
})
.catch((err) => console.log(err));
response.forEach((element) => {
2024-06-13 17:54:48 +00:00
// console.log(element);
const row = this.parseSecret(element.data);
2024-06-13 17:54:48 +00:00
row["id"] = element["id"];
this.secretsList.push(row);
});
},
parseSecret(gibberish) {
const jsonString = atob(gibberish);
const secret = JSON.parse(jsonString);
return secret;
},
generateTotp(secret) {
const { otp, expires } = TOTP.generate(secret);
console.log(expires);
return otp;
},
2024-06-13 17:54:48 +00:00
handleClick(scope) {
console.log(scope);
},
2024-06-14 18:42:26 +00:00
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() {
this.listSecrets();
},
2024-06-11 18:15:29 +00:00
};
</script>