Compare commits

...

4 Commits

5 changed files with 79 additions and 9 deletions

View File

@ -19,16 +19,31 @@ import ListSecrets from "./components/ListSecrets.vue";
</div> </div>
</div> </div>
<el-dialog v-model="creationDialog" title="Add a new TOTP secret" width="80vw"> <el-dialog
v-model="creationDialog"
title="Add a new TOTP secret"
destroy-on-close
width="80vw"
>
<CreateSecret @close="secretSaved" /> <CreateSecret @close="secretSaved" />
</el-dialog> </el-dialog>
<el-dialog v-model="editDialog" title="Edit TOTP secret" width="80vw"> <el-dialog
v-model="editDialog"
title="Edit TOTP secret"
destroy-on-close
width="80vw"
>
<CreateSecret :editSecret="editingSecret" @close="secretSaved" /> <CreateSecret :editSecret="editingSecret" @close="secretSaved" />
</el-dialog> </el-dialog>
<el-dialog v-model="importDialog" title="Import TOTP secrets" width="80vw"> <el-dialog
<ImportSecrets /> v-model="importDialog"
title="Import TOTP secrets"
destroy-on-close
width="80vw"
>
<ImportSecrets @close="secretsImported" />
</el-dialog> </el-dialog>
<div class="container"> <div class="container">
@ -80,6 +95,11 @@ export default {
this.listUpdated += 1; this.listUpdated += 1;
}, },
secretsImported() {
this.importDialog = false;
this.listUpdated += 1;
},
async validateToken() { async validateToken() {
const url = `${this.apiBaseUrl}/validate-token`; const url = `${this.apiBaseUrl}/validate-token`;
const token = sessionStorage.getItem("token"); const token = sessionStorage.getItem("token");

View File

@ -42,6 +42,15 @@
type="primary" type="primary"
>Save & Close</el-button >Save & Close</el-button
> >
<el-button
type="danger"
@click="
deleteSecret();
closeDialog();
"
v-if="this.method === 'PUT'"
>Delete</el-button
>
</div> </div>
</div> </div>
</template> </template>
@ -87,7 +96,7 @@ export default {
}, },
body: JSON.stringify(bodyData), body: JSON.stringify(bodyData),
}; };
console.log(requestOptions); // console.log(requestOptions);
await fetch(url, requestOptions) await fetch(url, requestOptions)
.then((response) => response.json()) .then((response) => response.json())
.then((data) => console.log(data)); .then((data) => console.log(data));
@ -100,6 +109,25 @@ export default {
(this.form.secret = ""); (this.form.secret = "");
this.$emit("close", true); this.$emit("close", true);
}, },
async deleteSecret() {
const url = `${this.apiBaseUrl}/secret`;
const token = sessionStorage.getItem("token");
const bodyData = { data: btoa(JSON.stringify(this.form)) };
bodyData["id"] = this.id;
const requestOptions = {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(bodyData),
};
// console.log(requestOptions);
await fetch(url, requestOptions)
.then((response) => response.json())
.then((data) => console.log(data));
},
}, },
created() { created() {

View File

@ -59,13 +59,13 @@ export default {
var label = decodeURIComponent(url.pathname.slice(1)); // Remove the leading '/' var label = decodeURIComponent(url.pathname.slice(1)); // Remove the leading '/'
const type = label.slice(1, -1).split("/")[0]; const type = label.slice(1, -1).split("/")[0];
label = label.slice(6); label = label.slice(6);
let accountName, issuerFromLabel; let username, issuerFromLabel;
const labelParts = label.split(":"); const labelParts = label.split(":");
if (labelParts.length === 2) { if (labelParts.length === 2) {
issuerFromLabel = labelParts[0]; issuerFromLabel = labelParts[0];
accountName = labelParts[1]; username = labelParts[1];
} else { } else {
accountName = label; username = label;
} }
const params = {}; const params = {};
@ -86,7 +86,7 @@ export default {
scheme, scheme,
type, type,
label, label,
accountName, username,
issuer, issuer,
secret, secret,
algorithm, algorithm,
@ -121,6 +121,7 @@ export default {
for (var i = 0; i < this.parsedTokens.length; i++) { for (var i = 0; i < this.parsedTokens.length; i++) {
await this.createSecret(this.parsedTokens[i]); await this.createSecret(this.parsedTokens[i]);
} }
this.$emit("close", true);
}, },
}, },
}; };

View File

@ -135,6 +135,14 @@ async def update_secret(secret: Secret, current_user: dict = Depends(get_current
return token return token
@app.delete('/secret')
async def delete_secret(secret: Secret, current_user: dict = Depends(get_current_user)):
"""Deletes the secret with the given id"""
secret.user_id = current_user['id']
# print(secret.model_dump())
user_id, secret_id = queries.DELETE_SECRET(secret.model_dump())
@app.get('/secret') @app.get('/secret')
async def list_secret(current_user: dict = Depends(get_current_user)): async def list_secret(current_user: dict = Depends(get_current_user)):
"""Returns the encrypted secrets of the user.""" """Returns the encrypted secrets of the user."""

View File

@ -143,6 +143,19 @@ UPDATE_SECRET = DbQuery(
rows='single' rows='single'
) )
DELETE_SECRET = DbQuery(
"""
DELETE from secrets
WHERE
user_id = :user_id
and id = :id
RETURNING user_id, id
""",
type='write',
returns=True,
rows='single'
)
GET_SECRETS = DbQuery( GET_SECRETS = DbQuery(
""" """
SELECT * SELECT *