make backend for my site

This commit is contained in:
yawaflua
2024-04-17 22:55:07 +03:00
parent 83c7fc1723
commit 1075225001
50 changed files with 571 additions and 312 deletions

View File

@@ -1,5 +1,5 @@
@page "{type?}"
@model yaflay.ru.Pages.AdminPanelModel
@model yawaflua.ru.Pages.AdminPanelModel
@using System.Text.Json.Nodes
@{
ViewData["Title"] = "AdminPanel";

View File

@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
public class AdminPanelModel : PageModel
{

View File

@@ -1,5 +1,5 @@
@page "{code}"
@model yaflay.ru.Pages.AuthorizeModel
@model yawaflua.ru.Pages.AuthorizeModel
@using System.Text.Json.Nodes
@using Newtonsoft.Json
@{
@@ -58,10 +58,10 @@
{
<h4>Ошибка! Попробуй авторизоваться заново</h4>
Console.Error.WriteLine("debug: START \\/ \nDon't worry, this message is not bad as you think");
Console.Error.WriteLine("debug: START \\/ \ninfo: Don't worry, this message is not bad as you think");
Console.Error.WriteLine("error: DiscordAuthorize is not worked");
Console.Error.WriteLine($"debug: Body from discord: {body}\ndebug: Sended data to discord: {message.Content.ReadAsStringAsync().Result}");
Console.Error.WriteLine($"info: Check environment data: \nClientId={Startup.clientId}\nClientSecret={Startup.clientSecret}\nRedirectUrl={Startup.redirectUrl}\nOwnerId={String.Join(",", Startup.ownerId)} ");
Console.Error.WriteLine($"info: Check environment data: \n ClientId={Startup.clientId}\n ClientSecret={Startup.clientSecret}\n RedirectUrl={Startup.redirectUrl}\n OwnerId={String.Join(",", Startup.ownerId)} ");
Console.Error.WriteLine("info: If any data is null and you set data in environment or appsettings.json, please create issue with this debug messages ");
Console.Error.WriteLine("debug: END /\\");
}
@@ -72,7 +72,7 @@
try
{
HttpContent bodytoApi;
bodytoApi = new StringContent(JsonConvert.SerializeObject(new yaflay.ru.Controllers.HomeController.authorizeBody()
bodytoApi = new StringContent(JsonConvert.SerializeObject(new yawaflua.ru.Controllers.ApiController.authorizeBody()
{
discordId = body["user"]["id"].ToString(),
melon = body["access_token"].ToString(),
@@ -87,7 +87,7 @@
Console.WriteLine(ex.Message);
}
Response.Redirect("/authorize");
Response.Redirect("/authorize", true);
}
}
}

View File

@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
public class AuthorizeModel : PageModel
{

View File

@@ -1,6 +1,6 @@
@page "{id?}"
@model BlogModel
@using yaflay.ru.Models.Tables
@using yawaflua.ru.Models.Tables
@using Newtonsoft.Json
@{
string path = $"{this.Request.Scheme}://{this.Request.Host}";

View File

@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.RazorPages;
using yaflay.ru.Models.Tables;
using yawaflua.ru.Models.Tables;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
public class BlogModel : PageModel
{

View File

@@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]

View File

@@ -1,4 +1,4 @@
@page "{uri?}"
@page
@model IndexModel
@{
ViewData["Title"] = "yawaflua";

View File

@@ -1,17 +1,16 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Caching.Memory;
using yaflay.ru.Models;
using yaflay.ru.Models.Tables;
using yawaflua.ru.Models;
using yawaflua.ru.Models.Tables;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IMemoryCache cache;
public AppDbContext ctx;
public string? uri { get; set; } = null;
public IndexModel(ILogger<IndexModel> logger, IMemoryCache cache, AppDbContext ctx)
{
_logger = logger;
@@ -19,28 +18,11 @@ namespace yaflay.ru.Pages
this.ctx = ctx;
}
public void OnGet(string? uri)
public void OnGet()
{
Page();
this.uri = uri ?? null;
Console.WriteLine(uri);
if (this.uri != null)
{
Redirects? fromCache = cache.Get<Redirects>($"redirectsWithUrl-{uri}") ?? null;
if (fromCache == null)
{
fromCache = ctx.Redirects.FirstOrDefault(k => k.uri == uri);
Console.WriteLine("Im here!");
if (fromCache != null)
cache.Set($"redirectsWithUrl-{uri}", (object)fromCache, DateTime.Now.AddMinutes(10));
}
Console.WriteLine(fromCache?.ToString());
Response.Redirect(fromCache?.redirectTo ?? "/404");
}
else
{
Page();
}
}
}

View File

@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
public class Index1Model : PageModel
{

View File

@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace yaflay.ru.Pages
namespace yawaflua.ru.Pages
{
public class PrivacyModel : PageModel
{

View File

@@ -1,3 +1,3 @@
@using yaflay.ru
@namespace yaflay.ru.Pages
@using yawaflua.ru
@namespace yawaflua.ru.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

12
Pages/rrobotsTxt.cshtml Normal file
View File

@@ -0,0 +1,12 @@
@page
@{
Layout = null;
this.Response.ContentType = "text/plain";
}
User-agent: *
<environment include="Development,Staging">Disallow: /*</environment>
<environment include="Production">Disallow: /* </environment>
<environment include="Production">Allow: /Blog </environment>
<environment include="Production">Allow: /Blog/* </environment>
<environment include="Production">Allow: /Privacy </environment>
<environment include="Production">Allow: / </environment>