You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using WcfControlMonitorLib;
|
|
|
|
namespace WcfControlMonitorWebLib.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 会话服务
|
|
/// </summary>
|
|
[ApiController, Route("api/sessions")]
|
|
public class SessionsController : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// 登录
|
|
/// </summary>
|
|
[HttpPost, Anonymous]
|
|
public IActionResult Login([FromMember] string account, [FromMember] string password)
|
|
{
|
|
var dr = CStaticClass.dbo.ExceSQL($"SELECT USER_ID FROM T_SYS_USER WHERE USER_ACCOUNT='{account}' AND USER_PASSWORD='{password}'").Tables[0].DefaultView.Table.Rows;
|
|
if (dr.Count > 0)
|
|
{
|
|
// 创建会话
|
|
var token = Guid.NewGuid().ToString("N");
|
|
WebSession.Store.Add(token, new WebSession { Value = account, Timestamp = DateTime.Now });
|
|
return StatusCode(201, new { token });
|
|
}
|
|
else
|
|
{
|
|
return StatusCode(401);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 注销
|
|
/// </summary>
|
|
[HttpDelete, Anonymous]
|
|
public IActionResult Logout(string token)
|
|
{
|
|
// 删除会话
|
|
if (WebSession.Store.ContainsKey(token))
|
|
{
|
|
WebSession.Store.Remove(token);
|
|
}
|
|
return StatusCode(204);
|
|
}
|
|
}
|
|
}
|