Skip to content

Commit a4d0094

Browse files
committed
Identity - user name and password to work with localization
1 parent 72c50fb commit a4d0094

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/App/Pages/Admin/Settings/Register.cshtml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ public async Task<IActionResult> OnPostAsync()
7070
// register new app user account
7171
var result = await _um.CreateAsync(new AppUser { UserName = UserName, Email = Email }, Password);
7272

73+
if (!result.Succeeded)
74+
{
75+
foreach (var er in result.Errors)
76+
{
77+
ModelState.AddModelError("Custom", er.Description);
78+
return Page();
79+
}
80+
}
81+
7382
// add user as author to app database
7483
var user = _db.Authors.Single(a => a.AppUserName == UserName);
7584
if (user == null)

src/App/Startup.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,16 @@ public void ConfigureServices(IServiceCollection services)
4545

4646
services.AddDbContext<AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient);
4747

48-
services.AddIdentity<AppUser, IdentityRole>()
49-
.AddEntityFrameworkStores<AppDbContext>()
50-
.AddDefaultTokenProviders();
48+
services.AddIdentity<AppUser, IdentityRole>(options => {
49+
options.Password.RequireDigit = false;
50+
options.Password.RequiredLength = 6;
51+
options.Password.RequireNonAlphanumeric = false;
52+
options.Password.RequireUppercase = false;
53+
options.Password.RequireLowercase = false;
54+
options.User.AllowedUserNameCharacters = null;
55+
})
56+
.AddEntityFrameworkStores<AppDbContext>()
57+
.AddDefaultTokenProviders();
5158

5259
services.AddLogging(loggingBuilder =>
5360
loggingBuilder.AddSerilog(dispose: true));

0 commit comments

Comments
 (0)