diff --git a/LoongPanel-Asp/ApplicationDbContext.cs b/LoongPanel-Asp/ApplicationDbContext.cs index 8722cd4..b9963d5 100755 --- a/LoongPanel-Asp/ApplicationDbContext.cs +++ b/LoongPanel-Asp/ApplicationDbContext.cs @@ -116,7 +116,7 @@ public class ApplicationDbContext(DbContextOptions options NormalizedName = roleName.ToUpperInvariant(), ApiPermissions = ["1","2","3","4","5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35"], - RouterPermissions = ["1", "2", "3", "4","5","6","7","8","9","10","11","12","13","14","15","16"] + RouterPermissions = ["1", "3", "4","5","6","7","8","9","10","11","12","13","14","15","16"] }); } diff --git a/LoongPanel-Asp/Controllers/AccountController.cs b/LoongPanel-Asp/Controllers/AccountController.cs index a9296e6..b483dc5 100755 --- a/LoongPanel-Asp/Controllers/AccountController.cs +++ b/LoongPanel-Asp/Controllers/AccountController.cs @@ -81,6 +81,17 @@ public class AccountController( user.Id }); } + //创建修改密码令牌 + var tokenPassword = await userManager.GeneratePasswordResetTokenAsync(user); + if (user.PasswordExpiredDate == null || user.PasswordExpiredDate < DateTimeOffset.Now) + { + //返回402 + return StatusCode(402,new + { + tokenPassword, + user.Id, + }); + } var roles = await userManager.GetRolesAsync(user); var roleId = roles.ToList()[0]; // 直接获取角色ID列表 var claimsIdentity = new ClaimsIdentity(new[] @@ -90,16 +101,7 @@ public class AccountController( new Claim(ClaimTypes.Role, roleId.ToLower()) // 将角色ID列表转换为逗号分隔的字符串 }); var token = tokenHelper.GenerateToken(claimsIdentity); - if (user.PasswordExpiredDate == null || user.PasswordExpiredDate < DateTimeOffset.Now) - { - //返回402 - return StatusCode(402,new - { - token, - user.Id, - }); - } - + return Ok(new { user.NickName, @@ -128,32 +130,14 @@ public class AccountController( return Ok("邮件已发送"); } [HttpGet("ChangePassword")] - public async Task ChangePassword([FromQuery] string currentPassword,[FromQuery] string newPassword) + public async Task ChangePassword([FromQuery] string userId, [FromQuery] string token,[FromQuery] string newPassword) { // 获取当前经过身份验证的用户 - var authenticatedUser = await userManager.GetUserAsync(HttpContext.User); - + var authenticatedUser = await userManager.FindByIdAsync(userId); if (authenticatedUser == null) { - return BadRequest("用户未登录"); + return BadRequest("用户不存在"); } - - // 检查当前密码是否正确 - var isCurrentPasswordValid = await userManager.CheckPasswordAsync(authenticatedUser, currentPassword); - if (!isCurrentPasswordValid) - { - return BadRequest("当前密码不正确"); - } - - // 检查新密码是否与旧密码相同 - if (currentPassword == newPassword) - { - return BadRequest("新密码不能与旧密码相同"); - } - - // 生成密码重置令牌 - var token = await userManager.GeneratePasswordResetTokenAsync(authenticatedUser); - // 重置密码 var result = await userManager.ResetPasswordAsync(authenticatedUser, token, newPassword); diff --git a/LoongPanel-Asp/Controllers/RoteController.cs b/LoongPanel-Asp/Controllers/RoteController.cs index 6c9e2f8..a2dd959 100755 --- a/LoongPanel-Asp/Controllers/RoteController.cs +++ b/LoongPanel-Asp/Controllers/RoteController.cs @@ -21,10 +21,15 @@ public class RoteController( var rotes = role!.RouterPermissions.ToList(); //获取路由列表 var apiPermissions = dbContext.RotePermissions.ToList().Where(x => rotes.Any(y => y == x.Id.ToString())).Select(x=>x.Router).ToList(); + //如果rotes 中包括* + if (rotes.Contains("*")) + { + return Ok("权限验证通过"); + } //将path全部小写 path = path.ToLower(); //使用正则匹配 var firstOrDefault = apiPermissions.FirstOrDefault(x => Regex.IsMatch(path,x)); - return Ok(firstOrDefault != null ? new ApiResponse(ApiResponseState.Success) : new ApiResponse(ApiResponseState.Forbidden)); + return Ok(firstOrDefault != null ? Ok("权限验证通过") : Unauthorized("你不具有访问此资源的权力")); } } \ No newline at end of file diff --git a/LoongPanel-Asp/LoongPanel-Asp.csproj b/LoongPanel-Asp/LoongPanel-Asp.csproj index 805ab29..52adf0a 100755 --- a/LoongPanel-Asp/LoongPanel-Asp.csproj +++ b/LoongPanel-Asp/LoongPanel-Asp.csproj @@ -43,9 +43,6 @@ PreserveNewest - - Never - diff --git a/LoongPanel-Asp/Properties/launchSettings.json b/LoongPanel-Asp/Properties/launchSettings.json index d43adb8..07f55f2 100755 --- a/LoongPanel-Asp/Properties/launchSettings.json +++ b/LoongPanel-Asp/Properties/launchSettings.json @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": false, "launchUrl": "swagger", - "applicationUrl": "http://192.168.0.13:5253", + "applicationUrl": "http://127.0.0.1:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/LoongPanel-Asp/appsettings.json b/LoongPanel-Asp/appsettings.json index eb177b1..921d13d 100755 --- a/LoongPanel-Asp/appsettings.json +++ b/LoongPanel-Asp/appsettings.json @@ -20,5 +20,5 @@ "Secret": "p4Qzf/+GPP/XNLalZGCzwlelOl6skiFZscj6iZ6rZZE=", "Issuer": "LoongPanel", "Audience": "LoongPanel", - "PubLicApi": "/Api/Account/Login;/Api/Account/VerifyEmail;/Api/Account/ForgotPassword;/Api/Account/ResetPassword;" + "PubLicApi": "/Api/Account/Login;/Api/Account/VerifyEmail;/Api/Account/ForgotPassword;/Api/Account/ResetPassword;/Api/Account/ChangePassword" } diff --git a/LoongPanel-Asp/apptemp.db b/LoongPanel-Asp/apptemp.db index c5ea5ea..1fef4b3 100644 Binary files a/LoongPanel-Asp/apptemp.db and b/LoongPanel-Asp/apptemp.db differ diff --git a/web/middleware/auth.ts b/web/middleware/auth.ts index fe5ef93..b54db43 100755 --- a/web/middleware/auth.ts +++ b/web/middleware/auth.ts @@ -1,9 +1,7 @@ -import type {HttpType} from "~/types/baseType"; import {defineNuxtRouteMiddleware} from "#app"; import {useToast} from 'vue-toastification' -interface RouteBackType extends HttpType { -} + export default defineNuxtRouteMiddleware(async (to, from) => { const toast = useToast(); @@ -21,9 +19,8 @@ export default defineNuxtRouteMiddleware(async (to, from) => { // 获取当前导航路径 const currentPath = to.path; - try { - const response = await $fetch('/Api/Rote/RoteVerify', { + await $fetch('/Api/Rote/RoteVerify', { method: 'GET', headers: { 'Authorization': 'Bearer ' + token @@ -31,27 +28,10 @@ export default defineNuxtRouteMiddleware(async (to, from) => { baseURL: runtimeConfig.public.baseUrl, params: {'path': currentPath} }); - - // 直接从响应中获取状态码 - const data = response as HttpType; - if (data.code !== 200) { - toast.error('未登录', {timeout: 3000}) - - if (data.code === 403) { - if (to.path === from.path) { - return navigateTo("/Home"); - } - return navigateTo(from.path); - } - - return navigateTo("/SignIn"); - } - } catch (error) { - // 处理错误情况 - console.error('请求验证路由时发生错误:', error); - toast.error('请求错误', {timeout: 3000}) - return navigateTo("/SignIn"); + // 如果验证成功,继续导航 + return true; + } catch (err) { + toast.error('权限不足', {timeout: 3000}); + return navigateTo("/error/403"); } - - return true; }); diff --git a/web/pages/changePassword/[[id]].vue b/web/pages/changePassword.vue similarity index 86% rename from web/pages/changePassword/[[id]].vue rename to web/pages/changePassword.vue index ea7a081..c4bc748 100644 --- a/web/pages/changePassword/[[id]].vue +++ b/web/pages/changePassword.vue @@ -1,7 +1,6 @@