Skip to content

Commit

Permalink
Implemented user self-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
usp-npe committed Apr 20, 2022
1 parent 06c93bc commit 56b041e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 24 deletions.
14 changes: 11 additions & 3 deletions app/Http/Controllers/UserManagement/API/UserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,26 @@ public function updatePassword(StoreNewUserPassword $request)
]);
}

public function delete()
public function delete(Request $request)
{
$user = Auth::user();
Auth::logout();
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();

$user->delete();

Log::notice('Used deleted account.', [
'user_id' => $user->id,
'user_name' => $user->name,
'email' => $user->email,
'client_ip' => request()->ip(),
]);
return view('user_management.userprofile.deleted');

return response()
->json([
'message' => __('Your account has been deleted.'),
]);
}

public function view2FA(Request $request)
Expand Down
1 change: 1 addition & 0 deletions config/ziggy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
'accounting.webling.index',
'cmtyvol.index',
'users.show',
'login',
],
];
3 changes: 2 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,5 +778,6 @@
"Edit metadata": "Metadaten bearbeiten",
"Add row": "Zeile hinzufügen",
"Load data": "Daten laden",
"Optional: Upload an alternative logo file.": "Optional: Alternatives Logo hochladen."
"Optional: Upload an alternative logo file.": "Optional: Alternatives Logo hochladen.",
"Account Deletion": "Accountlöschung"
}
4 changes: 4 additions & 0 deletions resources/js/api/userprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export default {
const url = route('api.userprofile.updatePassword')
return await api.post(url, data)
},
async delete() {
const url = route('api.userprofile.delete')
return await api.delete(url)
},
};
27 changes: 24 additions & 3 deletions resources/js/pages/users/UserProfilePage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<template>
<b-container v-if="user">
<b-container v-if="hasBeenDeleted">
<h2 class="display-4 p-0">{{ $t('Account Deletion') }}</h2>

<b-alert variant="info" show>
<font-awesome-icon icon="info-circle"/>
{{ $t('Your account has been deleted.') }}
</b-alert>

<div class="text-center mt-4">
<a :href="route('login')">{{ $t('Return to login') }}</a>
</div>
</b-container>
<b-container v-else-if="user">

<b-row class="align-items-center">
<b-col cols="auto">
Expand Down Expand Up @@ -309,6 +321,7 @@ export default {
password_confirmation: '',
languages: {},
isBusy: false,
hasBeenDeleted: false,
}
},
computed: {
Expand Down Expand Up @@ -368,9 +381,17 @@ export default {
getValidationState ({ dirty, validated, valid = null }) {
return dirty || validated ? valid : null;
},
confirmDelete() {
async confirmDelete() {
if (confirm(this.$t('Do you really want to delete your account and lose access to all data?'))) {
console.log('confirmDelete')
this.isBusy = true
try {
let data = await userprofileApi.delete()
showSnackbar(data.message)
this.hasBeenDeleted = true
} catch (err) {
alert(err)
}
this.isBusy = false
}
},
}
Expand Down
1 change: 1 addition & 0 deletions resources/js/vue-i18n-locales.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ export default {
"Add row": "Zeile hinzufügen",
"Load data": "Daten laden",
"Optional: Upload an alternative logo file.": "Optional: Alternatives Logo hochladen.",
"Account Deletion": "Accountlöschung",
"app": [],
"auth": {
"failed": "Diese Kombination aus Zugangsdaten wurden nicht in unserer Datenbank gefunden.",
Expand Down
2 changes: 1 addition & 1 deletion resources/js/ziggy.js

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions resources/views/user_management/userprofile/deleted.blade.php

This file was deleted.

1 change: 0 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@
->name('userprofile.update');
Route::post('userprofile/updatePassword', [UserProfileController::class, 'updatePassword'])
->name('userprofile.updatePassword');

Route::delete('userprofile', [UserProfileController::class, 'delete'])
->name('userprofile.delete');

Expand Down

0 comments on commit 56b041e

Please sign in to comment.