docs: #282 redirecting for admin area pages

This commit is contained in:
Hamid Reza Mohammadi 2022-02-15 20:40:56 +03:30
parent 553a13e60d
commit 1d71fd1859
23 changed files with 120 additions and 28 deletions

View File

@ -34,6 +34,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
using (HttpClient secureClient = new HttpClient())

View File

@ -110,6 +110,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = Request.Query["edit"] == "true" ? "ویرایش انجام شد." : "";
if (string.IsNullOrEmpty(Request.Query["url"]))

View File

@ -33,6 +33,10 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/donations/{Request.Query["id"]}");
if(!response.IsSuccessStatusCode)

View File

@ -80,6 +80,10 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
Donation = new GanjoorDonationViewModel()

View File

@ -23,6 +23,10 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
using (HttpClient secureClient = new HttpClient())

View File

@ -1,6 +1,7 @@
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;
@ -17,8 +18,11 @@ namespace GanjooRazor.Areas.Admin.Pages
/// </summary>
public string LastError { get; set; }
public async Task OnGetAsync()
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
@ -38,6 +42,7 @@ namespace GanjooRazor.Areas.Admin.Pages
LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
return Page();
}
}
}

View File

@ -34,6 +34,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/donations/expense/{Request.Query["id"]}");

View File

@ -72,6 +72,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
Expense = new GanjoorExpense()

View File

@ -25,6 +25,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))

View File

@ -43,6 +43,9 @@ namespace GanjooRazor.Areas.Admin.Pages
}
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
await ReadLocationsAsync();
return Page();

View File

@ -18,6 +18,10 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
using (HttpClient secureClient = new HttpClient())
{

View File

@ -138,6 +138,10 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = Request.Query["edit"] == "true" ? "ویرایش انجام شد." : "";
if (string.IsNullOrEmpty(Request.Query["id"]))
{

View File

@ -40,6 +40,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastResult = "";
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={Request.Query["url"]}");
if (!response.IsSuccessStatusCode)

View File

@ -18,6 +18,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public GanjoorPageSnapshotSummaryViewModel[] OlderVersions { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
using (HttpClient secureClient = new HttpClient())

View File

@ -124,6 +124,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastResult = "";
if (string.IsNullOrEmpty(Request.Query["id"]))

View File

@ -61,6 +61,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastResult = "";
await PreparePoet();

View File

@ -66,6 +66,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
using (HttpClient secureClient = new HttpClient())

View File

@ -42,6 +42,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public GanjoorPoemCompleteViewModel Poem { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastMessage = "";
var rhythmResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/rhythms?sortOnVerseCount=true");

View File

@ -43,6 +43,9 @@ namespace GanjooRazor.Areas.Admin.Pages
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
FatalError = "";
TotalCount = 0;
Skip = string.IsNullOrEmpty(Request.Query["skip"]) ? 0 : int.Parse(Request.Query["skip"]);

View File

@ -4,31 +4,37 @@
@{
Layout = "_AdminLayout";
ViewData["Title"] = "بازگشت از اسپاتیفای";
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
}
<form method="post">
<input asp-for="@Model.Code" type="hidden" />
@if (ViewData.ContainsKey("ganjoor-songrevu"))
{
<form method="post">
<input asp-for="@Model.Code" type="hidden" />
<div>
<button type="submit">ذخیره</button>
</div>
</form>
<p>
<strong>Code:</strong> <code>@Model.Code</code>
</p>
<p>
<strong>access_token:</strong> <code>@Model.access_token</code>
</p>
<p>
<strong>token_type:</strong> <code>@Model.token_type</code>
</p>
<p>
<strong>expires_in:</strong> <code>@Model.expires_in</code>
</p>
<p>
<strong>refresh_token:</strong> <code>@Model.refresh_token</code>
</p>
<p>
<strong>Error:</strong> <code>@Model.Error</code>
</p>
}
<div>
<button type="submit">ذخیره</button>
</div>
</form>
<p>
<strong>Code:</strong> <code>@Model.Code</code>
</p>
<p>
<strong>access_token:</strong> <code>@Model.access_token</code>
</p>
<p>
<strong>token_type:</strong> <code>@Model.token_type</code>
</p>
<p>
<strong>expires_in:</strong> <code>@Model.expires_in</code>
</p>
<p>
<strong>refresh_token:</strong> <code>@Model.refresh_token</code>
</p>
<p>
<strong>Error:</strong> <code>@Model.Error</code>
</p>

View File

@ -20,14 +20,21 @@ namespace GanjooRazor.Areas.Admin.Pages
_clientFactory = clientFactory;
_configuration = configuration;
}
public void OnGet(string code = "code", string state = "none")
public IActionResult OnGet(string code = "code", string state = "none")
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
Code = code;
State = state;
return Page();
}
public async Task<ActionResult> OnPostAsync(string code)
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
var nvc = new List<KeyValuePair<string, string>>();
nvc.Add(new KeyValuePair<string, string>("grant_type", "authorization_code"));
nvc.Add(new KeyValuePair<string, string>("code", code));

View File

@ -4,8 +4,14 @@
@{
Layout = "_AdminLayout";
ViewData["Title"] = "ورود به اسپاتیفای";
await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData);
}
@if (ViewData.ContainsKey("ganjoor-songrevu"))
{
<h1>@ViewData["Title"]</h1>
<p>Click <a href="@Model.SpotifyUrl">ورود</a></p>
}
<h1>@ViewData["Title"]</h1>
<p>Click <a href="@Model.SpotifyUrl">ورود</a></p>

View File

@ -1,5 +1,6 @@
using System.Net;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
@ -14,6 +15,14 @@ namespace GanjooRazor.Areas.Admin.Pages
_configuration = configuration;
}
public IActionResult OnGet()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
return Page();
}
/// <summary>
/// url
/// </summary>