- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
UserManager.CreateAsync Method (TUser, String)没有提到错误。
在 Controller 中,我只是编辑如下内容:
public async Task<ObjectResult> Register(RegisterViewModel model, string returnUrl = null)
{
IDictionary<string, object> value = new Dictionary<string, object>();
value["Success"] = false;
value["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
value["Success"] = true;
}
else
{
value["ErrorMessage"] = result.Errors;
}
}
return new ObjectResult(value);
}
在客户端:
$scope.registerForm_submit = function ($event, account) {
$event.preventDefault();
if (registerForm.isValid(account)) {
// registerForm.collectData returns new FormData() which contains
// email, password, confirmpassword, agreement, returnurl...
let formData = registerForm.collectData(account),
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === XMLHttpRequest.DONE) {
let data = JSON.parse(xhttp.responseText);
if (data['Success']) {
window.location = '/'
} else {
if (data['ErrorMessage'][0]['code'] === 'DuplicateUserName') {
let li = angular.element('<li/>').text(`Email ${account['email']} already exists.`);
angular.element('div[data-valmsg-summary=true] ul').html(li);
}
}
}
}
xhttp.open('POST', '/account/register');
xhttp.send(formData);
}
};
我已尝试使用现有电子邮件注册新帐户并获得代码:
data['ErrorMessage'][0]['code'] === 'DuplicateUserName'
我的问题:如何检查其他情况?
最佳答案
在 ASP.NET Identity 中定义的错误代码位于 https://aspnetidentity.codeplex.com/SourceControl/latest#src/Microsoft.AspNet.Identity.Core/Resources.Designer.cs - 我已将它们提取到此列表中:
ASP.NET Core Identity 定义了这些代码:
因此,可能并非所有以前的错误代码都会实际显示在 IdentityResult 中。我也不使用,所以这只是我从浏览可用源代码中收集的内容。买者自负...
似乎这应该记录在某处......
我喜欢在一个地方定义这种性质的字符串,所以我通常会这样做:
public class IdentityErrorCodes
{
public const string DefaultError = "DefaultError";
public const string ConcurrencyFailure = "ConcurrencyFailure";
public const string PasswordMismatch = "PasswordMismatch";
public const string InvalidToken = "InvalidToken";
public const string LoginAlreadyAssociated = "LoginAlreadyAssociated";
public const string InvalidUserName = "InvalidUserName";
public const string InvalidEmail = "InvalidEmail";
public const string DuplicateUserName = "DuplicateUserName";
public const string DuplicateEmail = "DuplicateEmail";
public const string InvalidRoleName = "InvalidRoleName";
public const string DuplicateRoleName = "DuplicateRoleName";
public const string UserAlreadyHasPassword = "UserAlreadyHasPassword";
public const string UserLockoutNotEnabled = "UserLockoutNotEnabled";
public const string UserAlreadyInRole = "UserAlreadyInRole";
public const string UserNotInRole = "UserNotInRole";
public const string PasswordTooShort = "PasswordTooShort";
public const string PasswordRequiresNonAlphanumeric = "PasswordRequiresNonAlphanumeric";
public const string PasswordRequiresDigit = "PasswordRequiresDigit";
public const string PasswordRequiresLower = "PasswordRequiresLower";
public const string PasswordRequiresUpper = "PasswordRequiresUpper";
public static string[] All = {
DefaultError,
ConcurrencyFailure,
PasswordMismatch,
InvalidToken,
LoginAlreadyAssociated,
InvalidUserName,
InvalidEmail,
DuplicateUserName,
DuplicateEmail,
InvalidRoleName,
DuplicateRoleName,
UserAlreadyHasPassword,
UserLockoutNotEnabled,
UserAlreadyInRole,
UserNotInRole,
PasswordTooShort,
PasswordRequiresNonAlphanumeric,
PasswordRequiresDigit,
PasswordRequiresLower,
PasswordRequiresUpper
};
}
这让您可以在用作查找的键中保持一致,最后一个字段 All
为您提供一个数组,您可以在必要时枚举。
使用您的代码,您可以这样做:
if(data['ErrorMessage'][0]['code'] == IdentityErrorCodes.DuplicateUserName)
{
}
等等。
关于c# - 使用中的错误案例列表 _userManager.CreateAsync(user, password),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40583707/
我在 Controller 中有此功能,但我无法重置密码,因为我想将字符长度更改为 5 位数字。 public function postReset(Request $request) { $th
我正在学习使用 maven password encryption能力,我想知道如何选择参数 .有两件事我不明白: 1) mvn --encrypt-master-password foobar总会给
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 这个问题似乎不是关于 a specific programming problem,
我想知道其他电子商务/行业网站上“忘记密码”流程的“标准”使用率是多少?目前,没有多少人会访问我网站上的“忘记密码”链接,但这主要是因为大多数人没有密码。我正在安装新的登录名(这将鼓励人们创建密码),
从存储库中提取源代码需要我的密码。 SourceTree 默认记住此密码。我不希望 SourceTree 记住我的密码。我每次都必须禁用此功能! 如何禁用此默认行为?谢谢! 最佳答案 我在 Mac 上
这个问题已经有答案了: When to use single quotes, double quotes, and backticks in MySQL (13 个回答) 已关闭 5 年前。 Erro
我正在为我的 iOS 应用程序使用 Firebase 身份验证服务。我想通过电子邮件或谷歌登录提供商登录应用程序。我申请了firebase instractions . 我可以使用电子邮件和密码登录。
我正在尝试了解角色密码在 Postgres 中的运作方式。 https://www.postgresql.org/docs/current/static/sql-createrole.html表示加密
为什么“确认密码和密码相同”部分不起作用?意思是,使用“getElementById”来处理密码和确认密码的部分。每个部分都有效,但特定部分除外。它不会在文本字段周围显示红色框。谁能帮我吗?
我遇到了 Flutter 的 TextInputType 没有密码类型的问题: /// All possible enum values. static const List values = con
我正在尝试使用 Azure 应用服务创建应用程序。 但是,它显示上述错误:无法识别的参数: 我使用的命令是 --> az ad app create --available-to-other-tena
我正在尝试使用 Azure 应用服务创建应用程序。 但是,它显示上述错误:无法识别的参数: 我使用的命令是 --> az ad app create --available-to-other-tena
我有(数千个)包含各种(数十亿)行的 csv 文件,例如: 组合.csv example0@domain.tld:passw0rd ex.a.m-pl_e1@domain.tld;p@££w0r46&
在我的 Spring 3 MVC 应用程序中,用户需要保存密码,如果他们也能够在保存时确认密码,那将是一个不错的功能。 在 bean 中,我使用基于注释的验证。是否有注释 validator 可用于执
我在 pgsql 中创建了一个没有密码的新用户。但是当我尝试为这个用户创建一个数据库时,它提示输入密码 >createuser -d -S -R -U postgres test1 Password:
我创建了 Form 这种形式的小部件有多个 TextFormFeild 我创建了自定义 BoxFeild .我面临与 相关的问题auto-validation 来自表单小部件。无法验证确认密码中的密码
在 SQL Server 2008 R2 标准版上,每当我尝试通过报表管理器更新数据源凭据时,我都无法保存更改,因为它会报告消息 "The password is not valid. Please
我有一个用 JAVA 编写并部署在 Wildfly 8.2 上的小型 REST 应用程序。当我尝试使用 javax 安全库登录时,出现错误 FailedLoginException: Password
验证错误:子“密码”失败,因为运行测试时显示[“密码”是必需的]错误 我使用 hapijs v17.2.3 和 mongodb 作为后端。我正在尝试使用 lab 和 code 执行单元测试。这是我的t
我使用 visual studio 2010 创建了一个登录表单,其中包含用户名的输入文本和 userpass 的密码类型输入。我有最新的 chrome 版本 59.0.3071.115(官方构建)(
我是一名优秀的程序员,十分优秀!