refactoring the login

This commit is contained in:
Paul Schneider 2026-02-22 19:54:10 +00:00
commit 9289207085
18 changed files with 209 additions and 368 deletions

View file

@ -1,63 +1,85 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Yavsc;
using Yavsc.Abstract.Identity;
using Yavsc.Abstract.Identity.Security;
using Yavsc.Attributes.Validation;
using Yavsc.Interfaces;
using Yavsc.Models.Access;
using Yavsc.Models.Relationship;
using Yavsc.ViewModels.Blog;
namespace Yavsc.Models.Blog
{
public class BlogPost : BlogPostBase,
IBlogPost, ICircleAuthorized, ITaggable<long>
public class BlogPostEditViewModel : BlogPost
{
public BlogPostEditViewModel(BlogPost post, bool publish)
{
Id = post.Id;
AuthorId = post.AuthorId;
ACL = post.ACL;
Content = post.Content;
Title = post.Title;
Publish = publish;
}
public bool Publish { get; set; }
}
public class BlogPost :
IBlogPost, ICircleAuthorized, ITaggable<long>
{
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Display(Name="Identifiant du post")]
public long Id { get; set; }
[Display(Name = "Identifiant du post")]
public long Id { get; set; }
[Display(Name="Identifiant de l'auteur")]
[StringLength(1024)]
public string? Photo { get; set; }
[StringLength(1024)]
[Required]
public string Title { get; set; }
[StringLength(56224)]
public string? Content { get; set; }
[InverseProperty("Target")]
[Display(Name = "Liste de contrôle d'accès")]
public virtual List<CircleAuthorizationToBlogPost>? ACL { get; set; }
[Display(Name = "Identifiant de l'auteur")]
[ForeignKey("Author")]
public string? AuthorId { get; set; }
public string? AuthorId { get; set; }
[Display(Name="Auteur")]
public virtual ApplicationUser? Author { set; get; }
[Display(Name = "Auteur")]
public virtual ApplicationUser? Author { set; get; }
[Display(Name="Date de création")]
[Display(Name = "Date de création")]
public DateTime DateCreated
{
get; set;
}
[Display(Name="Créateur")]
[Display(Name = "Créateur")]
public string? UserCreated
{
get; set;
}
[Display(Name="Dernière modification")]
[Display(Name = "Dernière modification")]
public DateTime DateModified
{
get; set;
}
[Display(Name="Utilisateur ayant modifé le dernier")]
public string? UserModified
[Display(Name = "Utilisateur ayant modifé le dernier")]
public string? UserModified
{
get; set;
}
public bool AuthorizeCircle(long circleId)
{
return ACL?.Any( i=>i.CircleId == circleId) ?? true;
return ACL?.Any(i => i.CircleId == circleId) ?? true;
}
public ICircleAuthorization[] GetACL()
@ -67,26 +89,26 @@ namespace Yavsc.Models.Blog
public void Tag(Tag tag)
{
var existent = Tags.SingleOrDefault(t => t.PostId == Id && t.TagId == tag.Id);
if (existent==null) Tags.Add(new BlogTag { PostId = Id, Tag = tag } );
var existent = Tags.SingleOrDefault(t => t.PostId == Id && t.TagId == tag.Id);
if (existent == null) Tags.Add(new BlogTag { PostId = Id, Tag = tag });
}
public void DeTag(Tag tag)
{
var existent = Tags.SingleOrDefault(t => (( t.TagId == tag.Id) && t.PostId == Id));
if (existent!=null) Tags.Remove(existent);
var existent = Tags.SingleOrDefault(t => ((t.TagId == tag.Id) && t.PostId == Id));
if (existent != null) Tags.Remove(existent);
}
public string[] GetTags()
{
return Tags.Select(t=>t.Tag.Name).ToArray();
return Tags.Select(t => t.Tag.Name).ToArray();
}
[InverseProperty("Post")]
public virtual List<BlogTag> Tags { get; set; }
public virtual List<BlogTag> Tags { get; set; }
[InverseProperty("Post")]
public virtual List<Comment> Comments { get; set; }
public virtual List<Comment> Comments { get; set; }
IApplicationUser IBlogPost.Author { get => this.Author; }
}