AccountController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Bowin.Common.ServiceToken;
  6. using Bowin.Common.ServiceToken.Permission;
  7. using Bowin.Common.WebModels;
  8. using YLShipBuildLandMap.Entity.ViewModel;
  9. using YLShipBuildLandMap.Services.SystemSetting;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.Extensions.Logging;
  13. using Newtonsoft.Json.Linq;
  14. using Bowin.Common.DES;
  15. using Bowin.Common.Cache;
  16. namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
  17. {
  18. [Route("api/systemsetting/[controller]/[action]")]
  19. [Authorize]
  20. public class AccountController : ControllerBase
  21. {
  22. private IUserService UserService { get; set; }
  23. private IFunctionCodeService FunctionCodeService { get; set; }
  24. readonly IDesAccessor DesAccessor;
  25. public AccountController(IUserService userService, IFunctionCodeService functionCodeService,IDesAccessor desAccessor)
  26. {
  27. UserService = userService;
  28. FunctionCodeService = functionCodeService;
  29. this.DesAccessor = desAccessor;
  30. }
  31. [AllowAnonymous]
  32. [HttpPost]
  33. public ResultMessage GetToken([FromBody] DesModel inputObject)
  34. {
  35. var data = this.DesAccessor.DeDesToken(inputObject);
  36. var datas = data.Split('|');
  37. string loginID = datas[0];
  38. string pdmd = datas[1];
  39. string verfiyKey = datas[2];
  40. string verfiyCode = datas[3];
  41. if (CacheHelper.Get(verfiyKey)?.ToString() != verfiyCode.ToUpper())
  42. {
  43. CacheHelper.Remove(verfiyKey);
  44. return ResultMessage.GetError("验证码错误,请重新输入。");
  45. }
  46. else
  47. {
  48. CacheHelper.Remove(verfiyKey);
  49. }
  50. ResultMessage result = new ResultMessage();
  51. var token = JwtHelper.GetToken(() => UserService.Login(loginID, pdmd), (x => x.UserID));
  52. return ResultMessage.Success(token);
  53. }
  54. [AllowAnonymous]
  55. [HttpPost]
  56. public ResultMessage TestToken([FromBody] DesModel inputObject)
  57. {
  58. var data = this.DesAccessor.DeDesToken(inputObject);
  59. return ResultMessage.Success(data);
  60. }
  61. [HttpPost]
  62. public ResultMessage GetUserFunctionCode()
  63. {
  64. return ResultMessage.Success(FunctionCodeService.GetUserFunctionCodes(LoginUser.Current.UserID));
  65. }
  66. [HttpPost]
  67. public ResultMessage RefreshToken()
  68. {
  69. return ResultMessage.Success(JwtHelper.RefreshToken<LoginUser>());
  70. }
  71. [HttpPost]
  72. public ResultMessage GetUsersForSelect([FromBody] dynamic inputObj)
  73. {
  74. string loginID = inputObj.loginID;
  75. string name = inputObj.name;
  76. int? pageIndex = inputObj.pageIndex;
  77. int? pageSize = inputObj.pageSize;
  78. return ResultMessage.Success(UserService.GetUserViewsForSelect(loginID, name, pageIndex, pageSize));
  79. }
  80. [HttpPost]
  81. public ResultMessage GetAllUsersForSelect([FromBody] dynamic inputObj)
  82. {
  83. string loginID = inputObj.loginID;
  84. string name = inputObj.name;
  85. bool isAllUser = true;
  86. int? pageIndex = inputObj.pageIndex;
  87. int? pageSize = inputObj.pageSize;
  88. return ResultMessage.Success(UserService.GetUserViewsForSelect(loginID, name, pageIndex, pageSize,null, isAllUser));
  89. }
  90. [HttpPost]
  91. public ResultMessage Test([FromBody] dynamic inputObject)
  92. {
  93. DateTime? testTime = inputObject.testTime;
  94. return ResultMessage.Success();
  95. }
  96. }
  97. }