-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #793 from EdiWang/master
Release v14.4.0
- Loading branch information
Showing
270 changed files
with
1,896 additions
and
3,872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.