From d4be306feeb1bade4eafbba3f29a4e6cb716a564 Mon Sep 17 00:00:00 2001 From: ajax Date: Sat, 20 Jul 2024 16:09:33 +0800 Subject: [PATCH 1/3] chore: Updated Deps --- .gitignore | 3 +++ ThuInfoWeb/ThuInfoWeb.csproj | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index bb6e2c5..dd62019 100644 --- a/.gitignore +++ b/.gitignore @@ -362,3 +362,6 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd /ThuInfoWeb/test.db + +# Rider .idea +.idea/ diff --git a/ThuInfoWeb/ThuInfoWeb.csproj b/ThuInfoWeb/ThuInfoWeb.csproj index d13232d..8585971 100644 --- a/ThuInfoWeb/ThuInfoWeb.csproj +++ b/ThuInfoWeb/ThuInfoWeb.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 enable enable @@ -11,10 +11,10 @@ - - - - + + + + From 08d21ece44f63f5b00b257e5c0b3f46c4e4840cd Mon Sep 17 00:00:00 2001 From: ajax Date: Sat, 20 Jul 2024 16:57:08 +0800 Subject: [PATCH 2/3] Added fields to control when an announcement should be shown --- README.md | 4 +- ThuInfoWeb/Controllers/HomeController.cs | 70 +++++++++++++----------- ThuInfoWeb/DBModels/Announce.cs | 13 ++++- ThuInfoWeb/Models/AnnounceViewModel.cs | 17 +++++- ThuInfoWeb/Views/Home/Announce.cshtml | 10 ++++ 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 1b923c8..9c70feb 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ The web server application of [THUInfo](https://github.com/UNIDY2002/THUInfo) # Build Instruction ## Step 1 -Install dotnet sdk 6.0. +Install dotnet sdk 8.0. If you are running RHEL or CentOS, just use ``` -$ sudo dnf install dotnet-sdk-6.0 +$ sudo dnf install dotnet-sdk-8.0 ``` Others should follow this [installation instruction](https://docs.microsoft.com/zh-cn/dotnet/core/install/linux) ## Step 2 diff --git a/ThuInfoWeb/Controllers/HomeController.cs b/ThuInfoWeb/Controllers/HomeController.cs index 1319ebe..eb89f6f 100644 --- a/ThuInfoWeb/Controllers/HomeController.cs +++ b/ThuInfoWeb/Controllers/HomeController.cs @@ -15,10 +15,10 @@ public class HomeController : Controller public HomeController(ILogger logger, Data data, UserManager userManager, VersionManager versionManager) { - this._logger = logger; - this._data = data; - this._userManager = userManager; - this._versionManager = versionManager; + _logger = logger; + _data = data; + _userManager = userManager; + _versionManager = versionManager; } public IActionResult Register() { @@ -33,29 +33,29 @@ public async Task Register(RegisterViewModel vm) ModelState.AddModelError(nameof(vm.Name), "禁止注册新用户"); return View(vm); - if (await _data.CheckUserAsync(vm.Name)) - { - ModelState.AddModelError(nameof(vm.Name), "用户名已被注册"); - return View(vm); - } - var user = new User() - { - Name = vm.Name, - PasswordHash = vm.Password.ToSHA256Hex(), - CreatedTime = DateTime.Now, - IsAdmin = false - }; - var result = await _data.CreateUserAsync(user); - if (result == 1) - { - await _userManager.DoLoginAsync(vm.Name, false); - return RedirectToAction("Index"); - } - else - { - ModelState.AddModelError(nameof(vm.Name), "发生未知错误"); - return View(vm); - } + // if (await _data.CheckUserAsync(vm.Name)) + // { + // ModelState.AddModelError(nameof(vm.Name), "用户名已被注册"); + // return View(vm); + // } + // var user = new User() + // { + // Name = vm.Name, + // PasswordHash = vm.Password.ToSHA256Hex(), + // CreatedTime = DateTime.Now, + // IsAdmin = false + // }; + // var result = await _data.CreateUserAsync(user); + // if (result == 1) + // { + // await _userManager.DoLoginAsync(vm.Name, false); + // return RedirectToAction("Index"); + // } + // else + // { + // ModelState.AddModelError(nameof(vm.Name), "发生未知错误"); + // return View(vm); + // } } public IActionResult Login() { @@ -133,7 +133,9 @@ public async Task Announce([FromQuery] int page = 1) Title = a.Title, Author = a.Author, CreatedTime = a.CreatedTime, - IsActive = a.IsActive + IsActive = a.IsActive, + VisibleNotAfter = a.VisibleNotAfter, + VisibleExact = a.VisibleExact }).ToList()); } @@ -141,14 +143,18 @@ public async Task Announce([FromQuery] int page = 1) public async Task CreateAnnounce(AnnounceViewModel vm) { if (vm.Title is null || vm.Content is null) return BadRequest("标题或内容为空"); - var user = HttpContext.User.Identity.Name; - var a = new Announce() + vm.VisibleNotAfter ??= "9.9.9"; + vm.VisibleExact ??= ""; + var user = HttpContext.User.Identity?.Name; + var a = new Announce { Title = vm.Title, Content = vm.Content, - Author = user, + Author = user ?? "", CreatedTime = DateTime.Now, - IsActive = vm.IsActive + IsActive = vm.IsActive, + VisibleNotAfter = vm.VisibleNotAfter, + VisibleExact = vm.VisibleExact }; var result = await _data.CreateAnnounceAsync(a); if (result != 1) return BadRequest(ModelState); diff --git a/ThuInfoWeb/DBModels/Announce.cs b/ThuInfoWeb/DBModels/Announce.cs index 5e84cd3..405b3bf 100644 --- a/ThuInfoWeb/DBModels/Announce.cs +++ b/ThuInfoWeb/DBModels/Announce.cs @@ -7,12 +7,23 @@ public class Announce { [Column(IsIdentity = true, IsPrimary = true)] public int Id { get; set; } + public string Title { get; set; } + [Column(StringLength = -1)] public string Content { get; set; } + public string Author { get; set; } + public DateTime CreatedTime { get; set; } + [JsonIgnore] public bool IsActive { get; set; } + + [Column(StringLength = 10, IsNullable = false)] + public string VisibleNotAfter { get; set; } + + [Column(StringLength = 30, IsNullable = false)] + public string VisibleExact { get; set; } } -} +} \ No newline at end of file diff --git a/ThuInfoWeb/Models/AnnounceViewModel.cs b/ThuInfoWeb/Models/AnnounceViewModel.cs index 3295886..385c996 100644 --- a/ThuInfoWeb/Models/AnnounceViewModel.cs +++ b/ThuInfoWeb/Models/AnnounceViewModel.cs @@ -5,12 +5,23 @@ namespace ThuInfoWeb.Models public class AnnounceViewModel { [Required, Display(Name = "标题")] - public string Title { get; set; } + public string? Title { get; set; } + [Required, Display(Name = "内容")] - public string Content { get; set; } + public string? Content { get; set; } + public int Id { get; set; } - public string Author { get; set; } + + public string? Author { get; set; } + public DateTime CreatedTime { get; set; } + public bool IsActive { get; set; } = true; + + [Display(Name = "对此版本及之前版本可见")] + public string? VisibleNotAfter { get; set; } + + [Display(Name = "对这些版本可见 (使用逗号分隔)")] + public string? VisibleExact { get; set; } } } diff --git a/ThuInfoWeb/Views/Home/Announce.cshtml b/ThuInfoWeb/Views/Home/Announce.cshtml index befd42b..c3c03a3 100644 --- a/ThuInfoWeb/Views/Home/Announce.cshtml +++ b/ThuInfoWeb/Views/Home/Announce.cshtml @@ -23,6 +23,7 @@ ID 标题 内容 + 生效版本 作者 创建时间 是否生效 @@ -36,6 +37,15 @@ @item.Id @item.Title @item.Content + + <= + @item.VisibleNotAfter + @if (item.VisibleExact != "") + { + , + @item.VisibleExact + } + @item.Author @item.CreatedTime @item.IsActive From 1991369f3ba11754afd78d1848c28386f5988252 Mon Sep 17 00:00:00 2001 From: ajax Date: Sat, 20 Jul 2024 17:00:53 +0800 Subject: [PATCH 3/3] Updated dockerfile aspnet version --- dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dockerfile b/dockerfile index c7d1139..a182b8d 100644 --- a/dockerfile +++ b/dockerfile @@ -1,9 +1,9 @@ -FROM bitnami/dotnet-sdk:6 AS build-env +FROM bitnami/dotnet-sdk:8 AS build-env WORKDIR /build COPY . ./ RUN dotnet publish -c Release -o out -FROM bitnami/aspnet-core:6 +FROM bitnami/aspnet-core:8 WORKDIR /app COPY --from=build-env /build/out . ENTRYPOINT [ "dotnet", "ThuInfoWeb.dll"]