Skip to content

Commit

Permalink
Merge pull request #793 from EdiWang/master
Browse files Browse the repository at this point in the history
Release v14.4.0
  • Loading branch information
EdiWang authored May 9, 2024
2 parents f126671 + 07b1f98 commit 786be8f
Show file tree
Hide file tree
Showing 270 changed files with 1,896 additions and 3,872 deletions.
34 changes: 33 additions & 1 deletion Deployment/mssql-migration.sql
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
--
-- v14.3.x - v14.4.0
CREATE TABLE [dbo].[LoginHistory](
[Id] [int] IDENTITY(1,1) NOT NULL,
[LoginTimeUtc] [datetime] NOT NULL,
[LoginIp] [nvarchar](64) NULL,
[LoginUserAgent] [nvarchar](128) NULL,
[DeviceFingerprint] [nvarchar](128) NULL,
CONSTRAINT [PK_LoginHistory] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

DROP TABLE [LocalAccount]
GO

EXEC sys.sp_rename
@objname = N'Category.RouteName',
@newname = 'Slug',
@objtype = 'COLUMN'
GO

IF EXISTS (
SELECT 1
FROM sys.columns c
JOIN sys.objects o ON c.object_id = o.object_id
WHERE o.name = 'Post' AND c.name = 'InlineCss'
)
BEGIN
ALTER TABLE Post DROP COLUMN InlineCss;
END;
GO
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Open Search | Search | Supported | `/opensearch`
Pingback | Social | Supported | `/pingback`
Reader View | Reader mode | Supported | N/A
FOAF | Social | Supported | `/foaf.xml`
RSD | Service Discovery | Supported | `/rsd` *If MetaWeblog is enabled*
MetaWeblog | Blogging | Basic Support | `/metaweblog`
RSD | Service Discovery | Deprecated | N/A
MetaWeblog | Blogging | Deprecated | N/A
Dublin Core Metadata | SEO | Basic Support | N/A
BlogML | Blogging | Not planned |
APML | Social | Not planned |
Expand Down
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Authors>Edi Wang</Authors>
<Company>edi.wang</Company>
<Copyright>(C) 2024 edi.wang@outlook.com</Copyright>
<AssemblyVersion>14.3.3.0</AssemblyVersion>
<FileVersion>14.3.3.0</FileVersion>
<Version>14.3.3</Version>
<AssemblyVersion>14.4.0.0</AssemblyVersion>
<FileVersion>14.4.0.0</FileVersion>
<Version>14.4.0</Version>
</PropertyGroup>
</Project>
28 changes: 0 additions & 28 deletions src/Moonglade.Auth/Account.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/Moonglade.Auth/AccountExistsQuery.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/Moonglade.Auth/ChangePasswordCommand.cs

This file was deleted.

11 changes: 0 additions & 11 deletions src/Moonglade.Auth/CountAccountsQuery.cs

This file was deleted.

53 changes: 0 additions & 53 deletions src/Moonglade.Auth/CreateAccountCommand.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/Moonglade.Auth/DeleteAccountCommand.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/Moonglade.Auth/GetAccountQuery.cs

This file was deleted.

21 changes: 0 additions & 21 deletions src/Moonglade.Auth/GetAccountsQuery.cs

This file was deleted.

16 changes: 16 additions & 0 deletions src/Moonglade.Auth/GetLoginHistoryQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Moonglade.Data;
using Moonglade.Data.Entities;
using Moonglade.Data.Specifications;

namespace Moonglade.Auth;

public record GetLoginHistoryQuery : IRequest<List<LoginHistoryEntity>>;

public class GetLoginHistoryQueryHandler(MoongladeRepository<LoginHistoryEntity> repo) : IRequestHandler<GetLoginHistoryQuery, List<LoginHistoryEntity>>
{
public async Task<List<LoginHistoryEntity>> Handle(GetLoginHistoryQuery request, CancellationToken ct)
{
var history = await repo.ListAsync(new LoginHistorySpec(10), ct);
return history;
}
}
24 changes: 12 additions & 12 deletions src/Moonglade.Auth/LogSuccessLoginCommand.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using Moonglade.Data.Entities;
using Moonglade.Data.Infrastructure;
using Moonglade.Data;
using Moonglade.Data.Entities;

namespace Moonglade.Auth;

public record LogSuccessLoginCommand(Guid Id, string IpAddress) : IRequest;
public record LogSuccessLoginCommand(string IpAddress, string UserAgent, string DeviceFingerprint) : IRequest;

public class LogSuccessLoginCommandHandler(IRepository<LocalAccountEntity> repo) : IRequestHandler<LogSuccessLoginCommand>
public class LogSuccessLoginCommandHandler(MoongladeRepository<LoginHistoryEntity> repo) : IRequestHandler<LogSuccessLoginCommand>
{
public async Task Handle(LogSuccessLoginCommand request, CancellationToken ct)
{
var (id, ipAddress) = request;

var entity = await repo.GetAsync(id, ct);
if (entity is not null)
var entity = new LoginHistoryEntity
{
entity.LastLoginIp = ipAddress.Trim();
entity.LastLoginTimeUtc = DateTime.UtcNow;
await repo.UpdateAsync(entity, ct);
}
LoginIp = request.IpAddress.Trim(),
LoginTimeUtc = DateTime.UtcNow,
LoginUserAgent = request.UserAgent.Trim(),
DeviceFingerprint = request.DeviceFingerprint.Trim()
};

await repo.AddAsync(entity, ct);
}
}
3 changes: 2 additions & 1 deletion src/Moonglade.Auth/Moonglade.Auth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.17.4" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.18.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Moonglade.Configuration\Moonglade.Configuration.csproj" />
<ProjectReference Include="..\Moonglade.Data\Moonglade.Data.csproj" />
<ProjectReference Include="..\Moonglade.Utils\Moonglade.Utils.csproj" />
</ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/Moonglade.Auth/UpdateLocalAccountPasswordRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;

