Make password optional

This commit is contained in:
Zoe Roux 2024-03-02 16:36:44 +01:00
parent 3bb36f5e78
commit 115d52977d
6 changed files with 1356 additions and 4 deletions

View File

@ -54,7 +54,9 @@ namespace Kyoo.Abstractions.Models
/// The user password (hashed, it can't be read like that). The hashing format is implementation defined.
/// </summary>
[SerializeIgnore]
public string Password { get; set; }
public string? Password { get; set; }
public bool HasPassword => Password != null;
/// <summary>
/// The list of permissions of the user. The format of this is implementation dependent.

View File

@ -28,7 +28,7 @@ public class PasswordResetRequest
/// <summary>
/// The old password
/// </summary>
public string OldPassword { get; set; }
public string? OldPassword { get; set; }
/// <summary>
/// The new password

View File

@ -316,7 +316,7 @@ namespace Kyoo.Authentication.Views
public async Task<ActionResult<User>> ResetPassword([FromBody] PasswordResetRequest request)
{
User user = await users.Get(User.GetIdOrThrow());
if (!BCryptNet.Verify(request.OldPassword, user.Password))
if (user.HasPassword && !BCryptNet.Verify(request.OldPassword, user.Password))
return Forbid(new RequestError("The old password is invalid."));
return await users.Patch(
user.Id,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Kyoo.Postgresql.Migrations
{
/// <inheritdoc />
public partial class MakePasswordOptional : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "password",
table: "users",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text"
);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "password",
table: "users",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true
);
}
}
}

View File

@ -620,7 +620,6 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnName("external_id");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text")
.HasColumnName("password");