Release v1.0.0 #16
.envDbInitializer.csDependencyInjection.cs
.gitea/workflows
ApiDto
ApiDto.csproj
Backend.slnCommon
Requests
Responses
Endpoint
Common
Attributes
BadRequestResponseAttribute.csLocalhostAttribute.csMaintenanceModeIgnoreAttribute.csNotFoundResponseAttribute.csTokenAuthenticationAttribute.cs
Exceptions
Interfaces
Model
Services
Configuration
EnvironmentManager.cs
General
Swagger
Controllers
BaseController.cs
Endpoint.csprojConfiguration
V1
CampusController.csDisciplineController.csFacultyController.csGroupController.csLectureHallController.csProfessorController.csScheduleController.cs
WeatherForecastController.csMiddleware
Program.csWeatherForecast.csSecurity
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus
Queries
Discipline
Queries
Faculty
Queries
Group
Queries
LectureHall
Queries
Professor
Queries
Schedule
Interfaces
Domain
Domain.csproj
Schedule
Migrations
MysqlMigrations
Migrations
20240601023106_InitialMigration.Designer.cs20240601023106_InitialMigration.csUberDbContextModelSnapshot.cs
MysqlMigrations.csprojPsqlMigrations
Migrations
20240601021702_InitialMigration.Designer.cs20240601021702_InitialMigration.csUberDbContextModelSnapshot.cs
PsqlMigrations.csprojSqliteMigrations
Persistence
Common
BaseDbContext.csConfigurationResolver.csDatabaseProvider.csDbContextFactory.csModelBuilderExtensions.cs
Contexts
Schedule
EntityTypeConfigurations
Persistence.csprojUberDbContext.cs@ -32,7 +32,11 @@ namespace Mirea.Api.Endpoint.Controllers.Configuration;
|
||||
[ApiController]
|
||||
[MaintenanceModeIgnore]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigureService notConfigureService, IMemoryCache cache) : BaseController
|
||||
public class SetupController(
|
||||
ISetupToken setupToken,
|
||||
IMaintenanceModeNotConfigureService notConfigureService,
|
||||
IMemoryCache cache,
|
||||
PasswordHashService passwordHashService) : BaseController
|
||||
{
|
||||
private const string CacheGeneralKey = "config_general";
|
||||
private const string CacheAdminKey = "config_admin";
|
||||
@ -208,6 +212,18 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
|
||||
if (!MailAddress.TryCreate(user.Email, out _))
|
||||
throw new ControllerArgumentException("The email address is incorrect.");
|
||||
|
||||
var (salt, hash) = passwordHashService.HashPassword(user.Password);
|
||||
|
||||
var admin = new Admin
|
||||
{
|
||||
Username = user.Username,
|
||||
Email = user.Email,
|
||||
PasswordHash = hash,
|
||||
Salt = salt
|
||||
};
|
||||
|
||||
cache.Set(CacheAdminKey, admin);
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
@ -297,14 +313,13 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
if (!new SettingsRequiredValidator(GeneralConfig).AreSettingsValid())
|
||||
throw new ControllerArgumentException("The necessary data has not been configured.");
|
||||
|
||||
// todo: change CreateUserRequest to Domain entity
|
||||
if (!cache.TryGetValue(CacheAdminKey, out CreateUserRequest? user) || user == null)
|
||||
if (!cache.TryGetValue(CacheAdminKey, out Admin? admin) || admin == null)
|
||||
throw new ControllerArgumentException("The administrator's data was not set.");
|
||||
|
||||
if (System.IO.File.Exists(PathBuilder.Combine(GeneralConfig.FilePath)))
|
||||
System.IO.File.Delete(PathBuilder.Combine(GeneralConfig.FilePath));
|
||||
|
||||
System.IO.File.WriteAllText(PathBuilder.Combine("admin.json"), JsonSerializer.Serialize(user));
|
||||
System.IO.File.WriteAllText(PathBuilder.Combine(Admin.PathToSave), JsonSerializer.Serialize(admin));
|
||||
|
||||
System.IO.File.WriteAllText(
|
||||
PathBuilder.Combine(GeneralConfig.FilePath),
|
||||
|
Reference in New Issue
Block a user