add registratoin

main
Peace 7 months ago
parent d7f6994b45
commit b14cbb5d30
  1. 9
      PeacePDS/PeacePDS/Components/Pages/Account/Login.razor
  2. 66
      PeacePDS/PeacePDS/Components/Pages/Account/Registration.razor
  3. 6
      PeacePDS/PeacePDS/Data/AppDbContext.cs
  4. 312
      PeacePDS/PeacePDS/Migrations/20241007070709_InitialCreate.Designer.cs
  5. 240
      PeacePDS/PeacePDS/Migrations/20241007070709_InitialCreate.cs
  6. 315
      PeacePDS/PeacePDS/Migrations/20241007071344_fix-createdat.Designer.cs
  7. 30
      PeacePDS/PeacePDS/Migrations/20241007071344_fix-createdat.cs
  8. 312
      PeacePDS/PeacePDS/Migrations/AppDbContextModelSnapshot.cs
  9. 5
      PeacePDS/PeacePDS/Models/Entities/Affirmation.cs
  10. 22
      PeacePDS/PeacePDS/Models/Entities/DailyEntry.cs
  11. 22
      PeacePDS/PeacePDS/Models/Entities/DailyTask.cs
  12. 18
      PeacePDS/PeacePDS/Models/Entities/HabitCheck.cs
  13. 21
      PeacePDS/PeacePDS/Models/Entities/HabitTracker.cs
  14. 16
      PeacePDS/PeacePDS/Models/Entities/User.cs
  15. 4
      PeacePDS/PeacePDS/Models/Entities/UserPolicy.cs
  16. 1
      PeacePDS/PeacePDS/PeacePDS.csproj
  17. 2
      PeacePDS/PeacePDS/Responses/CustomResponses.cs
  18. 27
      PeacePDS/PeacePDS/Services/UserService.cs
  19. 15
      PeacePDS/PeacePDS/Utils/PasswordHasher.cs
  20. 3
      PeacePDS/PeacePDS/appsettings.Development.json
  21. 2
      PeacePDS/PeacePDS/appsettings.json

@ -15,11 +15,11 @@
</style> </style>
<FluentGrid Class="mt-3" Spacing="1" Justify="JustifyContent.Center"> <FluentGrid Class="mt-3" Spacing="1" Justify="JustifyContent.Center">
<FluentGridItem Class="py-4 border rounded" xs="12" sm="8" lg="4"> <FluentGridItem Class="py-4 border rounded-1" xs="12" sm="8" lg="4">
<FluentEditForm Model="@Model" OnSubmit="Authenticate" FormName="loginform"> <FluentEditForm Model="@Model" OnSubmit="Authenticate" FormName="loginform">
<DataAnnotationsValidator /> <DataAnnotationsValidator />
<FluentValidationSummary /> <FluentValidationSummary />
<FluentStack Orientation="Orientation.Vertical" VerticalGap="3" HorizontalAlignment="HorizontalAlignment.Center"> <FluentStack class="px-4" Orientation="Orientation.Vertical" VerticalGap="3" HorizontalAlignment="HorizontalAlignment.Center">
<div> <div>
<FluentEmoji Value="@(new Emojis.SmileysEmotion.Color.Default.GrinningFace())" Width="5rem" /> <FluentEmoji Value="@(new Emojis.SmileysEmotion.Color.Default.GrinningFace())" Width="5rem" />
<h3>LOGIN</h3> <h3>LOGIN</h3>
@ -34,6 +34,7 @@
</div> </div>
<FluentLabel class="fullwidth" Color="Color.Warning">@errorMessage?.ToString()</FluentLabel> <FluentLabel class="fullwidth" Color="Color.Warning">@errorMessage?.ToString()</FluentLabel>
<FluentButton class="fullwidth" Type="ButtonType.Submit" Appearance="Appearance.Accent">Login</FluentButton> <FluentButton class="fullwidth" Type="ButtonType.Submit" Appearance="Appearance.Accent">Login</FluentButton>
<FluentAnchor class="fullwidth" Href="/registration" Appearance="Appearance.Neutral">Join</FluentAnchor>
</FluentStack> </FluentStack>
</FluentEditForm> </FluentEditForm>
</FluentGridItem> </FluentGridItem>
@ -60,10 +61,10 @@
var claims = new List<Claim> var claims = new List<Claim>
{ {
new Claim(ClaimTypes.Name, loginResponse.user.Name), new Claim(ClaimTypes.Name, loginResponse.User.Name),
}; };
foreach (var policy in loginResponse.policies) foreach (var policy in loginResponse.User.UserPolicies)
claims.Add(new Claim(policy.Policy, "true")); claims.Add(new Claim(policy.Policy, "true"));
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

