2018-09-13 16:34:32 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
2018-10-12 14:04:49 +08:00
|
|
|
|
using Longbow.Web.SignalR;
|
2018-09-13 16:34:32 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-10-15 21:08:54 +08:00
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
2018-11-21 21:01:50 +08:00
|
|
|
|
using System;
|
2018-09-13 16:34:32 +08:00
|
|
|
|
using System.Linq;
|
2018-10-15 21:08:54 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2018-09-13 16:34:32 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
|
{
|
2018-10-28 15:08:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 注册用户操作类
|
|
|
|
|
/// </summary>
|
2018-09-13 16:34:32 +08:00
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[Route("api/[controller]")]
|
2018-11-21 21:01:50 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class RegisterController : ControllerBase
|
2018-09-13 16:34:32 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 登录页面注册新用户remote validate调用
|
|
|
|
|
/// </summary>
|
2018-10-28 15:08:58 +08:00
|
|
|
|
/// <param name="userName"></param>
|
2018-09-13 16:34:32 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public bool Get(string userName)
|
|
|
|
|
{
|
2018-10-19 23:09:52 +08:00
|
|
|
|
return UserHelper.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName);
|
2018-09-13 16:34:32 +08:00
|
|
|
|
}
|
2018-10-11 17:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 登录页面注册新用户提交按钮调用
|
|
|
|
|
/// </summary>
|
2018-10-28 15:08:58 +08:00
|
|
|
|
/// <param name="hub"></param>
|
2018-10-11 17:03:09 +08:00
|
|
|
|
/// <param name="user"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
2018-10-15 21:08:54 +08:00
|
|
|
|
public async Task<bool> Post([FromServices]IHubContext<SignalRHub> hub, [FromBody]User user)
|
2018-10-11 17:03:09 +08:00
|
|
|
|
{
|
|
|
|
|
var ret = UserHelper.SaveUser(user);
|
2018-10-15 21:08:54 +08:00
|
|
|
|
if (ret) await SignalRManager.Send(hub.Clients.All, new MessageBody() { Category = "Users", Message = string.Format("{0}-{1}", user.UserName, user.Description) });
|
2018-10-11 17:03:09 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-09-13 16:34:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|