diff --git a/ZpcBulletinBoard/Classes/Global.cs b/ZpcBulletinBoard/Classes/Global.cs new file mode 100644 index 0000000..4f9cc49 --- /dev/null +++ b/ZpcBulletinBoard/Classes/Global.cs @@ -0,0 +1,36 @@ +namespace ZpcBulletinBoard.Classes +{ + public static class Global + { + public static T GetAttributeOfType(this Enum iEnumType) where T : System.Attribute + { + var type = iEnumType.GetType(); + var memberInfo = type.GetMember(iEnumType.ToString()); + var atributi = memberInfo[0].GetCustomAttributes(typeof(T), false); + return (atributi.Length > 0) ? (T)atributi[0] : null; + } + + public static List<(int EnumValue, T EnumAttribute)> GetEnumListClass(this Type iEnumType, + bool iUseOrder = false) where T : System.Attribute + { + List<(int EnumValue, T EnumAttribute)> titleValue = new(); + + foreach (var tempEnumValue in Enum.GetValues(iEnumType).Cast()) + { + object tempObject = GetAttributeOfType(tempEnumValue); + + titleValue.Add((Convert.ToInt32(tempEnumValue), (T)tempObject)); + } + + return titleValue.ToList(); + } + + public static TAttribute GetAttribute(Enum value) + where TAttribute : Attribute + { + var enumType = value.GetType(); + var name = Enum.GetName(enumType, value); + return enumType.GetField(name)?.GetCustomAttributes(false).OfType().SingleOrDefault(); + } + } +} diff --git a/ZpcBulletinBoard/Data/ApplicationDbContext.cs b/ZpcBulletinBoard/Data/ApplicationDbContext.cs index f52c7f3..e70a294 100644 --- a/ZpcBulletinBoard/Data/ApplicationDbContext.cs +++ b/ZpcBulletinBoard/Data/ApplicationDbContext.cs @@ -22,9 +22,14 @@ namespace ZpcBulletinBoard.Data //Relacije modelBuilder.Entity() - .HasMany(t => t.Notes) + .HasMany(t => t.Pages) .WithOne(t => t.BulletinBoard) .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasMany(t => t.Notes) + .WithOne(t => t.BulletinBoardPage) + .OnDelete(DeleteBehavior.Cascade); } } } diff --git a/ZpcBulletinBoard/Dockerfile.env b/ZpcBulletinBoard/Dockerfile.env new file mode 100644 index 0000000..c1e22bf --- /dev/null +++ b/ZpcBulletinBoard/Dockerfile.env @@ -0,0 +1,4 @@ +MYSQL_SERVER=192.168.1.12 +MYSQL_USER=david +MYSQL_PASSWORD=*staleker* +MYSQL_DATABASE=ZpcBulletinBoard \ No newline at end of file diff --git a/ZpcBulletinBoard/Keys/key-3a63e3da-2ef0-49c2-9e68-30571c991f22.xml b/ZpcBulletinBoard/Keys/key-3a63e3da-2ef0-49c2-9e68-30571c991f22.xml new file mode 100644 index 0000000..068fa30 --- /dev/null +++ b/ZpcBulletinBoard/Keys/key-3a63e3da-2ef0-49c2-9e68-30571c991f22.xml @@ -0,0 +1,16 @@ + + + 2024-02-27T04:54:17.6808298Z + 2024-02-27T04:54:17.6419309Z + 2024-05-27T04:54:17.6419309Z + + + + + + + 1ujUNFqnvXGLHSTiSV2F9ymK+Sosgl6qdy7m0M/Z9bPXyplHR9bOAgm4cy5otT3C/q5H/Qf6NnQkgUqggldGiw== + + + + \ No newline at end of file diff --git a/ZpcBulletinBoard/Migrations/20240227053725_3.Designer.cs b/ZpcBulletinBoard/Migrations/20240227053725_3.Designer.cs new file mode 100644 index 0000000..60687f6 --- /dev/null +++ b/ZpcBulletinBoard/Migrations/20240227053725_3.Designer.cs @@ -0,0 +1,405 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ZpcBulletinBoard.Data; + +#nullable disable + +namespace ZpcBulletinBoard.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240227053725_3")] + partial class _3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ClaimType") + .HasColumnType("longtext"); + + b.Property("ClaimValue") + .HasColumnType("longtext"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ClaimType") + .HasColumnType("longtext"); + + b.Property("ClaimValue") + .HasColumnType("longtext"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("varchar(255)"); + + b.Property("ProviderKey") + .HasColumnType("varchar(255)"); + + b.Property("ProviderDisplayName") + .HasColumnType("longtext"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("LoginProvider") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("Value") + .HasColumnType("longtext"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b => + { + b.Property("IdBulletinBoard") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Guid") + .HasColumnType("char(36)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Ratio") + .HasColumnType("int"); + + b.HasKey("IdBulletinBoard"); + + b.ToTable("BulletinBoards"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b => + { + b.Property("IdBulletinBoardPage") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Duration") + .HasColumnType("int"); + + b.Property("IdBulletinBoard") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("IdBulletinBoardPage"); + + b.HasIndex("IdBulletinBoard"); + + b.ToTable("BulletinBoardPage"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => + { + b.Property("IdNote") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Content") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Height") + .HasColumnType("int"); + + b.Property("IdBulletinBoardPage") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Width") + .HasColumnType("int"); + + b.Property("X") + .HasColumnType("int"); + + b.Property("Y") + .HasColumnType("int"); + + b.HasKey("IdNote"); + + b.HasIndex("IdBulletinBoardPage"); + + b.ToTable("Notes"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.IdentityApplicationRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Active") + .HasColumnType("tinyint(1)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.IdentityApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("Active") + .HasColumnType("tinyint(1)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("longtext"); + + b.Property("DateCreated") + .HasColumnType("datetime(6)"); + + b.Property("DateValidUntil") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnd") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("longtext"); + + b.Property("PhoneNumber") + .HasColumnType("longtext"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("SecurityStamp") + .HasColumnType("longtext"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TwoFactorEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b => + { + b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoard", "BulletinBoard") + .WithMany("Pages") + .HasForeignKey("IdBulletinBoard") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BulletinBoard"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => + { + b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", "BulletinBoardPage") + .WithMany("Notes") + .HasForeignKey("IdBulletinBoardPage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BulletinBoardPage"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b => + { + b.Navigation("Pages"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b => + { + b.Navigation("Notes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ZpcBulletinBoard/Migrations/20240227053725_3.cs b/ZpcBulletinBoard/Migrations/20240227053725_3.cs new file mode 100644 index 0000000..4179692 --- /dev/null +++ b/ZpcBulletinBoard/Migrations/20240227053725_3.cs @@ -0,0 +1,94 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ZpcBulletinBoard.Migrations +{ + /// + public partial class _3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Notes_BulletinBoards_IdBulletinBoard", + table: "Notes"); + + migrationBuilder.RenameColumn( + name: "IdBulletinBoard", + table: "Notes", + newName: "IdBulletinBoardPage"); + + migrationBuilder.RenameIndex( + name: "IX_Notes_IdBulletinBoard", + table: "Notes", + newName: "IX_Notes_IdBulletinBoardPage"); + + migrationBuilder.CreateTable( + name: "BulletinBoardPage", + columns: table => new + { + IdBulletinBoardPage = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + IdBulletinBoard = table.Column(type: "int", nullable: false), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Duration = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BulletinBoardPage", x => x.IdBulletinBoardPage); + table.ForeignKey( + name: "FK_BulletinBoardPage_BulletinBoards_IdBulletinBoard", + column: x => x.IdBulletinBoard, + principalTable: "BulletinBoards", + principalColumn: "IdBulletinBoard", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_BulletinBoardPage_IdBulletinBoard", + table: "BulletinBoardPage", + column: "IdBulletinBoard"); + + migrationBuilder.AddForeignKey( + name: "FK_Notes_BulletinBoardPage_IdBulletinBoardPage", + table: "Notes", + column: "IdBulletinBoardPage", + principalTable: "BulletinBoardPage", + principalColumn: "IdBulletinBoardPage", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Notes_BulletinBoardPage_IdBulletinBoardPage", + table: "Notes"); + + migrationBuilder.DropTable( + name: "BulletinBoardPage"); + + migrationBuilder.RenameColumn( + name: "IdBulletinBoardPage", + table: "Notes", + newName: "IdBulletinBoard"); + + migrationBuilder.RenameIndex( + name: "IX_Notes_IdBulletinBoardPage", + table: "Notes", + newName: "IX_Notes_IdBulletinBoard"); + + migrationBuilder.AddForeignKey( + name: "FK_Notes_BulletinBoards_IdBulletinBoard", + table: "Notes", + column: "IdBulletinBoard", + principalTable: "BulletinBoards", + principalColumn: "IdBulletinBoard", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/ZpcBulletinBoard/Migrations/ApplicationDbContextModelSnapshot.cs b/ZpcBulletinBoard/Migrations/ApplicationDbContextModelSnapshot.cs index c9536bf..3427f62 100644 --- a/ZpcBulletinBoard/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/ZpcBulletinBoard/Migrations/ApplicationDbContextModelSnapshot.cs @@ -139,6 +139,29 @@ namespace ZpcBulletinBoard.Migrations b.ToTable("BulletinBoards"); }); + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b => + { + b.Property("IdBulletinBoardPage") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Duration") + .HasColumnType("int"); + + b.Property("IdBulletinBoard") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("IdBulletinBoardPage"); + + b.HasIndex("IdBulletinBoard"); + + b.ToTable("BulletinBoardPage"); + }); + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => { b.Property("IdNote") @@ -152,7 +175,7 @@ namespace ZpcBulletinBoard.Migrations b.Property("Height") .HasColumnType("int"); - b.Property("IdBulletinBoard") + b.Property("IdBulletinBoardPage") .HasColumnType("int"); b.Property("Title") @@ -170,7 +193,7 @@ namespace ZpcBulletinBoard.Migrations b.HasKey("IdNote"); - b.HasIndex("IdBulletinBoard"); + b.HasIndex("IdBulletinBoardPage"); b.ToTable("Notes"); }); @@ -342,10 +365,10 @@ namespace ZpcBulletinBoard.Migrations .IsRequired(); }); - modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b => { b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoard", "BulletinBoard") - .WithMany("Notes") + .WithMany("Pages") .HasForeignKey("IdBulletinBoard") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -353,7 +376,23 @@ namespace ZpcBulletinBoard.Migrations b.Navigation("BulletinBoard"); }); + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => + { + b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", "BulletinBoardPage") + .WithMany("Notes") + .HasForeignKey("IdBulletinBoardPage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("BulletinBoardPage"); + }); + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b => + { + b.Navigation("Pages"); + }); + + modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b => { b.Navigation("Notes"); }); diff --git a/ZpcBulletinBoard/Models/Editor/BulletinBoard.cs b/ZpcBulletinBoard/Models/Editor/BulletinBoard.cs index dd54ed6..aea33bf 100644 --- a/ZpcBulletinBoard/Models/Editor/BulletinBoard.cs +++ b/ZpcBulletinBoard/Models/Editor/BulletinBoard.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using ZpcBulletinBoard.Classes; namespace ZpcBulletinBoard.Models.Editor { @@ -29,9 +30,11 @@ namespace ZpcBulletinBoard.Models.Editor [Display(Name = "Razmerje")] public RatioEnum Ratio { get; set; } + [NotMapped] public string RatioString => Ratio.GetAttributeOfType().Name ?? ""; + // InvoicePart [InverseProperty("BulletinBoard")] - public virtual ICollection Notes { get; set; } + public virtual ICollection Pages { get; set; } } } diff --git a/ZpcBulletinBoard/Models/Editor/BulletinBoardPage.cs b/ZpcBulletinBoard/Models/Editor/BulletinBoardPage.cs new file mode 100644 index 0000000..816573e --- /dev/null +++ b/ZpcBulletinBoard/Models/Editor/BulletinBoardPage.cs @@ -0,0 +1,31 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ZpcBulletinBoard.Models.Editor +{ + public class BulletinBoardPage + { + + [Key] + public int IdBulletinBoardPage { get; set; } + + [Required] + [ForeignKey("BulletinBoard")] + public int IdBulletinBoard { get; set; } + + [Required] + [Display(Name = "Ime")] + public string Name { get; set; } + + [Required] + [Display(Name = "Trajanje")] + public int Duration { get; set; } + + // ForeignKey + public BulletinBoard BulletinBoard { get; set; } + + + [InverseProperty("BulletinBoardPage")] + public virtual ICollection Notes { get; set; } + } +} diff --git a/ZpcBulletinBoard/Models/Editor/Note.cs b/ZpcBulletinBoard/Models/Editor/Note.cs index d1500a5..457c128 100644 --- a/ZpcBulletinBoard/Models/Editor/Note.cs +++ b/ZpcBulletinBoard/Models/Editor/Note.cs @@ -9,8 +9,8 @@ namespace ZpcBulletinBoard.Models.Editor public int IdNote { get; set; } [Required] - [ForeignKey("BulletinBoard")] - public int IdBulletinBoard { get; set; } + [ForeignKey("BulletinBoardPage")] + public int IdBulletinBoardPage { get; set; } [Required] public int X { get; set; } @@ -31,6 +31,6 @@ namespace ZpcBulletinBoard.Models.Editor public string Content { get; set; } // ForeignKey - public BulletinBoard BulletinBoard{ get; set; } + public BulletinBoardPage BulletinBoardPage { get; set; } } } diff --git a/ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml.cs b/ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml.cs index 5c0e628..ad590ea 100644 --- a/ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml.cs +++ b/ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml.cs @@ -36,13 +36,13 @@ namespace ZpcBulletinBoard.Pages.Boards { Ratio = BulletinBoard.RatioEnum.Ratio16To9, Guid = Guid.NewGuid(), - Notes = new List() + Pages = new List() }; return Page(); } - var tmpBoard = await context.BulletinBoards.Include(x => x.Notes) + var tmpBoard = await context.BulletinBoards.Include(x => x.Pages) .FirstOrDefaultAsync(m => m.Guid == guid); diff --git a/ZpcBulletinBoard/Pages/Boards/Index.cshtml.cs b/ZpcBulletinBoard/Pages/Boards/Index.cshtml.cs index e47449d..9714321 100644 --- a/ZpcBulletinBoard/Pages/Boards/Index.cshtml.cs +++ b/ZpcBulletinBoard/Pages/Boards/Index.cshtml.cs @@ -11,7 +11,7 @@ using ZpcBulletinBoard.Models.Editor; namespace ZpcBulletinBoard.Pages.Boards { - //[Authorize] + [Authorize] public class IndexModel(ApplicationDbContext context) : PageModel { public IList Boards { get;set; } diff --git a/ZpcBulletinBoard/Pages/Editor/EditMain.cshtml b/ZpcBulletinBoard/Pages/Editor/EditMain.cshtml index 9797105..fdcc498 100644 --- a/ZpcBulletinBoard/Pages/Editor/EditMain.cshtml +++ b/ZpcBulletinBoard/Pages/Editor/EditMain.cshtml @@ -15,13 +15,8 @@
-
-
+ + @@ -64,10 +64,6 @@
- -
- Ste pozabili geslo? Kliknite tukaj za ponastavitev -
diff --git a/ZpcBulletinBoard/Program.cs b/ZpcBulletinBoard/Program.cs index 4e9ade3..59521bd 100644 --- a/ZpcBulletinBoard/Program.cs +++ b/ZpcBulletinBoard/Program.cs @@ -29,6 +29,7 @@ using Microsoft.EntityFrameworkCore; //using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.HttpOverrides; using ZpcBulletinBoard.Data; +using ZpcBulletinBoard.Models; var builder = WebApplication.CreateBuilder(args); @@ -36,9 +37,61 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); +//TODO before publish var connectionString = builder.Configuration.GetConnectionString("DataConnection"); +//var sqlHost = Environment.GetEnvironmentVariable("MYSQL_SERVER"); +//var sqlUser = Environment.GetEnvironmentVariable("MYSQL_USER"); +//var sqlPassword = Environment.GetEnvironmentVariable("MYSQL_PASSWORD"); +//var sqlDatabase = Environment.GetEnvironmentVariable("MYSQL_DATABASE"); + +//var connectionString = $"server={sqlHost};user={sqlUser};password={sqlPassword};database={sqlDatabase};SSL Mode=None"; + builder.Services.AddDbContext(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))); +builder.Services.AddIdentity().AddEntityFrameworkStores().AddDefaultTokenProviders(); +builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN"); + +builder.Services.Configure(options => +{ + // Password settings + options.Password.RequireDigit = true; + options.Password.RequireLowercase = true; + options.Password.RequireNonAlphanumeric = true; + options.Password.RequireUppercase = true; + options.Password.RequiredLength = 8; + options.Password.RequiredUniqueChars = 1; + + // Lockout settings + options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); + options.Lockout.MaxFailedAccessAttempts = 3; + options.Lockout.AllowedForNewUsers = true; + + // User settings + options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + options.User.RequireUniqueEmail = true; +}); + +builder.Services.ConfigureApplicationCookie(options => +{ + // Cookie + options.Cookie.MaxAge = TimeSpan.FromHours(3); + options.Cookie.HttpOnly = true; + options.SlidingExpiration = true; + options.Cookie.SecurePolicy = CookieSecurePolicy.None;//Samo unencripted na locas + + options.LoginPath = $"/User/Login"; + options.LogoutPath = $"/User/Logout"; + options.AccessDeniedPath = $"/"; + options.ExpireTimeSpan = TimeSpan.FromMinutes(15);//Povecano na 15min +}); + +builder.Services.Configure(options => +{ + options.AutomaticAuthentication = false; +}); + +builder.Services.AddDataProtection().SetApplicationName("ZpcBulletinBoard").PersistKeysToFileSystem(new DirectoryInfo(@"Keys/")); + var app = builder.Build(); //app.UseStaticFiles(new StaticFileOptions @@ -55,6 +108,15 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } +var defaultCulture = new CultureInfo("sl-SI"); +var localizationOptions = new RequestLocalizationOptions +{ + DefaultRequestCulture = new RequestCulture(defaultCulture), + SupportedCultures = new List { defaultCulture }, + SupportedUICultures = new List { defaultCulture } +}; +app.UseRequestLocalization(localizationOptions); + app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/ZpcBulletinBoard/ZpcBulletinBoard.csproj b/ZpcBulletinBoard/ZpcBulletinBoard.csproj index 7bde14d..ce6c437 100644 --- a/ZpcBulletinBoard/ZpcBulletinBoard.csproj +++ b/ZpcBulletinBoard/ZpcBulletinBoard.csproj @@ -6,6 +6,7 @@ enable 02904645-4084-486e-a036-9081aa0cef47 Linux + Dockerfile.env diff --git a/ZpcBulletinBoard/appsettings.json b/ZpcBulletinBoard/appsettings.json index 8415bbc..16381ed 100644 --- a/ZpcBulletinBoard/appsettings.json +++ b/ZpcBulletinBoard/appsettings.json @@ -7,6 +7,6 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "DataConnection": "server=192.168.1.12;user=david;password=*staleker*;database=ZpcBulletinBoard" + "DataConnection": "server=192.168.1.12;user=david;password=*staleker*;database=ZpcBulletinBoard;SSL Mode=None" } } diff --git a/ZpcBulletinBoard/wwwroot/js/editor/edit-main.js b/ZpcBulletinBoard/wwwroot/js/editor/edit-main.js index c1a6caf..fb5f9e4 100644 --- a/ZpcBulletinBoard/wwwroot/js/editor/edit-main.js +++ b/ZpcBulletinBoard/wwwroot/js/editor/edit-main.js @@ -1,31 +1,12 @@ $(function () { - loadBoard(); - loadNotes(); }); -const ratio = '16:9' let divCanvas; let canWidth; let canHeight; let notes = []; -function loadBoard(){ - let placeholder = $('#divPlaceholder'); - placeholder.empty(); - - let tmpSplit = ratio.split(':'); - canWidth = placeholder.width(); - canHeight = canWidth / (parseFloat(tmpSplit[0]) / parseFloat(tmpSplit[1])); - divCanvas = $(`
`); - placeholder.append(divCanvas); - divCanvas.css({ - 'width': '100%', - 'height': canHeight + 'px', - 'background-color': 'white', - 'padding': '5px' - }); -} function loadNotes(){ let note = new Note(1, divCanvas, 200, 0, 400, 240, '

Naslov


Test

' ); @@ -40,6 +21,18 @@ function loadNotes(){ }); } +function addNewNote(){ + let tmpId = -1; + notes.forEach(note => { + if (note.id <= tmpId){ + tmpId = note.id -1; + } + }); + let note = new Note(tmpId, divCanvas, 0, 0, 400, 240, 'Vnesi besedilo'); + notes.push(note); + note.refresh(); +} + function openModalEditNote(id){ $('#inpModalEditNoteIdNote').val(id); note = getNote(id); @@ -47,7 +40,7 @@ function openModalEditNote(id){ $('#divModalEditNote').modal('show'); $('#divModalEditNoteSummernote').summernote('destroy'); $('#divModalEditNoteSummernote').html(note.content); - $('#divModalEditNoteSummernote').summernote({}); + $('#divModalEditNoteSummernote').summernote({height: 400,}); } function saveModalEditNote(){ @@ -89,3 +82,78 @@ function svgTest(){ }); } +function openModalSelectBoard() { + $.blockUI(); + $.ajax({ + type: "GET", + url: "/Editor/EditMain/?handler=Boards", + data: { + }, + success: function (data) { + if (data.successful){ + let tmp = ''; + data.boards.forEach(element => { + tmp += ``; + tmp += '' + element.name + ''; + tmp += ''; + }); + $('#tbodyModalSelectBoard').html(tmp); + $('#divModalSelectBoard').modal('show'); + } else { + console.log(data); + alert(data); + } + $.unblockUI(); + }, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr); + alert(xhr.responseText); + $.unblockUI(); + } + }); +} + +function modalSelectBoardSelect(element){ + loadBoard(parseInt($(element).attr('data-id'))); + $('#divModalSelectBoard').modal('hide'); +} + +function loadBoard(id){ + $.blockUI(); + $.ajax({ + type: "GET", + url: "/Editor/EditMain/?handler=Board", + data: { + id + }, + success: function (data) { + if (data.successful){ + let placeholder = $('#divPlaceholder'); + placeholder.empty(); + console.log(data); + let tmpSplit = data.board.ratioString.split(':'); + canWidth = placeholder.width(); + canHeight = canWidth / (parseFloat(tmpSplit[0]) / parseFloat(tmpSplit[1])); + divCanvas = $(`
`); + placeholder.append(divCanvas); + divCanvas.css({ + 'width': '100%', + 'height': canHeight + 'px', + 'background-color': 'white', + 'padding': '5px' + }); + loadNotes(); + } else { + console.log(data); + alert(data); + } + $.unblockUI(); + }, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr); + alert(xhr.responseText); + $.unblockUI(); + } + }); +} +