@ -0,0 +1,66 @@
@page "/registration"
@using System.Security.Claims
@using PeacePDS.Models.ViewModels
@using PeacePDS.Services
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication.Cookies
@using Microsoft.EntityFrameworkCore
@inject IUserService UserService
@inject NavigationManager NavManager
<style>
.fullwidth {
width:100%
}
</style>
<FluentGrid Class="mt-3" Spacing="1" Justify="JustifyContent.Center">
<FluentGridItem Class="py-4 border rounded-1" xs="12" sm="8" lg="4">
<FluentEditForm Model="@Model" OnSubmit="Authenticate" FormName="registrationform">
<DataAnnotationsValidator />
<FluentValidationSummary />
<FluentStack class="px-4" Orientation="Orientation.Vertical" VerticalGap="3" HorizontalAlignment="HorizontalAlignment.Center">
<div>
<FluentEmoji Value="@(new Emojis.SmileysEmotion.Color.Default.GrinningFace())" Width="5rem" />
<h3>registration</h3>
</div>
<div class="fullwidth">
<FluentTextField class="fullwidth" Style="width:100%" Name="Model.UserName" @bind-Value="Model.UserName" Label="User name" Placeholder="User name" Required />
<ValidationMessage class="fullwidth" For="@(() => Model.UserName)" />
</div>
<div class="fullwidth">
<FluentTextField class="fullwidth" Name="Model.Password" @bind-Value="Model.Password" TextFieldType="TextFieldType.Password" Label="password" Placeholder="Password" Required />
<ValidationMessage class="fullwidth" For="@(() => Model.Password)" />
</div>
<div class="fullwidth">
<FluentTextField class="fullwidth" Name="Model.ConfirmPassword" @bind-Value="Model.ConfirmPassword" TextFieldType="TextFieldType.Password" Label="password" Placeholder="Password" Required />
<ValidationMessage class="fullwidth" For="@(() => Model.ConfirmPassword)" />
</div>
<FluentLabel class="fullwidth" Color="Color.Warning">@errorMessage?.ToString()</FluentLabel>
<FluentButton class="fullwidth" Type="ButtonType.Submit" Appearance="Appearance.Accent">Join</FluentButton>
</FluentStack>
</FluentEditForm>
</FluentGridItem>
</FluentGrid>
@code {
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
[SupplyParameterFromForm]
public RegisterViewModel Model { get; set; } = new();
private string? errorMessage;
private async Task Authenticate()
{
RegistrationResponse registrationResponse = await UserService.RegisterAsync(Model);
if (!registrationResponse.Success)
{
errorMessage = registrationResponse.Message;
return;
}
NavManager.NavigateTo("/login");
}
}

@ -12,6 +12,10 @@ namespace PeacePDS.Data
public DbSet<User> Users { get; set; } public DbSet<User> Users { get; set; }
public DbSet<UserPolicy> UserPolicies { get; set; } public DbSet<UserPolicy> UserPolicies { get; set; }
public DbSet<Product> Products { get; set; } public DbSet<Affirmation> Affirmations { get; set; }
public DbSet<HabitTracker> HabitTrackers { get; set; }
public DbSet<HabitCheck> HabitChecks { get; set; }
public DbSet<DailyTask> DailyTasks { get; set; }
public DbSet<DailyEntry> DailyEntries { get; set; }
} }
} }

