Add password reset functionality for admin users: implement ResetPassword endpoint, update AdminUserEndpoints to include password reset logic, and enhance user interface for password management. Update translations for new features and ensure proper error handling in the reset process.

This commit is contained in:
Leonid Pershin
2026-07-25 19:49:08 +03:00
parent d44aa44d95
commit 1f6fa6f1ae
30 changed files with 1755 additions and 58 deletions
@@ -99,6 +99,29 @@ internal sealed class IdentityService(
);
}
public async Task<Result> ResetPasswordAsync(
Guid userId,
string newPassword,
CancellationToken cancellationToken
)
{
var user = await userManager.FindByIdAsync(userId.ToString());
if (user is null)
return Result.Failure(UserErrors.NotFound);
// Админ меняет чужой пароль — без текущего: сбрасываем через одноразовый токен сброса.
var token = await userManager.GeneratePasswordResetTokenAsync(user);
var result = await userManager.ResetPasswordAsync(user, token, newPassword);
return result.Succeeded
? Result.Success()
: Result.Failure(
Error.Validation(
"Auth.ResetPasswordFailed",
string.Join("; ", result.Errors.Select(e => e.Description))
)
);
}
public async Task<Result> ChangeUserNameAsync(
Guid userId,
string newUserName,
@@ -0,0 +1,96 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace TeleWave.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class WeeklyProgrammingOverrides : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "StartsAtUtc",
table: "ProgrammingOverride",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone");
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "EndsAtUtc",
table: "ProgrammingOverride",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone");
migrationBuilder.AddColumn<int>(
name: "DayOfWeek",
table: "ProgrammingOverride",
type: "integer",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "EndMinute",
table: "ProgrammingOverride",
type: "integer",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "Recurrence",
table: "ProgrammingOverride",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "StartMinute",
table: "ProgrammingOverride",
type: "integer",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DayOfWeek",
table: "ProgrammingOverride");
migrationBuilder.DropColumn(
name: "EndMinute",
table: "ProgrammingOverride");
migrationBuilder.DropColumn(
name: "Recurrence",
table: "ProgrammingOverride");
migrationBuilder.DropColumn(
name: "StartMinute",
table: "ProgrammingOverride");
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "StartsAtUtc",
table: "ProgrammingOverride",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "EndsAtUtc",
table: "ProgrammingOverride",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)),
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone",
oldNullable: true);
}
}
}
@@ -478,13 +478,25 @@ namespace TeleWave.Infrastructure.Migrations
b.Property<Guid>("ChannelId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("EndsAtUtc")
b.Property<int?>("DayOfWeek")
.HasColumnType("integer");
b.Property<int?>("EndMinute")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("EndsAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<int>("Mode")
.HasColumnType("integer");
b.Property<DateTimeOffset>("StartsAtUtc")
b.Property<int>("Recurrence")
.HasColumnType("integer");
b.Property<int?>("StartMinute")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("StartsAtUtc")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");