Ajoutez des fichiers projet.

This commit is contained in:
taywon18
2024-09-19 22:06:37 +02:00
parent 7420a47dc6
commit 70fe271ba4
39 changed files with 1605 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using Tagger.Data;
namespace Tagger.Service;
public class PageProvider
{
const string PageDirPath = "Pages";
public PageProvider()
{
Directory.CreateDirectory(PageDirPath);
}
public MarkdownPage? Get(string name)
{
string path = Path.Combine(PageDirPath, name);
if (!File.Exists(path))
return null;
return new()
{
Title = name,
Content = File.ReadAllText(path)
};
}
public void Save(MarkdownPage page)
{
string path = Path.Combine(PageDirPath, page.Title);
File.Delete(path);
File.WriteAllText(path, page.Content);
}
public void Delete(string name)
{
string path = Path.Combine(PageDirPath, name);
File.Delete(path);
}
public IEnumerable<string> List()
{
foreach(var i in Directory.GetFiles(PageDirPath))
{
//FileInfo fi = new(i);
yield return i.Substring(PageDirPath.Length+1);
}
}
}

View File

@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Components.Authorization;
namespace Tagger.Service;
public class UserManager
{
public async Task<bool> IsLogged(AuthenticationStateProvider stateProvider)
{
var authState = await stateProvider.GetAuthenticationStateAsync();
var user = authState.User;
return (user.Identity is not null && user.Identity.IsAuthenticated);
}
}