@ -0,0 +1,312 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PeacePDS.Data;
#nullable disable
namespace PeacePDS.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20241007070709_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
modelBuilder.Entity("PeacePDS.Models.Entities.Affirmation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AffirmationWord")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("Month")
.HasColumnType("datetime(6)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Affirmations");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyEntry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Compliment")
.HasColumnType("longtext");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("EntryDate")
.HasColumnType("datetime(6)");
b.Property<string>("Gratitude")
.HasColumnType("longtext");
b.Property<string>("Journal")
.HasColumnType("longtext");
b.Property<string>("Reflection")
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DailyEntries");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyTask", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("Date")
.HasColumnType("datetime(6)");
b.Property<bool>("IsCompleted")
.HasColumnType("tinyint(1)");
b.Property<string>("TaskName")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DailyTasks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitCheck", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CheckDate")
.HasColumnType("datetime(6)");
b.Property<int>("HabitTrackerId")
.HasColumnType("int");
b.Property<bool>("IsCompleted")
.HasColumnType("tinyint(1)");
b.HasKey("Id");
b.HasIndex("HabitTrackerId");
b.ToTable("HabitChecks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("HabitName")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("Month")
.HasColumnType("datetime(6)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("HabitTrackers");
});
modelBuilder.Entity("PeacePDS.Models.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("HashedPassword")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("varchar(255)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("PeacePDS.Models.Entities.UserPolicy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("IsEnable")
.HasColumnType("tinyint(1)");
b.Property<string>("Policy")
.HasMaxLength(50)
.HasColumnType("varchar(50)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserPolicies");
});
modelBuilder.Entity("PeacePDS.Models.Entities.Affirmation", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("Affirmations")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyEntry", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("DailyEntries")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyTask", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("DailyTasks")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitCheck", b =>
{
b.HasOne("PeacePDS.Models.Entities.HabitTracker", "HabitTracker")
.WithMany("HabitChecks")
.HasForeignKey("HabitTrackerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("HabitTracker");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("HabitTrackers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.UserPolicy", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("UserPolicies")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.Navigation("HabitChecks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.User", b =>
{
b.Navigation("Affirmations");
b.Navigation("DailyEntries");
b.Navigation("DailyTasks");
b.Navigation("HabitTrackers");
b.Navigation("UserPolicies");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,240 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PeacePDS.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
HashedPassword = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Affirmations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
Month = table.Column<DateTime>(type: "datetime(6)", nullable: false),
AffirmationWord = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Affirmations", x => x.Id);
table.ForeignKey(
name: "FK_Affirmations_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "DailyEntries",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
EntryDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Compliment = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Reflection = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Gratitude = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Journal = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DailyEntries", x => x.Id);
table.ForeignKey(
name: "FK_DailyEntries_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "DailyTasks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
Date = table.Column<DateTime>(type: "datetime(6)", nullable: false),
TaskName = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
IsCompleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DailyTasks", x => x.Id);
table.ForeignKey(
name: "FK_DailyTasks_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "HabitTrackers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
HabitName = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Month = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_HabitTrackers", x => x.Id);
table.ForeignKey(
name: "FK_HabitTrackers_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "UserPolicies",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<int>(type: "int", nullable: false),
Policy = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
IsEnable = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserPolicies", x => x.Id);
table.ForeignKey(
name: "FK_UserPolicies_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "HabitChecks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
HabitTrackerId = table.Column<int>(type: "int", nullable: false),
CheckDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
IsCompleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_HabitChecks", x => x.Id);
table.ForeignKey(
name: "FK_HabitChecks_HabitTrackers_HabitTrackerId",
column: x => x.HabitTrackerId,
principalTable: "HabitTrackers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Affirmations_UserId",
table: "Affirmations",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_DailyEntries_UserId",
table: "DailyEntries",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_DailyTasks_UserId",
table: "DailyTasks",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_HabitChecks_HabitTrackerId",
table: "HabitChecks",
column: "HabitTrackerId");
migrationBuilder.CreateIndex(
name: "IX_HabitTrackers_UserId",
table: "HabitTrackers",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_UserPolicies_UserId",
table: "UserPolicies",
column: "UserId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Affirmations");
migrationBuilder.DropTable(
name: "DailyEntries");
migrationBuilder.DropTable(
name: "DailyTasks");
migrationBuilder.DropTable(
name: "HabitChecks");
migrationBuilder.DropTable(
name: "UserPolicies");
migrationBuilder.DropTable(
name: "HabitTrackers");
migrationBuilder.DropTable(
name: "Users");
}
}
}

@ -0,0 +1,315 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PeacePDS.Data;
#nullable disable
namespace PeacePDS.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20241007071344_fix-createdat")]
partial class fixcreatedat
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
modelBuilder.Entity("PeacePDS.Models.Entities.Affirmation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AffirmationWord")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("Month")
.HasColumnType("datetime(6)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Affirmations");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyEntry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Compliment")
.HasColumnType("longtext");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("EntryDate")
.HasColumnType("datetime(6)");
b.Property<string>("Gratitude")
.HasColumnType("longtext");
b.Property<string>("Journal")
.HasColumnType("longtext");
b.Property<string>("Reflection")
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DailyEntries");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyTask", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("Date")
.HasColumnType("datetime(6)");
b.Property<bool>("IsCompleted")
.HasColumnType("tinyint(1)");
b.Property<string>("TaskName")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DailyTasks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitCheck", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CheckDate")
.HasColumnType("datetime(6)");
b.Property<int>("HabitTrackerId")
.HasColumnType("int");
b.Property<bool>("IsCompleted")
.HasColumnType("tinyint(1)");
b.HasKey("Id");
b.HasIndex("HabitTrackerId");
b.ToTable("HabitChecks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("HabitName")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("Month")
.HasColumnType("datetime(6)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("HabitTrackers");
});
modelBuilder.Entity("PeacePDS.Models.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("HashedPassword")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("varchar(255)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("PeacePDS.Models.Entities.UserPolicy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<bool>("IsEnable")
.HasColumnType("tinyint(1)");
b.Property<string>("Policy")
.HasMaxLength(50)
.HasColumnType("varchar(50)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserPolicies");
});
modelBuilder.Entity("PeacePDS.Models.Entities.Affirmation", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("Affirmations")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyEntry", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("DailyEntries")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyTask", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("DailyTasks")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitCheck", b =>
{
b.HasOne("PeacePDS.Models.Entities.HabitTracker", "HabitTracker")
.WithMany("HabitChecks")
.HasForeignKey("HabitTrackerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("HabitTracker");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("HabitTrackers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.UserPolicy", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("UserPolicies")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.Navigation("HabitChecks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.User", b =>
{
b.Navigation("Affirmations");
b.Navigation("DailyEntries");
b.Navigation("DailyTasks");
b.Navigation("HabitTrackers");
b.Navigation("UserPolicies");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,30 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PeacePDS.Migrations
{
/// <inheritdoc />
public partial class fixcreatedat : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "UserPolicies",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "UserPolicies");
}
}
}

@ -0,0 +1,312 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PeacePDS.Data;
#nullable disable
namespace PeacePDS.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
modelBuilder.Entity("PeacePDS.Models.Entities.Affirmation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AffirmationWord")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("Month")
.HasColumnType("datetime(6)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Affirmations");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyEntry", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Compliment")
.HasColumnType("longtext");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("EntryDate")
.HasColumnType("datetime(6)");
b.Property<string>("Gratitude")
.HasColumnType("longtext");
b.Property<string>("Journal")
.HasColumnType("longtext");
b.Property<string>("Reflection")
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DailyEntries");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyTask", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("Date")
.HasColumnType("datetime(6)");
b.Property<bool>("IsCompleted")
.HasColumnType("tinyint(1)");
b.Property<string>("TaskName")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("DailyTasks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitCheck", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CheckDate")
.HasColumnType("datetime(6)");
b.Property<int>("HabitTrackerId")
.HasColumnType("int");
b.Property<bool>("IsCompleted")
.HasColumnType("tinyint(1)");
b.HasKey("Id");
b.HasIndex("HabitTrackerId");
b.ToTable("HabitChecks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("HabitName")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("Month")
.HasColumnType("datetime(6)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("HabitTrackers");
});
modelBuilder.Entity("PeacePDS.Models.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<string>("HashedPassword")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("varchar(255)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("PeacePDS.Models.Entities.UserPolicy", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<bool>("IsEnable")
.HasColumnType("tinyint(1)");
b.Property<string>("Policy")
.HasMaxLength(50)
.HasColumnType("varchar(50)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("UserPolicies");
});
modelBuilder.Entity("PeacePDS.Models.Entities.Affirmation", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("Affirmations")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyEntry", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("DailyEntries")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.DailyTask", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("DailyTasks")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitCheck", b =>
{
b.HasOne("PeacePDS.Models.Entities.HabitTracker", "HabitTracker")
.WithMany("HabitChecks")
.HasForeignKey("HabitTrackerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("HabitTracker");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("HabitTrackers")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.UserPolicy", b =>
{
b.HasOne("PeacePDS.Models.Entities.User", "User")
.WithMany("UserPolicies")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("PeacePDS.Models.Entities.HabitTracker", b =>
{
b.Navigation("HabitChecks");
});
modelBuilder.Entity("PeacePDS.Models.Entities.User", b =>
{
b.Navigation("Affirmations");
b.Navigation("DailyEntries");
b.Navigation("DailyTasks");
b.Navigation("HabitTrackers");
b.Navigation("UserPolicies");
});
#pragma warning restore 612, 618
}
}
}

@ -5,11 +5,16 @@ namespace PeacePDS.Models.Entities
public class Affirmation public class Affirmation
{ {
public int Id { get; set; } public int Id { get; set; }
[Required]
public int UserId { get; set; } public int UserId { get; set; }
[Required]
public DateTime Month { get; set; } public DateTime Month { get; set; }
[Required]
public string AffirmationWord { get; set; } public string AffirmationWord { get; set; }
[Required]
public DateTime CreatedAt { get; set; } = DateTime.Now; public DateTime CreatedAt { get; set; } = DateTime.Now;
// Navigation Props
public User User { get; set; } public User User { get; set; }
} }
} }

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace PeacePDS.Models.Entities
{
public class DailyEntry
{
public int Id { get; set; }
[Required]
public int UserId { get; set; }
[Required]
public DateTime EntryDate { get; set; }
public string? Compliment { get; set; }
public string? Reflection { get; set; }
public string? Gratitude { get; set; }
public string? Journal { get; set; }
[Required]
public DateTime CreatedAt { get; set; } = DateTime.Now;
// Navigation Props
public User User { get; set; }
}
}

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace PeacePDS.Models.Entities
{
public class DailyTask
{
public int Id { get; set; }
[Required]
public int UserId { get; set; }
[Required]
public DateTime Date { get; set; }
[Required]
public string TaskName { get; set; }
[Required]
public bool IsCompleted { get; set; }
[Required]
public DateTime CreatedAt { get; set; } = DateTime.Now;
// Navigation Props
public User User { get; set; }
}
}

@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace PeacePDS.Models.Entities
{
public class HabitCheck
{
public int Id { get; set; }
[Required]
public int HabitTrackerId { get; set; }
[Required]
public DateTime CheckDate { get; set; }
[Required]
public bool IsCompleted { get; set; }
// Navigation Props
public HabitTracker HabitTracker { get; set; }
}
}

@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace PeacePDS.Models.Entities
{
public class HabitTracker
{
public int Id { get; set; }
[Required]
public int UserId { get; set; }
[Required]
public string HabitName { get; set; }
[Required]
public DateTime Month { get; set; }
[Required]
public DateTime CreatedAt { get; set; } = DateTime.Now;
// Navigation Props
public User User { get; set; }
public ICollection<HabitCheck> HabitChecks { get; set; }
}
}

@ -6,12 +6,20 @@ namespace PeacePDS.Models.Entities
{ {
public int Id { get; set; } public int Id { get; set; }
[MaxLength(100)] [Required, MaxLength(100)]
public string Name { get; set; } public string Name { get; set; }
[MaxLength(100)] [Required, MaxLength(255)]
public string Password { get; set; } public string HashedPassword { get; set; }
public DateTime CreatedAt { get; set; } [Required]
public DateTime CreatedAt { get; set; } = DateTime.Now;
// Navigation Props
public ICollection<UserPolicy> UserPolicies { get; set; }
public ICollection<Affirmation> Affirmations { get; set; }
public ICollection<HabitTracker> HabitTrackers { get; set; }
public ICollection<DailyTask> DailyTasks { get; set; }
public ICollection<DailyEntry> DailyEntries { get; set; }
} }
} }

@ -9,5 +9,9 @@ namespace PeacePDS.Models.Entities
[MaxLength(50)] [MaxLength(50)]
public string? Policy { get; set; } public string? Policy { get; set; }
public bool IsEnable { get; set; } public bool IsEnable { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.Now;
// Navigation Props
public User User { get; set; }
} }
} }

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

@ -5,6 +5,6 @@ namespace PeacePDS.Responses
public class CustomResponses public class CustomResponses
{ {
public record RegistrationResponse(bool Success = false, string Message = null!); public record RegistrationResponse(bool Success = false, string Message = null!);
public record LoginResponse(bool Success = false, string Message = null!, User user = null!, List<UserPolicy> policies = null!); public record LoginResponse(bool Success = false, string Message = null!, User User = null!);
} }
} }

