Added feature for delete user account
This commit is contained in:
parent
6ee117b583
commit
ad8b8f4767
4 changed files with 78 additions and 1 deletions
|
@ -22,8 +22,10 @@ if (typeof email !== "undefined" && typeof username !== "undefined") {
|
|||
wantlist:
|
||||
"Je viens d'ajouter {artist} - {album} à ma liste de souhaits !",
|
||||
},
|
||||
delete: false,
|
||||
},
|
||||
loading: false,
|
||||
deleting: false,
|
||||
errors: [],
|
||||
};
|
||||
},
|
||||
|
@ -108,6 +110,20 @@ if (typeof email !== "undefined" && typeof username !== "undefined") {
|
|||
|
||||
return true;
|
||||
},
|
||||
async deleteAccount() {
|
||||
try {
|
||||
await axios.delete(`/api/v1/me`);
|
||||
|
||||
showToastr("Compte supprimé", true);
|
||||
|
||||
window.location.href = "/se-deconnecter";
|
||||
} catch (err) {
|
||||
showToastr(
|
||||
err.response?.data?.message ||
|
||||
"Impossible de mettre à jour votre profil"
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
}).mount("#mon-compte");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import Joi from "joi";
|
||||
|
||||
import UsersModel from "../models/users";
|
||||
import AlbumsModel from "../models/albums";
|
||||
import WantlistModel from "../models/wantlist";
|
||||
import Pages from "./Pages";
|
||||
|
||||
/**
|
||||
|
@ -69,6 +71,23 @@ class Me extends Pages {
|
|||
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode permettant de supprimer un utilisateur et toutes ses données
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
async deleteMe() {
|
||||
const { _id } = this.req.user;
|
||||
|
||||
await AlbumsModel.deleteMany({ User: _id });
|
||||
await WantlistModel.deleteMany({ User: _id });
|
||||
await UsersModel.deleteOne({ _id });
|
||||
|
||||
return {
|
||||
deleted: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Me;
|
||||
|
|
|
@ -15,6 +15,16 @@ router
|
|||
const me = new Me(req);
|
||||
const data = await me.patchMe();
|
||||
|
||||
return sendResponse(req, res, data);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
})
|
||||
.delete(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||||
try {
|
||||
const me = new Me(req);
|
||||
const data = await me.deleteMe();
|
||||
|
||||
return sendResponse(req, res, data);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
|
|
|
@ -149,7 +149,39 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div></div>
|
||||
<div class="box">
|
||||
<h2>Supprimer mon compte</h2>
|
||||
<div>
|
||||
<p>
|
||||
Vous souhaitez supprimer votre compte et vos collections ?
|
||||
<br />
|
||||
Rien de plus simple !
|
||||
<br />
|
||||
Il vous suffit de cliquer sur le bouton ci-dessous et l'on se charge de supprimer dans la seconde absolument toutes les données stockées sur cette instance vous concernant !
|
||||
</p>
|
||||
|
||||
<div class="flash error">
|
||||
<div class="header">
|
||||
Attention
|
||||
</div>
|
||||
<div class="body">
|
||||
Toute suppression est définitive
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="delete">
|
||||
<input type="checkbox" id="delete" v-model="formData.delete">
|
||||
J'ai compris
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="button" class="button is-danger mt-10" :disabled="deleting || !formData.delete" @click="deleteAccount">
|
||||
<span v-if="!deleting">Supprimer</span>
|
||||
<i class="icon-spin animate-spin" v-if="deleting"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button is-primary mt-10" :disabled="loading">
|
||||
<span v-if="!loading">Mettre à jour</span>
|
||||
|
|
Loading…
Reference in a new issue