SES-88 Created User register connection

This commit is contained in:
Łukasz Góreczny 2020-12-13 19:27:28 +01:00
parent 79f6bede98
commit 2b4cd79484
21 changed files with 1455 additions and 58 deletions

View File

@ -0,0 +1,683 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SessionCompanion.Database;
namespace SessionCompanion.Database.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20201213175031_Username column rename")]
partial class Usernamecolumnrename
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.UseIdentityColumns()
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.0");
modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.HasKey("Id");
b.ToTable("Alignments");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Background", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.HasKey("Id");
b.ToTable("Backgrounds");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("AlignmentId")
.HasColumnType("int");
b.Property<int>("BackgroundId")
.HasColumnType("int");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("ClassId")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int>("RaceId")
.HasColumnType("int");
b.Property<string>("Sex")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AlignmentId");
b.HasIndex("BackgroundId");
b.HasIndex("CharacterId")
.IsUnique();
b.HasIndex("ClassId");
b.HasIndex("RaceId");
b.ToTable("Biographies");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Characters");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Charisma", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<bool>("CanDeception")
.HasColumnType("bit");
b.Property<bool>("CanIntimidation")
.HasColumnType("bit");
b.Property<bool>("CanPerformance")
.HasColumnType("bit");
b.Property<bool>("CanPersuasion")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Deception")
.HasColumnType("int");
b.Property<int>("Intimidation")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("Performance")
.HasColumnType("int");
b.Property<int>("Persuasion")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Charismas");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Classes");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Constitution", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Constitutions");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Dexterity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("Acrobatics")
.HasColumnType("int");
b.Property<bool>("CanAcrobatics")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<bool>("CanSleightOfHand")
.HasColumnType("bit");
b.Property<bool>("CanStealth")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("SleightOfHand")
.HasColumnType("int");
b.Property<int>("Stealth")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Dexterities");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Intelligence", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("Arcana")
.HasColumnType("int");
b.Property<bool>("CanArcana")
.HasColumnType("bit");
b.Property<bool>("CanHistory")
.HasColumnType("bit");
b.Property<bool>("CanInvestigation")
.HasColumnType("bit");
b.Property<bool>("CanNature")
.HasColumnType("bit");
b.Property<bool>("CanReligion")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("History")
.HasColumnType("int");
b.Property<int>("Investigation")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("Nature")
.HasColumnType("int");
b.Property<int>("Religion")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Intelligences");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Races");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("ArmorClass")
.HasColumnType("int");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("CurrentHealthPoints")
.HasColumnType("int");
b.Property<int>("ExperiencePoints")
.HasColumnType("int");
b.Property<int>("HealthPoints")
.HasColumnType("int");
b.Property<int>("Initiative")
.HasColumnType("int");
b.Property<int>("Level")
.HasColumnType("int");
b.Property<int>("Proficiency")
.HasColumnType("int");
b.Property<int>("Speed")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Statistics");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Strength", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("Athletics")
.HasColumnType("int");
b.Property<bool>("CanAthletics")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Strengths");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<string>("Password")
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users");
b.HasData(
new
{
Id = 1,
Password = "123",
Username = "Morwiec"
},
new
{
Id = 2,
Password = "123",
Username = "Cichoklepiec"
},
new
{
Id = 3,
Password = "123",
Username = "Ruletka"
});
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Wisdom", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("AnimalHandling")
.HasColumnType("int");
b.Property<bool>("CanAnimalHandling")
.HasColumnType("bit");
b.Property<bool>("CanInsight")
.HasColumnType("bit");
b.Property<bool>("CanMedicine")
.HasColumnType("bit");
b.Property<bool>("CanPerception")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<bool>("CanSurvival")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Insight")
.HasColumnType("int");
b.Property<int>("Medicine")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("Perception")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Survival")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Wisdoms");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Alignment", "Alignment")
.WithMany("Biography")
.HasForeignKey("AlignmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SessionCompanion.Database.Tables.Background", "Background")
.WithMany("Biography")
.HasForeignKey("BackgroundId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Biography")
.HasForeignKey("SessionCompanion.Database.Tables.Biography", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SessionCompanion.Database.Tables.Class", "Class")
.WithMany("Biography")
.HasForeignKey("ClassId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SessionCompanion.Database.Tables.Race", "Race")
.WithMany("Biography")
.HasForeignKey("RaceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Alignment");
b.Navigation("Background");
b.Navigation("Character");
b.Navigation("Class");
b.Navigation("Race");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b =>
{
b.HasOne("SessionCompanion.Database.Tables.User", "User")
.WithMany("Character")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Charisma", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Charisma")
.HasForeignKey("SessionCompanion.Database.Tables.Charisma", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Constitution", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Constitution")
.HasForeignKey("SessionCompanion.Database.Tables.Constitution", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Dexterity", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Dexterity")
.HasForeignKey("SessionCompanion.Database.Tables.Dexterity", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Intelligence", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Intelligence")
.HasForeignKey("SessionCompanion.Database.Tables.Intelligence", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Statistics")
.HasForeignKey("SessionCompanion.Database.Tables.Statistics", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Strength", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Strength")
.HasForeignKey("SessionCompanion.Database.Tables.Strength", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Wisdom", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Wisdom")
.HasForeignKey("SessionCompanion.Database.Tables.Wisdom", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b =>
{
b.Navigation("Biography");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Background", b =>
{
b.Navigation("Biography");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b =>
{
b.Navigation("Biography");
b.Navigation("Charisma");
b.Navigation("Constitution");
b.Navigation("Dexterity");
b.Navigation("Intelligence");
b.Navigation("Statistics");
b.Navigation("Strength");
b.Navigation("Wisdom");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b =>
{
b.Navigation("Biography");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b =>
{
b.Navigation("Biography");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.User", b =>
{
b.Navigation("Character");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,251 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace SessionCompanion.Database.Migrations
{
public partial class Usernamecolumnrename : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Nickname",
table: "Users",
newName: "Username");
migrationBuilder.CreateTable(
name: "Charismas",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CharacterId = table.Column<int>(type: "int", nullable: false),
Value = table.Column<int>(type: "int", nullable: false),
Modification = table.Column<int>(type: "int", nullable: false),
SavingThrows = table.Column<int>(type: "int", nullable: false),
CanSaveThrows = table.Column<bool>(type: "bit", nullable: false),
Deception = table.Column<int>(type: "int", nullable: false),
CanDeception = table.Column<bool>(type: "bit", nullable: false),
Intimidation = table.Column<int>(type: "int", nullable: false),
CanIntimidation = table.Column<bool>(type: "bit", nullable: false),
Performance = table.Column<int>(type: "int", nullable: false),
CanPerformance = table.Column<bool>(type: "bit", nullable: false),
Persuasion = table.Column<int>(type: "int", nullable: false),
CanPersuasion = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Charismas", x => x.Id);
table.ForeignKey(
name: "FK_Charismas_Characters_CharacterId",
column: x => x.CharacterId,
principalTable: "Characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Constitutions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CharacterId = table.Column<int>(type: "int", nullable: false),
Value = table.Column<int>(type: "int", nullable: false),
Modification = table.Column<int>(type: "int", nullable: false),
SavingThrows = table.Column<int>(type: "int", nullable: false),
CanSaveThrows = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Constitutions", x => x.Id);
table.ForeignKey(
name: "FK_Constitutions_Characters_CharacterId",
column: x => x.CharacterId,
principalTable: "Characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Dexterities",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CharacterId = table.Column<int>(type: "int", nullable: false),
Value = table.Column<int>(type: "int", nullable: false),
Modification = table.Column<int>(type: "int", nullable: false),
SavingThrows = table.Column<int>(type: "int", nullable: false),
CanSaveThrows = table.Column<bool>(type: "bit", nullable: false),
Acrobatics = table.Column<int>(type: "int", nullable: false),
CanAcrobatics = table.Column<bool>(type: "bit", nullable: false),
SleightOfHand = table.Column<int>(type: "int", nullable: false),
CanSleightOfHand = table.Column<bool>(type: "bit", nullable: false),
Stealth = table.Column<int>(type: "int", nullable: false),
CanStealth = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Dexterities", x => x.Id);
table.ForeignKey(
name: "FK_Dexterities_Characters_CharacterId",
column: x => x.CharacterId,
principalTable: "Characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Intelligences",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CharacterId = table.Column<int>(type: "int", nullable: false),
Value = table.Column<int>(type: "int", nullable: false),
Modification = table.Column<int>(type: "int", nullable: false),
SavingThrows = table.Column<int>(type: "int", nullable: false),
CanSaveThrows = table.Column<bool>(type: "bit", nullable: false),
Arcana = table.Column<int>(type: "int", nullable: false),
CanArcana = table.Column<bool>(type: "bit", nullable: false),
History = table.Column<int>(type: "int", nullable: false),
CanHistory = table.Column<bool>(type: "bit", nullable: false),
Investigation = table.Column<int>(type: "int", nullable: false),
CanInvestigation = table.Column<bool>(type: "bit", nullable: false),
Nature = table.Column<int>(type: "int", nullable: false),
CanNature = table.Column<bool>(type: "bit", nullable: false),
Religion = table.Column<int>(type: "int", nullable: false),
CanReligion = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Intelligences", x => x.Id);
table.ForeignKey(
name: "FK_Intelligences_Characters_CharacterId",
column: x => x.CharacterId,
principalTable: "Characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Strengths",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CharacterId = table.Column<int>(type: "int", nullable: false),
Value = table.Column<int>(type: "int", nullable: false),
Modification = table.Column<int>(type: "int", nullable: false),
SavingThrows = table.Column<int>(type: "int", nullable: false),
CanSaveThrows = table.Column<bool>(type: "bit", nullable: false),
Athletics = table.Column<int>(type: "int", nullable: false),
CanAthletics = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Strengths", x => x.Id);
table.ForeignKey(
name: "FK_Strengths_Characters_CharacterId",
column: x => x.CharacterId,
principalTable: "Characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Wisdoms",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CharacterId = table.Column<int>(type: "int", nullable: false),
Value = table.Column<int>(type: "int", nullable: false),
Modification = table.Column<int>(type: "int", nullable: false),
SavingThrows = table.Column<int>(type: "int", nullable: false),
CanSaveThrows = table.Column<bool>(type: "bit", nullable: false),
AnimalHandling = table.Column<int>(type: "int", nullable: false),
CanAnimalHandling = table.Column<bool>(type: "bit", nullable: false),
Insight = table.Column<int>(type: "int", nullable: false),
CanInsight = table.Column<bool>(type: "bit", nullable: false),
Medicine = table.Column<int>(type: "int", nullable: false),
CanMedicine = table.Column<bool>(type: "bit", nullable: false),
Perception = table.Column<int>(type: "int", nullable: false),
CanPerception = table.Column<bool>(type: "bit", nullable: false),
Survival = table.Column<int>(type: "int", nullable: false),
CanSurvival = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Wisdoms", x => x.Id);
table.ForeignKey(
name: "FK_Wisdoms_Characters_CharacterId",
column: x => x.CharacterId,
principalTable: "Characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Charismas_CharacterId",
table: "Charismas",
column: "CharacterId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Constitutions_CharacterId",
table: "Constitutions",
column: "CharacterId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Dexterities_CharacterId",
table: "Dexterities",
column: "CharacterId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Intelligences_CharacterId",
table: "Intelligences",
column: "CharacterId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Strengths_CharacterId",
table: "Strengths",
column: "CharacterId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Wisdoms_CharacterId",
table: "Wisdoms",
column: "CharacterId",
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Charismas");
migrationBuilder.DropTable(
name: "Constitutions");
migrationBuilder.DropTable(
name: "Dexterities");
migrationBuilder.DropTable(
name: "Intelligences");
migrationBuilder.DropTable(
name: "Strengths");
migrationBuilder.DropTable(
name: "Wisdoms");
migrationBuilder.RenameColumn(
name: "Username",
table: "Users",
newName: "Nickname");
}
}
}

View File

@ -103,6 +103,60 @@ namespace SessionCompanion.Database.Migrations
b.ToTable("Characters"); b.ToTable("Characters");
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Charisma", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<bool>("CanDeception")
.HasColumnType("bit");
b.Property<bool>("CanIntimidation")
.HasColumnType("bit");
b.Property<bool>("CanPerformance")
.HasColumnType("bit");
b.Property<bool>("CanPersuasion")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Deception")
.HasColumnType("int");
b.Property<int>("Intimidation")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("Performance")
.HasColumnType("int");
b.Property<int>("Persuasion")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Charismas");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b => modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -118,6 +172,144 @@ namespace SessionCompanion.Database.Migrations
b.ToTable("Classes"); b.ToTable("Classes");
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Constitution", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Constitutions");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Dexterity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("Acrobatics")
.HasColumnType("int");
b.Property<bool>("CanAcrobatics")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<bool>("CanSleightOfHand")
.HasColumnType("bit");
b.Property<bool>("CanStealth")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("SleightOfHand")
.HasColumnType("int");
b.Property<int>("Stealth")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Dexterities");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Intelligence", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("Arcana")
.HasColumnType("int");
b.Property<bool>("CanArcana")
.HasColumnType("bit");
b.Property<bool>("CanHistory")
.HasColumnType("bit");
b.Property<bool>("CanInvestigation")
.HasColumnType("bit");
b.Property<bool>("CanNature")
.HasColumnType("bit");
b.Property<bool>("CanReligion")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("History")
.HasColumnType("int");
b.Property<int>("Investigation")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("Nature")
.HasColumnType("int");
b.Property<int>("Religion")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Intelligences");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b => modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -175,6 +367,42 @@ namespace SessionCompanion.Database.Migrations
b.ToTable("Statistics"); b.ToTable("Statistics");
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Strength", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("Athletics")
.HasColumnType("int");
b.Property<bool>("CanAthletics")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Strengths");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.User", b => modelBuilder.Entity("SessionCompanion.Database.Tables.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -182,10 +410,10 @@ namespace SessionCompanion.Database.Migrations
.HasColumnType("int") .HasColumnType("int")
.UseIdentityColumn(); .UseIdentityColumn();
b.Property<string>("Nickname") b.Property<string>("Password")
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<string>("Password") b.Property<string>("Username")
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.HasKey("Id"); b.HasKey("Id");
@ -196,23 +424,83 @@ namespace SessionCompanion.Database.Migrations
new new
{ {
Id = 1, Id = 1,
Nickname = "Morwiec", Password = "123",
Password = "123" Username = "Morwiec"
}, },
new new
{ {
Id = 2, Id = 2,
Nickname = "Cichoklepiec", Password = "123",
Password = "123" Username = "Cichoklepiec"
}, },
new new
{ {
Id = 3, Id = 3,
Nickname = "Ruletka", Password = "123",
Password = "123" Username = "Ruletka"
}); });
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Wisdom", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.UseIdentityColumn();
b.Property<int>("AnimalHandling")
.HasColumnType("int");
b.Property<bool>("CanAnimalHandling")
.HasColumnType("bit");
b.Property<bool>("CanInsight")
.HasColumnType("bit");
b.Property<bool>("CanMedicine")
.HasColumnType("bit");
b.Property<bool>("CanPerception")
.HasColumnType("bit");
b.Property<bool>("CanSaveThrows")
.HasColumnType("bit");
b.Property<bool>("CanSurvival")
.HasColumnType("bit");
b.Property<int>("CharacterId")
.HasColumnType("int");
b.Property<int>("Insight")
.HasColumnType("int");
b.Property<int>("Medicine")
.HasColumnType("int");
b.Property<int>("Modification")
.HasColumnType("int");
b.Property<int>("Perception")
.HasColumnType("int");
b.Property<int>("SavingThrows")
.HasColumnType("int");
b.Property<int>("Survival")
.HasColumnType("int");
b.Property<int>("Value")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CharacterId")
.IsUnique();
b.ToTable("Wisdoms");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b => modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b =>
{ {
b.HasOne("SessionCompanion.Database.Tables.Alignment", "Alignment") b.HasOne("SessionCompanion.Database.Tables.Alignment", "Alignment")
@ -267,6 +555,50 @@ namespace SessionCompanion.Database.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Charisma", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Charisma")
.HasForeignKey("SessionCompanion.Database.Tables.Charisma", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Constitution", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Constitution")
.HasForeignKey("SessionCompanion.Database.Tables.Constitution", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Dexterity", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Dexterity")
.HasForeignKey("SessionCompanion.Database.Tables.Dexterity", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Intelligence", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Intelligence")
.HasForeignKey("SessionCompanion.Database.Tables.Intelligence", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b => modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b =>
{ {
b.HasOne("SessionCompanion.Database.Tables.Character", "Character") b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
@ -278,6 +610,28 @@ namespace SessionCompanion.Database.Migrations
b.Navigation("Character"); b.Navigation("Character");
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Strength", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Strength")
.HasForeignKey("SessionCompanion.Database.Tables.Strength", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Wisdom", b =>
{
b.HasOne("SessionCompanion.Database.Tables.Character", "Character")
.WithOne("Wisdom")
.HasForeignKey("SessionCompanion.Database.Tables.Wisdom", "CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Character");
});
modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b => modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b =>
{ {
b.Navigation("Biography"); b.Navigation("Biography");
@ -292,7 +646,19 @@ namespace SessionCompanion.Database.Migrations
{ {
b.Navigation("Biography"); b.Navigation("Biography");
b.Navigation("Charisma");
b.Navigation("Constitution");
b.Navigation("Dexterity");
b.Navigation("Intelligence");
b.Navigation("Statistics"); b.Navigation("Statistics");
b.Navigation("Strength");
b.Navigation("Wisdom");
}); });
modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b => modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b =>

View File

@ -17,19 +17,19 @@ namespace SessionCompanion.Database
new User new User
{ {
Id = 1, Id = 1,
Nickname = "Morwiec", Username = "Morwiec",
Password = "123" Password = "123"
}, },
new User new User
{ {
Id = 2, Id = 2,
Nickname = "Cichoklepiec", Username = "Cichoklepiec",
Password = "123" Password = "123"
}, },
new User new User
{ {
Id = 3, Id = 3,
Nickname = "Ruletka", Username = "Ruletka",
Password = "123" Password = "123"
} }
}; };

View File

@ -6,7 +6,7 @@ namespace SessionCompanion.Database.Tables
{ {
public class User : BaseEntity public class User : BaseEntity
{ {
public string Nickname { get; set; } public string Username { get; set; }
public string Password { get; set; } public string Password { get; set; }
public ICollection<Character> Character { get; set; } public ICollection<Character> Character { get; set; }
} }

View File

@ -72,7 +72,7 @@ public async Task<Either<CharacterViewModel, ErrorResponse>> Get(int id)
### Przypisanie nowej wartości ### Przypisanie nowej wartości
Jeśli z jakiegośpowodu będziemy chcieli zmienić wartość obiektu Either, musimy dokonać tego w taki oto sposób: Jeśli z jakiegośpowodu będziemy chcieli zmienić wartość obiektu Either, musimy dokonać tego w taki oto sposób:
```cs ```cs
UserViewModel user = new UserViewModel() { Id = 1, Nickname = "Testowy", Password = "Secret" }; UserViewModel user = new UserViewModel() { Id = 1, Username = "Testowy", Password = "Secret" };
Either<UserViewModel, string> test = "asd"; Either<UserViewModel, string> test = "asd";
// zmieniamy wartość Either // zmieniamy wartość Either
@ -80,13 +80,13 @@ test = user;
// Warto zauważyć, że możemy zmienić wartość obiektu znajdujacego się wewnątrz // Warto zauważyć, że możemy zmienić wartość obiektu znajdujacego się wewnątrz
// którejś ze zmiennej o ile jest on publiczny // którejś ze zmiennej o ile jest on publiczny
test.Left.Nickname = "test"; test.Left.Username = "test";
// Jednak jeśli dokonamy tego po zmianie wartości obietu na inny pomimo tego, że // Jednak jeśli dokonamy tego po zmianie wartości obietu na inny pomimo tego, że
// dla kodu jest to ok, to nie zadziała to poprawnie, ponieważ wartość starego obiektu // dla kodu jest to ok, to nie zadziała to poprawnie, ponieważ wartość starego obiektu
// jest zmieniana na null(dla boola na false) // jest zmieniana na null(dla boola na false)
test = "asd"; test = "asd";
test.Left.Nickname = "b³¹d"; test.Left.Username = "b³¹d";
``` ```

View File

@ -10,6 +10,6 @@ namespace SessionCompanion.Services.Interfaces
{ {
public interface IUserService : IServiceBase<UserViewModel, User> public interface IUserService : IServiceBase<UserViewModel, User>
{ {
Task<UserViewModel> SearchUserByNickname(string userName); Task<UserViewModel> SearchUserByUsername(string userName);
} }
} }

View File

@ -18,9 +18,9 @@ namespace SessionCompanion.Services.Services
public UserService(IMapper mapper, IRepository<User> repository) : base(mapper, repository) public UserService(IMapper mapper, IRepository<User> repository) : base(mapper, repository)
{ } { }
public async Task<UserViewModel> SearchUserByNickname(string userName) public async Task<UserViewModel> SearchUserByUsername(string userName)
{ {
var User = await Repository.Get(u => u.Nickname.Equals(userName)).FirstOrDefaultAsync(); var User = await Repository.Get(u => u.Username.Equals(userName)).FirstOrDefaultAsync();
return Mapper.Map<UserViewModel>(User); return Mapper.Map<UserViewModel>(User);
} }
} }

View File

@ -485,12 +485,22 @@
Czy postać posiada biegłość w atletyce Czy postać posiada biegłość w atletyce
</summary> </summary>
</member> </member>
<member name="P:SessionCompanion.ViewModels.UserViewModels.UserRegisterViewModel.Username">
<summary>
Nazwa użytkowika
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.UserViewModels.UserRegisterViewModel.Password">
<summary>
Hasło użytkownika
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.UserViewModels.UserViewModel.Id"> <member name="P:SessionCompanion.ViewModels.UserViewModels.UserViewModel.Id">
<summary> <summary>
Identyfikator użytkownika Identyfikator użytkownika
</summary> </summary>
</member> </member>
<member name="P:SessionCompanion.ViewModels.UserViewModels.UserViewModel.Nickname"> <member name="P:SessionCompanion.ViewModels.UserViewModels.UserViewModel.Username">
<summary> <summary>
Nazwa użytkowika Nazwa użytkowika
</summary> </summary>

View File

@ -0,0 +1,19 @@
namespace SessionCompanion.ViewModels.UserViewModels
{
using System.ComponentModel.DataAnnotations;
public class UserRegisterViewModel
{
/// <summary>
/// Nazwa użytkowika
/// </summary>
[Required]
public string Username { get; set; }
/// <summary>
/// Hasło użytkownika
/// </summary>
[Required]
public string Password { get; set; }
}
}

View File

@ -10,7 +10,7 @@
/// <summary> /// <summary>
/// Nazwa użytkowika /// Nazwa użytkowika
/// </summary> /// </summary>
public string Nickname { get; set; } public string Username { get; set; }
/// <summary> /// <summary>
/// Hasło użytkownika /// Hasło użytkownika

View File

@ -48,10 +48,14 @@
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<mat-error *ngIf="apiError">
{{apiErrorMessage}}
</mat-error>
<button <button
mat-raised-button mat-raised-button
class="btn-primary form-container" class="btn-primary form-container"
(click)="GoToLoginPage()"> (click)="Register()">
<mat-icon matSuffix class="arrow-forward">arrow_forward</mat-icon> <mat-icon matSuffix class="arrow-forward">arrow_forward</mat-icon>
</button> </button>
</div> </div>

View File

@ -1,16 +1,24 @@
import { Component } from '@angular/core'; import {Component, OnDestroy} from '@angular/core';
import { FormGroup, ValidationErrors, ValidatorFn, Validators, FormBuilder } from '@angular/forms'; import { FormGroup, ValidationErrors, ValidatorFn, Validators, FormBuilder } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import {UserService} from '../../../services/user.service';
import {Subscription} from 'rxjs';
import {ErrorResponse} from '../../../types/ErrorResponse';
import {UserRegisterViewModel} from '../../../types/viewmodels/user-viewmodels/UserRegisterViewModel';
import {HttpErrorResponse} from '@angular/common/http';
import {type} from 'os';
@Component({ @Component({
selector: 'app-registration', selector: 'app-registration',
templateUrl: './registration.component.html', templateUrl: './registration.component.html',
styleUrls: ['./registration.component.css'] styleUrls: ['./registration.component.css']
}) })
export class RegistrationComponent { export class RegistrationComponent implements OnDestroy {
constructor(private router: Router, private formBuilder: FormBuilder) {} allSubscriptions = new Subscription();
constructor(private router: Router, private formBuilder: FormBuilder, private userService: UserService) {}
isExpanded = false; apiError = false;
apiErrorMessage = '';
public signUpFormGroup: FormGroup = this.formBuilder.group({ public signUpFormGroup: FormGroup = this.formBuilder.group({
newAccount: this.formBuilder.group({ newAccount: this.formBuilder.group({
@ -23,22 +31,42 @@ export class RegistrationComponent {
}) })
}); });
collapse() {
this.isExpanded = false;
}
GoToLoginPage() { GoToLoginPage() {
this.router.navigate(['login']) this.router.navigate(['login']);
} }
toggle() { Register() {
this.isExpanded = !this.isExpanded; const userRegisterModel = new class implements UserRegisterViewModel {
password: string;
username: string;
};
userRegisterModel.username = this.signUpFormGroup.get('newAccount').value['username'];
userRegisterModel.password = this.signUpFormGroup.get('newAccount').value['password'];
this.allSubscriptions.add(
this.userService.registerUser(userRegisterModel).subscribe(
() => {
this.router.navigate(['login']);
},
(error: ErrorResponse | HttpErrorResponse) => {
if (error instanceof HttpErrorResponse) {
error = error.error as ErrorResponse;
}
this.apiError = true;
this.apiErrorMessage = error.message;
}
));
}
ngOnDestroy() {
this.allSubscriptions.unsubscribe();
} }
} }
export const passwordMatchValidator: ValidatorFn = (formGroup: FormGroup): ValidationErrors | null => { export const passwordMatchValidator: ValidatorFn = (formGroup: FormGroup): ValidationErrors | null => {
const parent = formGroup.parent as FormGroup; const parent = formGroup.parent as FormGroup;
if (!parent) return null; if (!parent) { return null; }
return parent.get('password').value === parent.get('confirmPassword').value ? return parent.get('password').value === parent.get('confirmPassword').value ?
null : { 'mismatch': true }; null : { 'mismatch': true };
} };

View File

@ -4,6 +4,7 @@ import { Router } from '@angular/router';
import {UserService} from '../../../services/user.service'; import {UserService} from '../../../services/user.service';
import {ErrorResponse} from '../../../types/ErrorResponse'; import {ErrorResponse} from '../../../types/ErrorResponse';
import {Subscription} from 'rxjs'; import {Subscription} from 'rxjs';
import {HttpErrorResponse} from '@angular/common/http';
@Component({ @Component({
selector: 'app-sign-in', selector: 'app-sign-in',
@ -36,10 +37,13 @@ export class SignInComponent implements OnDestroy {
(success) => { (success) => {
this.router.navigate(['player']); this.router.navigate(['player']);
}, },
(error: ErrorResponse) => { (error: ErrorResponse | HttpErrorResponse) => {
this.apiError = true; if (error instanceof HttpErrorResponse) {
this.apiErrorMessage = error.message; error = error.error as ErrorResponse;
} }
this.apiError = true;
this.apiErrorMessage = error.message;
}
)); ));
} }

View File

@ -4,6 +4,8 @@ import {Observable, of, throwError} from 'rxjs';
import {ErrorResponse} from '../types/ErrorResponse'; import {ErrorResponse} from '../types/ErrorResponse';
import {Either} from '../types/Either'; import {Either} from '../types/Either';
import {switchMap} from 'rxjs/operators'; import {switchMap} from 'rxjs/operators';
import {SuccessResponse} from '../types/SuccessResponse';
import {UserRegisterViewModel} from '../types/viewmodels/user-viewmodels/UserRegisterViewModel';
Injectable({ Injectable({
providedIn: 'root' providedIn: 'root'
@ -28,4 +30,16 @@ export class UserService {
}) })
); );
} }
registerUser(userRegisterModel: UserRegisterViewModel): Observable<SuccessResponse> {
return this.http.post<Either<SuccessResponse, ErrorResponse>>(this.baseUrl + 'register', userRegisterModel).pipe(
switchMap(response => {
if (response.isLeft) {
return of(response.left);
} else {
return throwError(response.right);
}
})
);
}
} }

View File

@ -1,4 +1,4 @@
export interface ErrorResponse { export interface ErrorResponse {
code: number; statusCode: number;
message: string; message: string;
} }

View File

@ -0,0 +1,4 @@
export interface SuccessResponse {
code: number;
message: string;
}

View File

@ -0,0 +1,4 @@
export interface UserRegisterViewModel {
username: string;
password: string;
}

View File

@ -34,11 +34,11 @@ namespace SessionCompanion.Configurations
{ {
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return context.Response.WriteAsync(new ErrorResponse()
{ string response = "{\"statusCode\":" + context.Response.StatusCode + ",\"message\":\"" + exception.Message
StatusCode = context.Response.StatusCode, + "\"}";
Message = exception.Message
}.ToString()); return context.Response.WriteAsync(response);
} }
} }
} }

View File

@ -2,11 +2,11 @@
using SessionCompanion.Services.Interfaces; using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.UserViewModels; using SessionCompanion.ViewModels.UserViewModels;
using System.Threading.Tasks; using System.Threading.Tasks;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.ApiResponses;
namespace SessionCompanion.Controllers namespace SessionCompanion.Controllers
{ {
using System;
using SessionCompanion.Extensions.EitherType; using SessionCompanion.Extensions.EitherType;
using SessionCompanion.ViewModels.ApiResponses; using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.UserViewModels; using SessionCompanion.ViewModels.UserViewModels;
@ -31,7 +31,7 @@ namespace SessionCompanion.Controllers
[HttpGet("login")] [HttpGet("login")]
public async Task<Either<int, ErrorResponse>> Login(string userName, string password) public async Task<Either<int, ErrorResponse>> Login(string userName, string password)
{ {
UserViewModel user = await _service.SearchUserByNickname(userName); UserViewModel user = await _service.SearchUserByUsername(userName);
if (user != null && user.Password.Equals(password)) if (user != null && user.Password.Equals(password))
{ {
@ -49,24 +49,27 @@ namespace SessionCompanion.Controllers
/// <summary> /// <summary>
/// Metoda rejestruje podanego użytkownika /// Metoda rejestruje podanego użytkownika
/// </summary> /// </summary>
/// <param name="model"> Model uzytkownika do zarejestrowania </param> /// <param name="userRegisterModel"> Model uzytkownika do zarejestrowania </param>
/// <returns> SuccessResponse/ErrorResponse </returns> /// <returns> SuccessResponse/ErrorResponse </returns>
[HttpPost("register")] [HttpPost("register")]
public async Task<Either<SuccessResponse, ErrorResponse>> Register(UserViewModel model) public async Task<Either<SuccessResponse, ErrorResponse>> Register(UserRegisterViewModel userRegisterModel)
{ {
if(!ModelState.IsValid) if (!ModelState.IsValid)
return new ErrorResponse() {
{ return new ErrorResponse() { StatusCode = 400, Message = "Given model is incorect" };
StatusCode = 400, }
Message = "Given model is incorect"
}; UserViewModel userModel = new UserViewModel()
{
await _service.Create(model); Password = userRegisterModel.Password,
Username = userRegisterModel.Username
};
await _service.Create(userModel);
await _service.SaveAsync(); await _service.SaveAsync();
return new SuccessResponse("User created"); return new SuccessResponse("User created");
} }
} }
} }

View File

@ -19,6 +19,13 @@
<param name="password"> Hasło </param> <param name="password"> Hasło </param>
<returns>Id użytkownika lub wiadomość błędu</returns> <returns>Id użytkownika lub wiadomość błędu</returns>
</member> </member>
<member name="M:SessionCompanion.Controllers.UserController.Register(SessionCompanion.ViewModels.UserViewModels.UserRegisterViewModel)">
<summary>
Metoda rejestruje podanego użytkownika
</summary>
<param name="userRegisterModel"> Model uzytkownika do zarejestrowania </param>
<returns> SuccessResponse/ErrorResponse </returns>
</member>
<member name="F:SessionCompanion.Hubs.SessionHub.ConnectedCharacters"> <member name="F:SessionCompanion.Hubs.SessionHub.ConnectedCharacters">
<summary> <summary>
Lista zalogowanych graczy i identyfikator wybranej postaci Lista zalogowanych graczy i identyfikator wybranej postaci