@ -3,6 +3,7 @@ using PeacePDS.Models.Entities;
using PeacePDS.Models.ViewModels; using PeacePDS.Models.ViewModels;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using static PeacePDS.Responses.CustomResponses; using static PeacePDS.Responses.CustomResponses;
using PeacePDS.Utils;
namespace PeacePDS.Services namespace PeacePDS.Services
{ {
@ -21,17 +22,33 @@ namespace PeacePDS.Services
return new LoginResponse(false, "Invalid account information"); return new LoginResponse(false, "Invalid account information");
var user = _appDbContext.Users.Where(u => u.Name == model.UserName).FirstOrDefault(); var user = _appDbContext.Users.Where(u => u.Name == model.UserName).FirstOrDefault();
if (user is null || user.Password != model.Password) if (user is null || !PasswordHasher.VerifyPassword(model.Password, user.HashedPassword))
return new LoginResponse(false, "Invalid account information"); return new LoginResponse(false, "Invalid account information");
var policies = await _appDbContext.UserPolicies.Where(p => p.UserId == user.Id && p.IsEnable).ToListAsync(); user = _appDbContext.Users.Where(u => u.Name == model.UserName).Include(u => u.UserPolicies).FirstOrDefault();
return new LoginResponse(true, "Success", user, policies); return new LoginResponse(true, "Success", user);
} }
public Task<RegistrationResponse> RegisterAsync(RegisterViewModel model) public async Task<RegistrationResponse> RegisterAsync(RegisterViewModel model)
{ {
throw new NotImplementedException(); if (string.IsNullOrWhiteSpace(model.UserName) || string.IsNullOrWhiteSpace(model.Password) || string.IsNullOrEmpty(model.ConfirmPassword) || !string.Equals(model.Password, model.ConfirmPassword))
return new RegistrationResponse(false, "Invalid account information");
var user = _appDbContext.Users.Where(u => u.Name == model.UserName).FirstOrDefault();
if (user is not null)
return new RegistrationResponse(false, "Unavailable account name");
User newUser = new User()
{
Name = model.UserName,
HashedPassword = PasswordHasher.HashPassword(model.Password),
};
_appDbContext.Users.Add(newUser);
await _appDbContext.SaveChangesAsync();
return new RegistrationResponse(true, "Success");
} }
} }
} }

@ -0,0 +1,15 @@
namespace PeacePDS.Utils
{
public class PasswordHasher
{
public static string HashPassword(string password)
{
return BCrypt.Net.BCrypt.HashPassword(password);
}
public static bool VerifyPassword(string password, string hashedPassword)
{
return BCrypt.Net.BCrypt.Verify(password, hashedPassword);
}
}
}

@ -1,4 +1,7 @@
{ {
"ConnectionStrings": {
"DefaultConnection": "Server=peacecloud.synology.me; Port=23306; Database=WEBPDS_DEV; Uid=pds; Pwd=Pds92070983!@"
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",

@ -1,6 +1,6 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Server=peacecloud.synology.me; Port=23306; Database=BLAZORAUTH; Uid=pds; Pwd=Pds92070983!@" "DefaultConnection": "Server=peacecloud.synology.me; Port=23306; Database=WEBPDS; Uid=pds; Pwd=Pds92070983!@"
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {

Loading…
Cancel
Save