mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 03:57:47 -04:00
#75 remove account
This commit is contained in:
parent
b85ff19e87
commit
3a05202178
@ -49,12 +49,17 @@
|
||||
</ul>
|
||||
</template></Loading>
|
||||
|
||||
<p>
|
||||
<button class="btn btn-outline-secondary btn-sm" @click="logout">
|
||||
<section>
|
||||
<a href="#" class="badge badge-light border" @click.prevent="logout">
|
||||
<Icon v="sign-out"/>
|
||||
<T>user.logout</T>
|
||||
</button>
|
||||
</p>
|
||||
</a>
|
||||
|
||||
<a href="#" class="badge badge-light border" @click.prevent="deleteAccount">
|
||||
<Icon v="trash-alt"/>
|
||||
<T>user.deleteAccount</T>
|
||||
</a>
|
||||
</section>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@ -99,6 +104,13 @@
|
||||
setProfiles(profiles) {
|
||||
this.profiles = profiles;
|
||||
},
|
||||
async deleteAccount() {
|
||||
await this.$confirm(this.$t('user.deleteAccountConfirm'), 'danger');
|
||||
|
||||
const response = await this.$axios.$post(`/user/delete`, {}, { headers: this.$auth() });
|
||||
|
||||
this.logout();
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -681,6 +681,8 @@ user:
|
||||
avatar:
|
||||
header: 'Avatar'
|
||||
change: 'Zmień'
|
||||
deleteAccount: 'Usuń konto'
|
||||
deleteAccountConfirm: 'Czy na pewno chcesz usunąć swoje konto? Ta operacja jest nieodwracalna!'
|
||||
|
||||
profile:
|
||||
description: 'Opis'
|
||||
|
@ -161,6 +161,17 @@ const changeUsername = async (db, user, username) => {
|
||||
return await issueAuthentication(db, user);
|
||||
}
|
||||
|
||||
const removeAccount = async (db, user) => {
|
||||
const userId = (await db.get(SQL`SELECT id FROM users WHERE username = ${user.username}`)).id;
|
||||
if (!userId) {
|
||||
return false;
|
||||
}
|
||||
await db.get(SQL`DELETE FROM profiles WHERE userId = ${userId}`)
|
||||
await db.get(SQL`DELETE FROM authenticators WHERE userId = ${userId}`)
|
||||
await db.get(SQL`DELETE FROM users WHERE id = ${userId}`)
|
||||
return true;
|
||||
}
|
||||
|
||||
export default async function (req, res, next) {
|
||||
const db = await dbConnection();
|
||||
const user = authenticate(req);
|
||||
@ -177,5 +188,9 @@ export default async function (req, res, next) {
|
||||
return renderJson(res, await changeUsername(db, user, req.body.username));
|
||||
}
|
||||
|
||||
if (req.method === 'POST' && req.url === '/delete' && user && user.authenticated) {
|
||||
return renderJson(res, await removeAccount(db, user));
|
||||
}
|
||||
|
||||
return renderJson(res, {error: 'Not found'}, 404);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user