#195 delete user button in the UI

This commit is contained in:
Hamid Reza Mohammadi 2021-09-01 20:56:44 +04:30
parent 585fc52783
commit 3fdc916986
3 changed files with 88 additions and 0 deletions

View File

@ -29,5 +29,10 @@ else
<td>ایمیل:</td>
<td>@Model.UserInfo.Email</td>
</tr>
<tr>
<td colspan="2">
<a role="button" style="cursor:pointer;width:100%;color:white;background-color:red;display:block" href="/Admin/KickoutUser?id=@Model.UserInfo.Id">حذف حساب کاربری</a>
</td>
</tr>
</table>
}

View File

@ -0,0 +1,37 @@
@page
@model GanjooRazor.Areas.Admin.Pages.KickoutUserModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_AdminLayout";
ViewData["Title"] = "حذف کاربر";
}
@if (!string.IsNullOrEmpty(Model.LastResult))
{
<p>
@Model.LastResult
</p>
<p>
<a role="button" href="/Admin/ExamineUser?id=@Model.UserInfo.Id" class="actionlink">برگشت</a>
</p>
}
else
{
<table>
<tr>
<td colspan="2">
آیا از حذف @Model.UserInfo.Email اطمینان دارید؟
</td>
</tr>
<tr>
<td>
<form method="post">
<input type="submit" value="بله" />
</form>
</td>
<td>
<a role="button" href="/Admin/ExamineUser?id=@Model.UserInfo.Id" class="actionlink">خیر / برگشت</a>
</td>
</tr>
</table>
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RSecurityBackend.Models.Auth.ViewModels;
namespace GanjooRazor.Areas.Admin.Pages
{
public class KickoutUserModel : PageModel
{
public PublicRAppUser UserInfo { get; set; }
/// <summary>
/// Last Error
/// </summary>
public string LastResult { get; set; }
public async Task OnGetAsync()
{
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
var userInfoResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/{Request.Query["id"]}");
if (userInfoResponse.IsSuccessStatusCode)
{
UserInfo = JsonConvert.DeserializeObject<PublicRAppUser>(await userInfoResponse.Content.ReadAsStringAsync());
}
else
{
LastResult = await userInfoResponse.Content.ReadAsStringAsync();
}
}
else
{
LastResult = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
}
}
}