Skip to content

Commit

Permalink
feat : Delete user #96
Browse files Browse the repository at this point in the history
  • Loading branch information
shps951023 committed Mar 20, 2024
1 parent beb9102 commit bd91298
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Frontend/src/views/UsersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</g>
</svg>
</button>
<button class="btn" @click="deleteRole(item.Id)"><svg width="20px" height="20px" viewBox="0 0 24 24"
<button class="btn" @click="deleteUser(item.Id)"><svg width="20px" height="20px" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 12V17" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
<path d="M14 12V17" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
Expand Down Expand Up @@ -201,11 +201,11 @@ const insert = async () => {
}
users.value.push({ Id: null, Enable: true })
}
const deleteRole = async (Id) => {
const deleteUser = async (Id) => {
if (!confirm("Are you sure you want to delete?")) {
return;
}
await service.post('api/deleteRole', { Id: Id }).then(async () => {
await service.post('api/deleteUser', { Id: Id }).then(async () => {
alert("Delete successfully")
await fetchData();
})
Expand Down
30 changes: 29 additions & 1 deletion src/MiniAuth/MiniAuthMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,35 @@ order by id
await OkResult(context, "".ToJson(code: 200, message: ""));
return;
}

if (subPath.StartsWithSegments("/api/deleteUser"))
{
JsonDocument bodyJson = await GetBodyJson(context);
var root = bodyJson.RootElement;
if (!root.TryGetProperty("Id", out var _id))
throw new MiniAuthException("Without Id key");
var id = _id.GetString();
using (var cn = this._db.GetConnection())
{
using (var command = cn.CreateCommand())
{
if (id != null)
{
command.CommandText = @"delete from users where id = @id";
command.AddParameters(new Dictionary<string, object>()
{
{ "@id", _id },
});
command.ExecuteNonQuery();
await OkResult(context, "".ToJson(code: 200, message: ""));
}
else
{
throw new MiniAuthException("Id is null");
}
}
}
return;
}
if (subPath.StartsWithSegments("/api/deleteRole"))
{
JsonDocument bodyJson = await GetBodyJson(context);
Expand Down

0 comments on commit bd91298

Please sign in to comment.