using Bootstrap.DataAccess; using Longbow.Web.SignalR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using System.Linq; using System.Threading.Tasks; namespace Bootstrap.Admin.Controllers.Api { /// /// 注册用户操作类 /// [AllowAnonymous] [Route("api/[controller]")] [ApiController] public class RegisterController : ControllerBase { /// /// 登录页面注册新用户remote validate调用 /// /// /// [HttpGet] public bool Get(string userName) { return UserHelper.RetrieveUserByUserName(userName) == null && !UserHelper.RetrieveNewUsers().Any(u => u.UserName == userName); } /// /// 登录页面注册新用户提交按钮调用 /// /// /// /// [HttpPost] public async Task Post([FromServices]IHubContext hub, [FromBody]User user) { var ret = UserHelper.Save(user); if (ret) await SignalRManager.Send(hub.Clients.All, new MessageBody() { Category = "Users", Message = string.Format("{0}-{1}", user.UserName, user.Description) }); return ret; } /// /// 重置密码调用 /// /// /// [HttpPut("{userName}")] public bool Put(string userName, [FromBody]User user) => UserHelper.ResetPassword(userName, user.Password); /// /// 忘记密码调用 /// /// /// [HttpPut] public bool Put([FromBody]ResetUser user) { if (UserHelper.RetrieveUserByUserName(user.UserName) == null) return true; return UserHelper.ForgotPassword(user); } } }