diff --git a/PhoneToolMX.Models/Data/PTMXContext.cs b/PhoneToolMX.Models/Data/PTMXContext.cs index 0db822b..c7401b9 100644 --- a/PhoneToolMX.Models/Data/PTMXContext.cs +++ b/PhoneToolMX.Models/Data/PTMXContext.cs @@ -79,6 +79,9 @@ namespace PhoneToolMX.Data { ext.HasKey(x => x.Id); ext.Property(x => x.Id).UseIdentityColumn(); ext.Property(x => x.ExtId).HasComputedColumnSql("\"Id\" + 1000", stored: true); + ext + .Property(p => p.Password) + .HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')"); var phone = modelBuilder.Entity(); phone @@ -87,9 +90,6 @@ namespace PhoneToolMX.Data { phone.HasKey(p => p.Id); phone.Property(p => p.Id).UseIdentityColumn(); // Randomly generates a 24-char password - phone - .Property(p => p.Password) - .HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')"); // Wallpapers, ringtones, etc var cd = modelBuilder.Entity(); diff --git a/PhoneToolMX.Models/Migrations/20231020040540_ExtensionPassword.Designer.cs b/PhoneToolMX.Models/Migrations/20231020040540_ExtensionPassword.Designer.cs new file mode 100644 index 0000000..9cdce86 --- /dev/null +++ b/PhoneToolMX.Models/Migrations/20231020040540_ExtensionPassword.Designer.cs @@ -0,0 +1,358 @@ +// +using System; +using System.Net.NetworkInformation; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PhoneToolMX.Data; + +#nullable disable + +namespace PhoneToolMX.Models.Migrations +{ + [DbContext(typeof(PTMXContext))] + [Migration("20231020040540_ExtensionPassword")] + partial class ExtensionPassword + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.23") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ExtensionPhone", b => + { + b.Property("ExtensionsId") + .HasColumnType("integer"); + + b.Property("PhonesId") + .HasColumnType("integer"); + + b.HasKey("ExtensionsId", "PhonesId"); + + b.HasIndex("PhonesId"); + + b.ToTable("ExtensionPhone"); + }); + + modelBuilder.Entity("ExtensionUser", b => + { + b.Property("ExtensionsId") + .HasColumnType("integer"); + + b.Property("OwnersId") + .HasColumnType("text"); + + b.HasKey("ExtensionsId", "OwnersId"); + + b.HasIndex("OwnersId"); + + b.ToTable("ExtensionUser"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.CustomData", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Data") + .HasColumnType("bytea"); + + b.Property("DataType") + .HasColumnType("integer"); + + b.Property("FriendlyName") + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("PhoneId") + .HasColumnType("integer"); + + b.Property("Size") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("PhoneId"); + + b.ToTable("CustomData"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.Extension", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DirectoryName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ExtId") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("integer") + .HasComputedColumnSql("\"Id\" + 1000", true); + + b.Property("HoldMusicId") + .HasColumnType("integer"); + + b.Property("Listed") + .HasColumnType("boolean"); + + b.Property("Password") + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')"); + + b.HasKey("Id"); + + b.HasIndex("HoldMusicId"); + + b.ToTable("Extensions"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.Phone", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BackgroundId") + .HasColumnType("integer"); + + b.Property("FriendlyName") + .IsRequired() + .HasColumnType("text"); + + b.Property("MacAddress") + .IsRequired() + .HasColumnType("macaddr"); + + b.Property("ModelId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BackgroundId"); + + b.HasIndex("ModelId"); + + b.ToTable("Phones"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.PhoneModel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("MaxExtensions") + .HasColumnType("bigint"); + + b.Property("ModelName") + .HasColumnType("text"); + + b.Property("PreVvxPolycom") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.ToTable("PhoneModels"); + + b.HasData( + new + { + Id = 0, + MaxExtensions = 6L, + ModelName = "Polycom VVX300/310", + PreVvxPolycom = false + }); + }); + + modelBuilder.Entity("PhoneToolMX.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("NormalizedName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Role"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.User", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasColumnType("text"); + + b.Property("NormalizedUserName") + .HasColumnType("text"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("PhoneUser", b => + { + b.Property("OwnersId") + .HasColumnType("text"); + + b.Property("PhonesId") + .HasColumnType("integer"); + + b.HasKey("OwnersId", "PhonesId"); + + b.HasIndex("PhonesId"); + + b.ToTable("PhoneUser"); + }); + + modelBuilder.Entity("ExtensionPhone", b => + { + b.HasOne("PhoneToolMX.Models.Extension", null) + .WithMany() + .HasForeignKey("ExtensionsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PhoneToolMX.Models.Phone", null) + .WithMany() + .HasForeignKey("PhonesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ExtensionUser", b => + { + b.HasOne("PhoneToolMX.Models.Extension", null) + .WithMany() + .HasForeignKey("ExtensionsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PhoneToolMX.Models.User", null) + .WithMany() + .HasForeignKey("OwnersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("PhoneToolMX.Models.CustomData", b => + { + b.HasOne("PhoneToolMX.Models.Phone", null) + .WithMany("Ringtones") + .HasForeignKey("PhoneId"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.Extension", b => + { + b.HasOne("PhoneToolMX.Models.CustomData", "HoldMusic") + .WithMany() + .HasForeignKey("HoldMusicId"); + + b.Navigation("HoldMusic"); + }); + + modelBuilder.Entity("PhoneToolMX.Models.Phone", b => + { + b.HasOne("PhoneToolMX.Models.CustomData", "Background") + .WithMany() + .HasForeignKey("BackgroundId"); + + b.HasOne("PhoneToolMX.Models.PhoneModel", "Model") + .WithMany() + .HasForeignKey("ModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Background"); + + b.Navigation("Model"); + }); + + modelBuilder.Entity("PhoneUser", b => + { + b.HasOne("PhoneToolMX.Models.User", null) + .WithMany() + .HasForeignKey("OwnersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PhoneToolMX.Models.Phone", null) + .WithMany() + .HasForeignKey("PhonesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("PhoneToolMX.Models.Phone", b => + { + b.Navigation("Ringtones"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PhoneToolMX.Models/Migrations/20231020040540_ExtensionPassword.cs b/PhoneToolMX.Models/Migrations/20231020040540_ExtensionPassword.cs new file mode 100644 index 0000000..b40da8a --- /dev/null +++ b/PhoneToolMX.Models/Migrations/20231020040540_ExtensionPassword.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PhoneToolMX.Models.Migrations +{ + public partial class ExtensionPassword : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Password", + table: "Phones"); + + migrationBuilder.AddColumn( + name: "Password", + table: "Extensions", + type: "text", + nullable: true, + defaultValueSql: "encode(gen_random_bytes(18), 'base64')"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Password", + table: "Extensions"); + + migrationBuilder.AddColumn( + name: "Password", + table: "Phones", + type: "text", + nullable: true, + defaultValueSql: "encode(gen_random_bytes(18), 'base64')"); + } + } +} diff --git a/PhoneToolMX.Models/Migrations/PTMXContextModelSnapshot.cs b/PhoneToolMX.Models/Migrations/PTMXContextModelSnapshot.cs index 5bcb161..47245c4 100644 --- a/PhoneToolMX.Models/Migrations/PTMXContextModelSnapshot.cs +++ b/PhoneToolMX.Models/Migrations/PTMXContextModelSnapshot.cs @@ -18,7 +18,7 @@ namespace PhoneToolMX.Models.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.16") + .HasAnnotation("ProductVersion", "6.0.23") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -35,7 +35,7 @@ namespace PhoneToolMX.Models.Migrations b.HasIndex("PhonesId"); - b.ToTable("ExtensionPhone", (string)null); + b.ToTable("ExtensionPhone"); }); modelBuilder.Entity("ExtensionUser", b => @@ -50,16 +50,16 @@ namespace PhoneToolMX.Models.Migrations b.HasIndex("OwnersId"); - b.ToTable("ExtensionUser", (string)null); + b.ToTable("ExtensionUser"); }); modelBuilder.Entity("PhoneToolMX.Models.CustomData", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Data") .HasColumnType("bytea"); @@ -81,7 +81,7 @@ namespace PhoneToolMX.Models.Migrations b.HasIndex("PhoneId"); - b.ToTable("CustomData", (string)null); + b.ToTable("CustomData"); }); modelBuilder.Entity("PhoneToolMX.Models.Extension", b => @@ -107,11 +107,16 @@ namespace PhoneToolMX.Models.Migrations b.Property("Listed") .HasColumnType("boolean"); + b.Property("Password") + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')"); + b.HasKey("Id"); b.HasIndex("HoldMusicId"); - b.ToTable("Extensions", (string)null); + b.ToTable("Extensions"); }); modelBuilder.Entity("PhoneToolMX.Models.Phone", b => @@ -136,18 +141,13 @@ namespace PhoneToolMX.Models.Migrations b.Property("ModelId") .HasColumnType("integer"); - b.Property("Password") - .ValueGeneratedOnAdd() - .HasColumnType("text") - .HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')"); - b.HasKey("Id"); b.HasIndex("BackgroundId"); b.HasIndex("ModelId"); - b.ToTable("Phones", (string)null); + b.ToTable("Phones"); }); modelBuilder.Entity("PhoneToolMX.Models.PhoneModel", b => @@ -169,7 +169,7 @@ namespace PhoneToolMX.Models.Migrations b.HasKey("Id"); - b.ToTable("PhoneModels", (string)null); + b.ToTable("PhoneModels"); b.HasData( new @@ -198,7 +198,7 @@ namespace PhoneToolMX.Models.Migrations b.HasKey("Id"); - b.ToTable("Role", (string)null); + b.ToTable("Role"); }); modelBuilder.Entity("PhoneToolMX.Models.User", b => @@ -250,7 +250,7 @@ namespace PhoneToolMX.Models.Migrations b.HasKey("Id"); - b.ToTable("Users", (string)null); + b.ToTable("Users"); }); modelBuilder.Entity("PhoneUser", b => @@ -265,7 +265,7 @@ namespace PhoneToolMX.Models.Migrations b.HasIndex("PhonesId"); - b.ToTable("PhoneUser", (string)null); + b.ToTable("PhoneUser"); }); modelBuilder.Entity("ExtensionPhone", b => diff --git a/PhoneToolMX.Models/Models/Extension.cs b/PhoneToolMX.Models/Models/Extension.cs index 822d042..faedccb 100644 --- a/PhoneToolMX.Models/Models/Extension.cs +++ b/PhoneToolMX.Models/Models/Extension.cs @@ -21,5 +21,7 @@ namespace PhoneToolMX.Models { [NotMapped] public string ListViewName => $"{DirectoryName} ({ExtId})"; + + public string Password { get; set; } } } \ No newline at end of file diff --git a/PhoneToolMX.Models/Models/Phone.cs b/PhoneToolMX.Models/Models/Phone.cs index abc5fad..c396439 100644 --- a/PhoneToolMX.Models/Models/Phone.cs +++ b/PhoneToolMX.Models/Models/Phone.cs @@ -23,6 +23,5 @@ namespace PhoneToolMX.Models { public ICollection Extensions { get; set; } public CustomData Background { get; set; } public ICollection Ringtones { get; set; } - public string Password { get; set; } } } \ No newline at end of file diff --git a/PhoneToolMX.Models/PhoneToolMX.Models.csproj b/PhoneToolMX.Models/PhoneToolMX.Models.csproj index 62e3384..fb12075 100644 --- a/PhoneToolMX.Models/PhoneToolMX.Models.csproj +++ b/PhoneToolMX.Models/PhoneToolMX.Models.csproj @@ -4,6 +4,8 @@ net6.0 enable disable + Debug;Release + AnyCPU;x64 diff --git a/PhoneToolMX/PhoneToolMX.csproj b/PhoneToolMX/PhoneToolMX.csproj index 8b8fa58..83189c1 100644 --- a/PhoneToolMX/PhoneToolMX.csproj +++ b/PhoneToolMX/PhoneToolMX.csproj @@ -3,6 +3,8 @@ net6.0 enable + Debug;Release + AnyCPU;x64