public async Task <object> RegistUserAsync([FromBody] UserRegistModel model) { if (string.IsNullOrWhiteSpace(model.UserName)) { return(BadRequest(WebResultHelper.JsonMessageResult("用户名不能为空"))); } if (string.IsNullOrWhiteSpace(model.Password)) { return(BadRequest(WebResultHelper.JsonMessageResult("密码不能为空"))); } GeneralResponse result = await userService.RegistUserAsync(new Extension.UserRegistModel { Name = model.UserName, Password = model.Password, PositionId = model.PositionId }); if (result.IsSuccess) { return(Ok()); } return(BadRequest(WebResultHelper.JsonMessageResult(result.Message))); }
public async Task <object> LoginAsync(LoginModel model) { UserLoginResponse result = await userService.UserLoginAsync(new Extension.LoginModel { Name = model.UserName, Password = model.Password }); if (result.IsSuccess) { //HttpContext.Session.SetString("Token", result.Token); return(Ok(new { result.Token })); } return(BadRequest(WebResultHelper.JsonMessageResult("用户名或密码错误"))); }
public Task Invoke( HttpContext context, AuthorizationTagService authorizationTagService, VerificationService verificationService, UserService userService, IServiceProvider serviceProvider) { string result; string controllerName = (string)context.GetRouteValue("controller"); string actionName = (string)context.GetRouteValue("action"); //查询用户信息 string token = getTokenFunc(context, serviceProvider); userService.SetToken(token); //Task.Run(async () => //{ // await userService.GetUserInfoAsync(); //}); //没有AuthorizationTagAttribute,直接放行 if (!authorizationTagService.ActionHasTag(controllerName, actionName)) { log.LogTrace($"{controllerName} {actionName} has no tag"); return(_next(context)); } //id不为空时,再判断是否需要认证 if (!string.IsNullOrWhiteSpace(token)) { if (verificationService.AllowAccess(controllerName, actionName)) { return(_next(context)); } result = WebResultHelper.JsonMessageResult("没有访问权限"); } else { result = WebResultHelper.JsonMessageResult("请先登录"); } context.Response.StatusCode = 401; context.Response.ContentType = "application/json"; context.Response.WriteAsync(result); return(Task.CompletedTask); }