|
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Caching.Memory;
|
using Newtonsoft.Json;
|
using StackExchange.Profiling;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Authorization;
|
using WIDESEAWCS_Core.BaseController;
|
using WIDESEAWCS_Core.Const;
|
using WIDESEAWCS_Core.Extensions;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_Core.HttpContextUser;
|
using WIDESEAWCS_Core.Utilities;
|
using WIDESEAWCS_DTO.SerialPort;
|
using WIDESEAWCS_DTO.Telescopic;
|
using WIDESEAWCS_ISystemServices;
|
using WIDESEAWCS_Model;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_WCSServer.Controllers
|
{
|
[Route("api/User")]
|
[ApiController]
|
public class Sys_UserController : ApiBaseController<ISys_UserService, Sys_User>
|
{
|
|
public Sys_UserController(ISys_UserService userService) : base(userService)
|
{
|
}
|
[HttpPost, Route("FaceCompareFeature"), AllowAnonymous]
|
public WebResponseContent FaceCompareFeature(string file1, string file2)
|
{
|
var score = Service.FaceCompareFeature(file1, file2);
|
return WebResponseContent.Instance.OK(data: "data:" + score);
|
}
|
|
[HttpPost, Route("swgLogin"), AllowAnonymous]
|
public dynamic SwgLogin([FromBody] SwaggerLoginRequest loginRequest)
|
{
|
if (loginRequest is null)
|
{
|
return new { result = false };
|
}
|
|
try
|
{
|
LoginInfo loginInfo = new LoginInfo
|
{
|
Password = loginRequest.pwd,
|
UserName = loginRequest.name
|
};
|
var result = Service.Login(loginInfo);
|
if (result.Status)
|
{
|
HttpContext.SuccessSwagger();
|
Dictionary<string, object>? dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(result.Data.Serialize());
|
if (dict != null)
|
{
|
HttpContext.SuccessSwaggerJwt((dict.ContainsKey("token") ? dict["token"].ToString() : "") ?? "");
|
}
|
string str = HttpContext.GetSuccessSwaggerJwt();
|
return new { result = true };
|
}
|
}
|
catch (Exception ex)
|
{
|
|
}
|
|
return new { result = false };
|
}
|
|
|
[HttpPost, Route("login"), AllowAnonymous]
|
public IActionResult Login([FromBody] LoginInfo loginInfo)
|
{
|
var result = Json(Service.Login(loginInfo));
|
return result;
|
}
|
[HttpPost, Route("getCurrentUserInfo")]
|
public WebResponseContent GetCurrentUser()
|
{
|
return Service.GetCurrentUserInfo();
|
}
|
|
[HttpPost, Route("modifyPwd")]
|
public IActionResult ModifyPwd(string oldPwd, string newPwd)
|
{
|
return Json(Service.ModifyPwd(oldPwd, newPwd));
|
}
|
|
[HttpGet, Route("getVierificationCode"), AllowAnonymous]
|
public IActionResult GetVierificationCode()
|
{
|
//var html = MiniProfiler.Current.RenderIncludes(_httpContextAccessor.HttpContext);
|
string code = "1234" /*VierificationCode.RandomText()*/;
|
var data = new
|
{
|
img = VierificationCode.CreateBase64Imgage(code),
|
uuid = Guid.NewGuid()
|
};
|
|
return Json(data);
|
}
|
[HttpGet, Route("SerializeJwt"), AllowAnonymous]
|
public WebResponseContent SerializeJwt(string code)
|
{
|
return WebResponseContent.Instance.OK(data: JwtHelper.SerializeJwt(code));
|
}
|
[HttpPost, Route("replaceToken")]
|
public WebResponseContent ReplaceToken()
|
{
|
WebResponseContent responseContent = new WebResponseContent();
|
try
|
{
|
string token = App.User.GetToken();
|
if (string.IsNullOrEmpty(token))
|
{
|
return responseContent = WebResponseContent.Instance.Error("token无效,请重新登录!");
|
}
|
TokenModelJwt tokenModelJwt = new TokenModelJwt()
|
{
|
RoleId = App.User.RoleId,
|
TenantId = App.User.TenantId,
|
UserId = App.User.UserId,
|
UserName = App.User.UserName
|
};
|
string newToken = JwtHelper.IssueJwt(tokenModelJwt);
|
return responseContent = WebResponseContent.Instance.OK(data: newToken);
|
}
|
catch (Exception ex)
|
{
|
return responseContent.Error(ex.Message);
|
}
|
}
|
|
|
/// <summary>
|
/// 修改用户密码
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="oldPwd"></param>
|
/// <param name="newPwd"></param>
|
/// <returns></returns>
|
[HttpPost, Route("UpdatePwd")]
|
public WebResponseContent UpdatePwd(int id, string oldPwd, string newPwd)
|
{
|
return Service.UpdatePwd(id, oldPwd, newPwd);
|
}
|
|
|
|
/// <summary>
|
/// 更新用户信息
|
/// </summary>
|
/// <param name="userDTO"></param>
|
/// <returns></returns>
|
[HttpPost, Route("Upuserbase"), AllowAnonymous]
|
public WebResponseContent Upuserbase([FromBody] UserDTO userDTO)
|
{
|
return Service.Upuserbase(userDTO);
|
}
|
|
|
/// <summary>
|
/// 上传图片文件名
|
/// </summary>
|
/// <param name="files"></param>
|
/// <param name="sys_User"></param>
|
/// <returns></returns>
|
[HttpPost, Route("SaveFiles"), AllowAnonymous]
|
public WebResponseContent SaveFiles(IFormCollection files)
|
{
|
return Service.SaveFiles(files);
|
}
|
|
/// <summary>
|
/// 添加用户
|
/// </summary>
|
/// <param name="addUserDTO"></param>
|
/// <returns></returns>
|
[HttpPost, Route("AdduserData"), AllowAnonymous]
|
public WebResponseContent AdduserData([FromBody] AddUserDTO addUserDTO)
|
{
|
return Service.AdduserData(addUserDTO);
|
}
|
|
/// <summary>
|
/// 更新用户
|
/// </summary>
|
/// <param name="addUserDTO"></param>
|
/// <returns></returns>
|
[HttpPost, Route("UpuserData"), AllowAnonymous]
|
public WebResponseContent UpuserData([FromBody] AddUserDTO addUserDTO)
|
{
|
return Service.UpuserData(addUserDTO);
|
}
|
|
/// <summary>
|
/// 删除用户
|
/// </summary>
|
/// <param name="deleteUserDTO"></param>
|
/// <returns></returns>
|
[HttpPost, Route("DeleteUserData"), AllowAnonymous]
|
public WebResponseContent DeleteUserData(string userAccount)
|
{
|
return Service.DeleteUserData(userAccount);
|
}
|
|
|
/// <summary>
|
/// 登入后清除这次全部调用SaveFaceFiles方法的图片
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet, Route("CleanUnusedImages"), AllowAnonymous]
|
public WebResponseContent CleanUnusedImages()
|
{
|
return Service.CleanUnusedImages();
|
}
|
|
/// <summary>
|
///人脸登入时调用该方法上传图片
|
/// </summary>
|
/// <param name="files"></param>
|
/// <returns></returns>
|
[HttpPost, Route("SaveFaceFiles"), AllowAnonymous]
|
public WebResponseContent SaveFaceFiles(IFormCollection files)
|
{
|
return Service.SaveFaceFiles(files);
|
}
|
|
|
|
/// <summary>
|
/// //人脸删除(删除用户的某一张人脸,如果该用户只有一张人脸图片,则同时删除用户。)
|
/// </summary>
|
/// <param name="addUserDTO"></param>
|
/// <returns></returns>
|
[HttpPost, Route("DeleteUserIsface"), AllowAnonymous]
|
public WebResponseContent DeleteUserIsface(string account)
|
{
|
return Service.DeleteUserIsface(account);
|
}
|
|
|
[HttpPost, Route("YShowUserList"),AllowAnonymous]
|
public WebResponseContent YShowUserList([FromBody] PaginationDTO pagination)
|
{
|
return Service.YShowUserList(pagination);
|
}
|
|
[HttpPost, Route("DelUserList"), AllowAnonymous]
|
public WebResponseContent DelUserList([FromBody] int[] keys)
|
{
|
return Service.DelUserList(keys);
|
}
|
|
}
|
|
public class SwaggerLoginRequest
|
{
|
public string name { get; set; }
|
public string pwd { get; set; }
|
}
|
}
|