Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static class CacheKey
const string EMAIL_FORGOT_PASSWORD_SEND_PRE = "email_forgot_password_send:";
const string MSG_CODE_FORGOT_PASSWORD_CODE_PRE = "msg_forgot_password_code:";
const string MSG_CODE_FORGOT_PASSWORD_SEND_PRE = "msg_forgot_password_send:";
const string EMAIL_DELETE_ACCOUNT_CODE_PRE = "email_delete_account_code:";
const string EMAIL_DELETE_ACCOUNT_SEND_PRE = "email_delete_account_send:";
const string EMAIL_UPDATE_CODE_PRE = "email_update_code:";
const string EMAIL_UPDATE_SEND_PRE = "email_update_send:";
public const string STAFF_DEFAULT_PASSWORD = "staff_default_password";
Expand Down Expand Up @@ -130,6 +132,16 @@ public static string EmailCodeForgotPasswordKey(string email)
return $"{EMAIL_FORGOT_PASSWORD_CODE_PRE}{email}";
}

public static string EmailCodeDeleteAccountSendKey(string email)
{
return $"{EMAIL_DELETE_ACCOUNT_SEND_PRE}{email}";
}

public static string EmailCodeDeleteAccountKey(string email)
{
return $"{EMAIL_DELETE_ACCOUNT_CODE_PRE}{email}";
}

public static string EmailCodeUpdateSendKey(string email)
{
return $"{EMAIL_UPDATE_SEND_PRE}{email}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Masa.Auth.Domain/Masa.Auth.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public async Task SendEmailAsync(SendEmailCommand command)
case SendEmailTypes.Verifiy:
case SendEmailTypes.UpdateEmail:
case SendEmailTypes.ForgotPassword:
case SendEmailTypes.DeleteAccount:
if (!_userRepository.Any(u => u.Email == model.Email))
{
throw new UserFriendlyException(UserFriendlyExceptionCodes.USER_EMAIL_NOT_EXIST, model.Email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ public async Task DeleteAccountAsync(DeleteAccountCommand command)
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.USER_NOT_EXIST);
}

if (command.SmsCode is not null && command.EmailCode is not null)
{
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.INVALID_CAPTCHA);
}

if (command.SmsCode is not null)
{
var smsCodeKey = CacheKey.MsgCodeDeleteAccountKey(user.PhoneNumber);
Expand All @@ -723,6 +728,15 @@ public async Task DeleteAccountAsync(DeleteAccountCommand command)
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.INVALID_SMS_CAPTCHA);
}
}
else if (command.EmailCode is not null)
{
var emailCodeKey = CacheKey.EmailCodeDeleteAccountKey(user.Email);
var emailCode = await _distributedCacheClient.GetAsync<string>(emailCodeKey);
if (!command.EmailCode.Equals(emailCode))
{
throw new UserFriendlyException(errorCode: UserFriendlyExceptionCodes.INVALID_EMAIL_CAPTCHA);
}
}

await _userDomainService.RemoveAsync(user.Id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace Masa.Auth.Service.Admin.Application.Subjects.Commands;

public record DeleteAccountCommand(string? SmsCode) : Command
public record DeleteAccountCommand(string? SmsCode, string? EmailCode) : Command
{
}
4 changes: 2 additions & 2 deletions src/Services/Masa.Auth.Service.Admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM registry.cn-hangzhou.aliyuncs.com/masa/dotnet_sdk:6.0.403 AS publish
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS publish
WORKDIR /src
COPY . .
ENV CSPROJ="src/Services/Masa.Auth.Service.Admin/Masa.Auth.Service.Admin.csproj"
RUN dotnet restore $CSPROJ && dotnet publish $CSPROJ -c Release -o /app/publish


FROM registry.cn-hangzhou.aliyuncs.com/masa/dotnet_aspnet:6.0.4
FROM mcr.microsoft.com/dotnet/aspnet:10.0

Check warning on line 10 in src/Services/Masa.Auth.Service.Admin/Dockerfile

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This image runs with "root" or "containerAdministrator" as the default user. Make sure it is safe here.

See more on https://sonarcloud.io/project/issues?id=masastack_MASA.Auth&issues=AZ73H6QqWYpOdl3gJd4M&open=AZ73H6QqWYpOdl3gJd4M&pullRequest=1475
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS=http://0.0.0.0:80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public async Task SendEmailAsync(SendEmailModel sendEmailModel, TimeSpan? expira
sendKey = CacheKey.EmailCodeBindSendKey(sendEmailModel.Email);
sendValueKey = CacheKey.EmailCodeBindKey(sendEmailModel.Email);
break;
case SendEmailTypes.DeleteAccount:
sendKey = CacheKey.EmailCodeDeleteAccountSendKey(sendEmailModel.Email);
sendValueKey = CacheKey.EmailCodeDeleteAccountKey(sendEmailModel.Email);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>6efa3c5e-9868-4abd-90a1-75aca8b7b38f</UserSecretsId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task<PaginationDto<OnlineUserDto>> GetListAsync(
var sessionJson = await db.StringGetAsync(SsoSessionKey(subjectId));
if (sessionJson.HasValue)
{
var session = JsonSerializer.Deserialize<WebOnlineSessionDto>(sessionJson!);
var session = JsonSerializer.Deserialize<WebOnlineSessionDto>((string)sessionJson!);
if (session != null)
webSessions[subjectId] = new WebSessionDto(session.LoginTime, session.ClientId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public async Task<ImpersonationCacheItem> GetImpersonatedAsync([FromServices] IE
[RoutePattern("account/delete", StartWithBaseUri = true, HttpMethod = "Post")]
public async Task DeleteAccountAsync([FromServices] IEventBus eventBus, [FromBody] DeleteAccountModel model)
{
var command = new DeleteAccountCommand(model.SmsCode);
var command = new DeleteAccountCommand(model.SmsCode, model.EmailCode);
await eventBus.PublishAsync(command);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Masa.Auth.Web.Sso/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM registry.cn-hangzhou.aliyuncs.com/masa/dotnet_sdk:6.0.403 AS publish
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS publish
WORKDIR /src
COPY . .
ENV CSPROJ="src/Web/Masa.Auth.Web.Sso/Masa.Auth.Web.Sso.csproj"
RUN dotnet restore $CSPROJ && dotnet publish $CSPROJ -c Release -o /app/publish

FROM registry.cn-hangzhou.aliyuncs.com/masa/dotnet_aspnet:6.0.4
FROM mcr.microsoft.com/dotnet/aspnet:10.0

Check warning on line 7 in src/Web/Masa.Auth.Web.Sso/Dockerfile

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This image runs with "root" or "containerAdministrator" as the default user. Make sure it is safe here.

See more on https://sonarcloud.io/project/issues?id=masastack_MASA.Auth&issues=AZ73H6MQWYpOdl3gJd4L&open=AZ73H6MQWYpOdl3gJd4L&pullRequest=1475
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS=https://0.0.0.0:443
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Masa.Auth.Web.Sso/Masa.Auth.Web.Sso.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
Expand Down
Loading