|
|
@@ -0,0 +1,93 @@
|
|
|
+using Attribute;
|
|
|
+using Base;
|
|
|
+using Common;
|
|
|
+using Dto;
|
|
|
+using Enums;
|
|
|
+using Extensions;
|
|
|
+using Filters;
|
|
|
+using Infrastructure;
|
|
|
+using Infrastructure.Model;
|
|
|
+using Mapster;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Middleware;
|
|
|
+using Model;
|
|
|
+using Model.Base;
|
|
|
+using Services;
|
|
|
+using Util;
|
|
|
+using Vo;
|
|
|
+
|
|
|
+namespace Controllers.Feign
|
|
|
+{
|
|
|
+ public class VsCodeController : BaseController
|
|
|
+ {
|
|
|
+ private readonly ISysUserService sysUserService;
|
|
|
+ private readonly ISysPermissionService permissionService;
|
|
|
+ private readonly ISysRoleService roleService;
|
|
|
+ private readonly ISysLoginService sysLoginService;
|
|
|
+
|
|
|
+ public VsCodeController(ISysUserService sysUserService, ISysPermissionService permissionService, ISysRoleService roleService, ISysLoginService sysLoginService)
|
|
|
+ {
|
|
|
+ this.sysUserService = sysUserService;
|
|
|
+ this.permissionService = permissionService;
|
|
|
+ this.roleService = roleService;
|
|
|
+ this.sysLoginService = sysLoginService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// vscode登录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("/api/vscode/login")]
|
|
|
+ public IActionResult login([FromBody] VsLoginDto param)
|
|
|
+ {
|
|
|
+ SysUser user = sysUserService.GetFirst(m => m.username == param.username) ?? new SysUser();
|
|
|
+ string password = Function.MD532(param.password + user.salt);
|
|
|
+ if(password != user.password)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "用户名或密码错误");
|
|
|
+ }
|
|
|
+ List<SysRole> roles = roleService.SelectUserRoleListByUserId(user.userId);
|
|
|
+ List<string> permissions = permissionService.GetMenuPermission(user);
|
|
|
+ TokenModel loginUser = new(user.Adapt<TokenModel>(), roles.Adapt<List<Roles>>());
|
|
|
+ CacheService.SetUserPerms(GlobalConstant.UserPermKEY + user.userId, permissions);
|
|
|
+ var result = sysLoginService.GetLoginInfo(loginUser);
|
|
|
+ loginUser.refreshToken = result.refresh_token;
|
|
|
+ return SUCCESS(new LoginVo
|
|
|
+ {
|
|
|
+ token = result.access_token,
|
|
|
+ refreshToken = result.refresh_token
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// vscode刷新Token
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("/api/vscode/refreshToken")]
|
|
|
+ public IActionResult refreshToken([FromBody] VsRefreshTokenDto param)
|
|
|
+ {
|
|
|
+ TokenModel tokenModel = JwtUtil.GetLoginUser(HttpContext);
|
|
|
+ if(tokenModel == null)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "用户未登录");
|
|
|
+ }
|
|
|
+ if(tokenModel.refreshToken != param.refreshToken)
|
|
|
+ {
|
|
|
+ return ToResponse(ResultCode.BAD_REQUEST, "刷新令牌错误");
|
|
|
+ }
|
|
|
+ SysUser user = sysUserService.GetFirst(m => m.userId == tokenModel.userId) ?? new SysUser();
|
|
|
+ List<SysRole> roles = roleService.SelectUserRoleListByUserId(user.userId);
|
|
|
+ List<string> permissions = permissionService.GetMenuPermission(user);
|
|
|
+ TokenModel loginUser = new(user.Adapt<TokenModel>(), roles.Adapt<List<Roles>>());
|
|
|
+ CacheService.SetUserPerms(GlobalConstant.UserPermKEY + user.userId, permissions);
|
|
|
+ var result = sysLoginService.GetLoginInfo(loginUser);
|
|
|
+ return SUCCESS(new LoginVo
|
|
|
+ {
|
|
|
+ token = result.access_token,
|
|
|
+ refreshToken = result.refresh_token
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|