Ajoutez des fichiers projet.
This commit is contained in:
50
Tagger/Service/PageProvider.cs
Normal file
50
Tagger/Service/PageProvider.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Tagger/Service/UserManager.cs
Normal file
14
Tagger/Service/UserManager.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user