namespace Moonglade.Auth;

public class UpdateLocalAccountPasswordRequest
{
[Required]
[RegularExpression("^[A-Za-z0-9]{3,16}$")]
public string NewUsername { get; set; }

[Required]
[RegularExpression("^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9._~!@#$^&*]{8,}$")]
public string OldPassword { get; set; }

[Required]
[RegularExpression("^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9._~!@#$^&*]{8,}$")]
public string NewPassword { get; set; }
}
31 changes: 9 additions & 22 deletions src/Moonglade.Auth/ValidateLoginCommand.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
using Moonglade.Data.Entities;
using Moonglade.Data.Infrastructure;
using Moonglade.Configuration;
using Moonglade.Utils;

namespace Moonglade.Auth;

public record ValidateLoginCommand(string Username, string InputPassword) : IRequest<Guid>;
public record ValidateLoginCommand(string Username, string InputPassword) : IRequest<bool>;

public class ValidateLoginCommandHandler(IRepository<LocalAccountEntity> repo) : IRequestHandler<ValidateLoginCommand, Guid>
public class ValidateLoginCommandHandler(IBlogConfig config) : IRequestHandler<ValidateLoginCommand, bool>
{
public async Task<Guid> Handle(ValidateLoginCommand request, CancellationToken ct)
public Task<bool> Handle(ValidateLoginCommand request, CancellationToken ct)
{
var account = await repo.GetAsync(p => p.Username == request.Username);
if (account is null) return Guid.Empty;
var account = config.LocalAccountSettings;

var valid = account.PasswordHash == (string.IsNullOrWhiteSpace(account.PasswordSalt)
? Helper.HashPassword(request.InputPassword.Trim())
: Helper.HashPassword2(request.InputPassword.Trim(), account.PasswordSalt));
if (account is null) return Task.FromResult(false);
if (account.Username != request.Username) return Task.FromResult(false);

// migrate old account to salt
if (valid && string.IsNullOrWhiteSpace(account.PasswordSalt))
{
var salt = Helper.GenerateSalt();
var newHash = Helper.HashPassword2(request.InputPassword.Trim(), salt);
var valid = account.PasswordHash == Helper.HashPassword(request.InputPassword.Trim(), account.PasswordSalt);

account.PasswordSalt = salt;
account.PasswordHash = newHash;

await repo.UpdateAsync(account, ct);
}

return valid ? account.Id : Guid.Empty;
return Task.FromResult(valid);
}
}
2 changes: 1 addition & 1 deletion src/Moonglade.Comments/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Comment

public string CommentContent { get; set; }

public IReadOnlyList<CommentReplyDigest> CommentReplies { get; set; }
public List<CommentReplyDigest> CommentReplies { get; set; }
}

public class CommentDetailedItem : Comment
Expand Down
Loading

0 comments on commit 786be8f

Please sign in to comment.