public IActionResult Login(UserLoginCommand command) { if (null == command) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (command.Account.IsNullOrWhitespace() || command.Passwrd.IsNullOrWhitespace()) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (command.VerifyCode != HttpContext.Session.GetString("verifycode")) { HttpContext.Session.Remove("verifycode"); return(Json(new { code = -1, msg = "Error:验证码错误", url = string.Empty })); } var commandResult = this._commandInvokerFactory.Handle <UserLoginCommand, UserLoginCommandResult>(command); if (!commandResult.IsSuccess) { return(Json(new { code = -1, msg = $"错误:{commandResult.GetErrors()[0]}", url = string.Empty })); } // 登陆验证成功 HttpContext.Session.Remove("verifycode"); AccountLoginManager.SetLogin(HttpContext, commandResult); return(Json(new { code = 1, msg = "Success:登陆成功", url = command.ReturnUrl.IsNullOrWhitespace() ? "/Admin/Index" : command.ReturnUrl })); }
public IActionResult Register(UserRegisterCommand command) { if (null == command) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (command.UserAccount.IsNullOrWhitespace()) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (command.Password.IsNullOrWhitespace()) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (command.ConfirmPassword.IsNullOrWhitespace()) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (command.Password != command.ConfirmPassword) { return(Json(new { code = -1, msg = "Error:数据不正确", url = string.Empty })); } else if (this.CheckAccount(this._commandInvokerFactory)) { return(Json(new { code = 1, msg = "Error:已存在后台管理账号", url = "/Account/Index" })); } var commandResult = this._commandInvokerFactory.Handle <UserRegisterCommand, UserLoginCommandResult>(command); if (!commandResult.IsSuccess) { return(Json(new { code = -1, msg = $"错误:{commandResult.GetErrors()[0]}", url = string.Empty })); } AccountLoginManager.SetLogin(HttpContext, commandResult); return(Json(new { code = 1, msg = "Success:注册成功", url = "/Admin/Index" })); }