public IHttpActionResult Login([FromBody] ActionsLoginBody body) { try { var request = new AuthRequest(); string userName; string errorMessage; if (!DataProvider.AdministratorDao.Validate(body.Account, body.Password, true, out userName, out errorMessage)) { DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfFailedLogin(userName); // 记录最后登录时间、失败次数+1 return(BadRequest(errorMessage)); } var adminInfo = DataProvider.AdministratorDao.GetByUserName(userName); DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfLogin(userName); // 记录最后登录时间、失败次数清零 var accessToken = request.AdminLogin(userName, body.IsAutoLogin); return(Ok(new { Value = adminInfo, AccessToken = accessToken })); } catch (Exception ex) { LogUtils.AddErrorLog(ex); return(InternalServerError(ex)); } }
public IHttpActionResult Main() { try { var request = new AuthRequest(); var account = request.GetPostString("account"); var password = request.GetPostString("password"); if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password)) { return(Unauthorized()); } string userName; string errorMessage; if (!DataProvider.AdministratorDao.Validate(account, password, false, out userName, out errorMessage)) { LogUtils.AddAdminLog(userName, "后台管理员登录失败"); DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfFailedLogin(userName); return(Unauthorized()); } DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfLogin(userName); request.AdminLogin(userName); return(Ok(new { UserName = userName })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public override void Submit_OnClick(object sender, EventArgs e) { var account = TbAccount.Text; var password = TbPassword.Text; if (!_vcManager.IsCodeValid(TbValidateCode.Text)) // 检测验证码是否正确 { LtlMessage.Text = GetMessageHtml("验证码不正确,请重新输入!"); return; } string userName; string errorMessage; if (!DataProvider.AdministratorDao.ValidateAccount(account, password, out userName, out errorMessage)) // 检测密码是否正确 { LogUtils.AddAdminLog(userName, "后台管理员登录失败"); DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfFailedLogin(userName); // 记录最后登录时间、失败次数+1 LtlMessage.Text = GetMessageHtml(errorMessage); // 把错误信息显示在页面上 return; } DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfLogin(userName); // 记录最后登录时间、失败次数清零 AuthRequest.AdminLogin(userName); // 写Cookie并记录管理员操作日志 PageUtils.Redirect(PageUtils.GetAdminDirectoryUrl(string.Empty)); // 跳转到登录成功的后台页 }