Skip to content

Commit 200f723

Browse files
authored
Prevent registering if disabled (skoruba#25)
1 parent 7bb0053 commit 200f723

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/Skoruba.IdentityServer4.STS.Identity/Controllers/AccountController.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,15 @@ public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null,
381381
}
382382

383383
// If the user does not have an account, then ask the user to create an account.
384-
ViewData["ReturnUrl"] = returnUrl;
385-
ViewData["LoginProvider"] = info.LoginProvider;
386-
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
384+
if (_registerConfiguration.Enabled)
385+
{
386+
ViewData["ReturnUrl"] = returnUrl;
387+
ViewData["LoginProvider"] = info.LoginProvider;
388+
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
387389

388-
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = email });
390+
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = email });
391+
}
392+
return RedirectToLocal(returnUrl);
389393
}
390394

391395
[HttpPost]
@@ -422,19 +426,22 @@ public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirma
422426
Email = model.Email
423427
};
424428

425-
var result = await _userManager.CreateAsync(user);
426-
if (result.Succeeded)
429+
if (_registerConfiguration.Enabled)
427430
{
428-
result = await _userManager.AddLoginAsync(user, info);
431+
var result = await _userManager.CreateAsync(user);
429432
if (result.Succeeded)
430433
{
431-
await _signInManager.SignInAsync(user, isPersistent: false);
434+
result = await _userManager.AddLoginAsync(user, info);
435+
if (result.Succeeded)
436+
{
437+
await _signInManager.SignInAsync(user, isPersistent: false);
432438

433-
return RedirectToLocal(returnUrl);
439+
return RedirectToLocal(returnUrl);
440+
}
434441
}
435-
}
436442

437-
AddErrors(result);
443+
AddErrors(result);
444+
}
438445
}
439446

440447
ViewData["LoginProvider"] = info.LoginProvider;

0 commit comments

Comments
 (0)