我正在尝试使用 Flutter 实现最佳的 UX AutovalidateMode.onUserInteraction。
选项1
当我在表单键上设置验证时,当用户尝试输入一个 texField 时,整个表单会变成红色并出现错误。
child: Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
Run Code Online (Sandbox Code Playgroud)
选项2
当我 AutovalidateMode.onUserInteraction在每个文本字段上设置时,当用户尝试键入时,我最终会在每个文本字段上收到错误,并且当他们完成输入时错误会消失。
RoundedPasswordResetField(
validator: (value) {
if (value.isEmpty) {
return 'Please Re-enter Password';
}
if (password != confirmpassword) {
return "Password does not match";
}
//
return null;
},
autovalidateMode: AutovalidateMode.onUserInteraction,
hintText: "Please Re-enter Password",
onChanged: (value) {
confirmpassword = value;
},
),
Run Code Online (Sandbox Code Playgroud)
选项3
当我将其设置为 时autovalidateMode: AutovalidateMode.disabled,,当用户尝试在字段为空时提交字段时,会出现错误,但是当他们键入特定的正确详细信息时,错误不会清除
RoundedPasswordResetField(
validator: (value) {
if (value.isEmpty) {
return 'Please Re-enter Password';
}
if …Run Code Online (Sandbox Code Playgroud) 我正在使用 dot net core 编写一个 Web api。当用户输入无效的用户名或密码时,我想返回无效的用户名或密码作为 json 响应,该功能很简单。我怎样才能在 dot net core 中做到这一点,我已经成功返回了这个
用户名或密码无效
我怎样才能返回这个
{ "message": "Invalid Login credentials!" }
这是我的控制器
[HttpPost]
[Route("/api/[controller]/signin")]
public async Task<IActionResult> Login([FromBody] LoginViewModel loginmodel)
{
if (!ModelState.IsValid)
{
//return BadRequestModelState();
return Conflict(new ErrorViewModel("Wrong data sent"));
}
Users user = await _userService.GetByEmail(loginmodel.Username);
if (user == null)
{
return this.StatusCode(StatusCodes.Status401Unauthorized, "Invalid username or password");
}
bool isCorrectPassword = _passwordHasher.VerifyPassword(loginmodel.Password, user.Password);
if (!isCorrectPassword)
{
return this.StatusCode(StatusCodes.Status401Unauthorized, "Invalid username or password");
}
}
Run Code Online (Sandbox Code Playgroud)