Skip to content

Commit

Permalink
Updated package versions, simplified code, and improved file structure
Browse files Browse the repository at this point in the history
In `JwtTokenService.cs`, the error message for an invalid refreshToken was updated and the log message for a successful refreshToken refresh was removed.
  • Loading branch information
luoyunchong committed Mar 16, 2024
1 parent 4a76323 commit a6439c6
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 41 deletions.
1 change: 1 addition & 0 deletions LinCms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
docs\README.md = docs\README.md
README.md = README.md
run.sh = run.sh
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LinCms.Infrastructure", "src\LinCms.Infrastructure\LinCms.Infrastructure.csproj", "{A769DA45-FC9F-452F-A591-635C101569C8}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.806" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="[1.19.6-Preview.1, 1.19.6]" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.815" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="IGeekFan.AspNetCore.RapiDoc" Version="0.0.7" />
Expand Down
33 changes: 33 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
SERVER_NAME=lincms-web

#判断是否存在webnotebook容器
docker ps | grep lincms-web &> /dev/null
#如果不存在,则Remove
if [ $? -ne 0 ]
then
echo "${SERVER_NAME} container not exist continue.. "
else
echo "remove ${SERVER_NAME} container"
docker rm ${SERVER_NAME} -f
fi

docker images | grep registry.cn-hangzhou.aliyuncs.com/igeekfan/${SERVER_NAME} &> /dev/null

if [ $? -ne 0 ]
then
echo "image does not exist , continue..."
else
echo "image exists !!! remove it"
docker rmi --force registry.cn-hangzhou.aliyuncs.com/igeekfan/${SERVER_NAME}
fi
#从阿里云拉取刚刚push的镜像
docker pull registry.cn-hangzhou.aliyuncs.com/igeekfan/${SERVER_NAME}

sudo docker run --restart \
unless-stopped \
-p 5011:8080 \
-v /var/www/lin-cms-dotnetcore/wwwroot/:/app/wwwroot:rw \
-v /var/www/lin-cms-dotnetcore/appsettings.Production.json/:/app/appsettings.Production.json:rw \
--privileged=true \
--name ${SERVER_NAME} \
-d registry.cn-hangzhou.aliyuncs.com/igeekfan/${SERVER_NAME}
5 changes: 2 additions & 3 deletions src/LinCms.Application/Cms/Account/JwtTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task<UserAccessToken> GetRefreshTokenAsync(string refreshToken)

if (user.IsNull())
{
throw new LinCmsException("该refreshToken无效!");
throw new LinCmsException("该refreshToken无效!", ErrorCode.RefreshTokenError);
}

if (DateTime.Compare(user.LastLoginTime, DateTime.Now) > new TimeSpan(30, 0, 0, 0).Ticks)
Expand All @@ -77,8 +77,7 @@ public async Task<UserAccessToken> GetRefreshTokenAsync(string refreshToken)
}

UserAccessToken tokens = await _tokenManager.CreateTokenAsync(user);
_logger.LogInformation($"用户{user.Username},JwtRefreshToken 刷新-登录成功");


return tokens;
}

Expand Down
12 changes: 6 additions & 6 deletions src/LinCms.Application/LinCms.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="8.0.0" />
<PackageReference Include="AspNet.Security.OAuth.QQ" Version="8.0.0" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="8.0.0" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="8.0.1" />
<!--<PackageReference Include="DotNetCore.CAP.SqlServer" Version="6.1.1-preview-176300030" />-->
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="8.0.0" />
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="8.0.0" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="8.0.0" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="8.0.1" />
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="8.0.1" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="8.0.1" />
<PackageReference Include="IdentityServer4" Version="4.1.2" />
<PackageReference Include="IdentityModel" Version="6.2.0" />
<PackageReference Include="IGeekFan.Localization.FreeSql" Version="0.0.536" />
<PackageReference Include="IGeekFan.Localization.FreeSql" Version="0.0.539" />
<PackageReference Include="MQiniu.Core" Version="1.0.1" />
<PackageReference Include="FreeRedis" Version="1.2.10" />
<PackageReference Include="FreeRedis" Version="1.2.14" />
<PackageReference Include="FreeRedis.DistributedCache" Version="1.2.5" />
</ItemGroup>

