Server admin can add new user

This commit is contained in:
nicolas.dorier
2018-08-02 00:16:16 +09:00
parent a1a4eed860
commit 846bd08e20
4 changed files with 28 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ using BTCPayServer.Services.Mails;
using BTCPayServer.Services.Stores; using BTCPayServer.Services.Stores;
using BTCPayServer.Logging; using BTCPayServer.Logging;
using BTCPayServer.Security; using BTCPayServer.Security;
using System.Globalization;
namespace BTCPayServer.Controllers namespace BTCPayServer.Controllers
{ {
@@ -236,23 +237,25 @@ namespace BTCPayServer.Controllers
[HttpGet] [HttpGet]
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> Register(string returnUrl = null) public async Task<IActionResult> Register(string returnUrl = null, bool logon = true)
{ {
var policies = await _SettingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings(); var policies = await _SettingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
if (policies.LockSubscription) if (policies.LockSubscription && !User.IsInRole(Roles.ServerAdmin))
return RedirectToAction(nameof(HomeController.Index), "Home"); return RedirectToAction(nameof(HomeController.Index), "Home");
ViewData["ReturnUrl"] = returnUrl; ViewData["ReturnUrl"] = returnUrl;
ViewData["Logon"] = logon.ToString(CultureInfo.InvariantCulture).ToLowerInvariant();
return View(); return View();
} }
[HttpPost] [HttpPost]
[AllowAnonymous] [AllowAnonymous]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null) public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null, bool logon = true)
{ {
ViewData["ReturnUrl"] = returnUrl; ViewData["ReturnUrl"] = returnUrl;
ViewData["Logon"] = logon.ToString(CultureInfo.InvariantCulture).ToLowerInvariant();
var policies = await _SettingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings(); var policies = await _SettingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
if (policies.LockSubscription) if (policies.LockSubscription && !User.IsInRole(Roles.ServerAdmin))
return RedirectToAction(nameof(HomeController.Index), "Home"); return RedirectToAction(nameof(HomeController.Index), "Home");
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
@@ -274,6 +277,7 @@ namespace BTCPayServer.Controllers
await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);
if (!policies.RequiresConfirmedEmail) if (!policies.RequiresConfirmedEmail)
{ {
if(logon)
await _signInManager.SignInAsync(user, isPersistent: false); await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToLocal(returnUrl); return RedirectToLocal(returnUrl);
} }

View File

@@ -137,6 +137,23 @@ namespace BTCPayServer
request.PathBase.ToUriComponent()); request.PathBase.ToUriComponent());
} }
public static string GetCurrentUrl(this HttpRequest request)
{
return string.Concat(
request.Scheme,
"://",
request.Host.ToUriComponent(),
request.PathBase.ToUriComponent(),
request.Path.ToUriComponent());
}
public static string GetCurrentPath(this HttpRequest request)
{
return string.Concat(
request.PathBase.ToUriComponent(),
request.Path.ToUriComponent());
}
public static string GetAbsoluteUri(this HttpRequest request, string redirectUrl) public static string GetAbsoluteUri(this HttpRequest request, string redirectUrl)
{ {
bool isRelative = bool isRelative =

View File

@@ -16,7 +16,7 @@
<hr class="primary"> <hr class="primary">
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<form asp-route-returnUrl="@ViewData["ReturnUrl"]" method="post"> <form asp-route-returnUrl="@ViewData["ReturnUrl"]" asp-route-logon="@ViewData["Logon"]" method="post">
<h4>Create a new account.</h4> <h4>Create a new account.</h4>
<hr /> <hr />
<div asp-validation-summary="All" class="text-danger"></div> <div asp-validation-summary="All" class="text-danger"></div>

View File

@@ -7,7 +7,7 @@
<h4>@ViewData["Title"]</h4> <h4>@ViewData["Title"]</h4>
<partial name="_StatusMessage" for="StatusMessage" /> <partial name="_StatusMessage" for="StatusMessage" />
<a asp-controller="Account" asp-action="Register" asp-route-returnUrl="@Context.Request.GetCurrentPath()" asp-route-logon="false" class="btn btn-primary" role="button"><span class="fa fa-plus"></span> Create a new user</a>
<table class="table table-sm table-responsive-md"> <table class="table table-sm table-responsive-md">
<thead> <thead>
<tr> <tr>