Expand Down
12 changes: 6 additions & 6 deletions src/LinCms.Core/LinCms.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="IGeekFan.FreeKit.Extras" Version="0.0.536" />
<PackageReference Include="IGeekFan.FreeKit.Extras" Version="0.0.539" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="DotNetCore.Security" Version="17.3.0" />
<PackageReference Include="IGeekFan.FreeKit.Email" Version="0.0.536" />
<PackageReference Include="FreeSql.Extensions.JsonMap" Version="3.2.806" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageReference Include="IGeekFan.FreeKit.Email" Version="0.0.539" />
<PackageReference Include="FreeSql.Extensions.JsonMap" Version="3.2.815" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.3" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
<PackageReference Include="Z.ExtensionMethods" Version="2.1.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/LinCms.Infrastructure/LinCms.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<ItemGroup>

<ProjectReference Include="..\LinCms.Core\LinCms.Core.csproj" />
<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.806" />
<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.806" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.806" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.806" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.806" />
<PackageReference Include="FreeSql.Provider.Odbc" Version="3.2.806" />
<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.815" />
<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.815" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.815" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.815" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.815" />
<PackageReference Include="FreeSql.Provider.Odbc" Version="3.2.815" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions src/LinCms.Web/Controllers/Cms/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class AccountController : ApiControllerBase
private readonly ITokenService _tokenService;
private readonly IAccountService _accountService;
private readonly IAuditBaseRepository<BlackRecord> _blackRecordRepository;
private readonly IUserService _userService;
private readonly CaptchaOption _loginCaptchaOption;
private readonly ICaptchaManager _captchaManager;
public AccountController(IComponentContext componentContext, IConfiguration configuration, IAccountService accountService, IAuditBaseRepository<BlackRecord> blackRecordRepository, IUserService userService, IOptionsMonitor<CaptchaOption> loginCaptchaOption, ICaptchaManager captchaManager)
Expand All @@ -42,7 +41,6 @@ public AccountController(IComponentContext componentContext, IConfiguration conf
_tokenService = componentContext.ResolveNamed<ITokenService>(isIdentityServer4 ? nameof(IdentityServer4Service) : nameof(JwtTokenService));
_accountService = accountService;
_blackRecordRepository = blackRecordRepository;
_userService = userService;
_loginCaptchaOption = loginCaptchaOption.CurrentValue;
_captchaManager = captchaManager;
}
Expand Down Expand Up @@ -81,7 +79,7 @@ public IActionResult CaptchaImg()
[HttpPost("login")]
public Task<UserAccessToken> Login([FromBody] LoginInputDto loginInputDto, [FromHeader] string? tag)
{
if (_loginCaptchaOption.Enabled == true)
if (_loginCaptchaOption.Enabled)
{
if (loginInputDto.Captcha.IsNullOrWhiteSpace())
{
Expand Down
6 changes: 3 additions & 3 deletions src/LinCms.Web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
Expand All @@ -7,19 +9,17 @@ EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Directory.Build.props", "."]
COPY ["src/LinCms.Web/LinCms.Web.csproj", "src/LinCms.Web/"]
COPY ["src/LinCms.Application.Contracts/LinCms.Application.Contracts.csproj", "src/LinCms.Application.Contracts/"]
COPY ["src/LinCms.Core/LinCms.Core.csproj", "src/LinCms.Core/"]
COPY ["src/LinCms.Application/LinCms.Application.csproj", "src/LinCms.Application/"]
COPY ["src/LinCms.Infrastructure/LinCms.Infrastructure.csproj", "src/LinCms.Infrastructure/"]
COPY ["src/LinCms.Plugins/LinCms.Plugins.csproj", "src/LinCms.Plugins/"]
RUN dotnet restore "./src/LinCms.Web/./LinCms.Web.csproj"
RUN dotnet restore "./src/LinCms.Web/LinCms.Web.csproj"
COPY . .
WORKDIR "/src/src/LinCms.Web"
RUN dotnet build "./LinCms.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build


FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./LinCms.Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
Expand Down
14 changes: 7 additions & 7 deletions src/LinCms.Web/LinCms.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="7.1.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" />
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.16" />
<PackageReference Include="IGeekFan.AspNetCore.RapiDoc" Version="0.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6-Preview.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Owl.reCAPTCHA" Version="7.0.0" />
<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="7.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="8.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.MariaDB" Version="1.0.1" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.5.0" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
Expand Down
8 changes: 4 additions & 4 deletions test/LinCms.Test/LinCms.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.3" />
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit a6439c6

Please sign in to comment.