mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Make first user admin of the website
This commit is contained in:
@@ -27,10 +27,11 @@ namespace BTCPayServer.Controllers
|
|||||||
private readonly IEmailSender _emailSender;
|
private readonly IEmailSender _emailSender;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
StoreRepository storeRepository;
|
StoreRepository storeRepository;
|
||||||
|
RoleManager<IdentityRole> _RoleManager;
|
||||||
|
|
||||||
public AccountController(
|
public AccountController(
|
||||||
UserManager<ApplicationUser> userManager,
|
UserManager<ApplicationUser> userManager,
|
||||||
|
RoleManager<IdentityRole> roleManager,
|
||||||
StoreRepository storeRepository,
|
StoreRepository storeRepository,
|
||||||
SignInManager<ApplicationUser> signInManager,
|
SignInManager<ApplicationUser> signInManager,
|
||||||
IEmailSender emailSender,
|
IEmailSender emailSender,
|
||||||
@@ -41,7 +42,9 @@ namespace BTCPayServer.Controllers
|
|||||||
_signInManager = signInManager;
|
_signInManager = signInManager;
|
||||||
_emailSender = emailSender;
|
_emailSender = emailSender;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
_RoleManager = roleManager;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[TempData]
|
[TempData]
|
||||||
public string ErrorMessage { get; set; }
|
public string ErrorMessage { get; set; }
|
||||||
@@ -232,7 +235,15 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("User created a new account with password.");
|
_logger.LogInformation("User created a new account with password.");
|
||||||
|
|
||||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
var admin = await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin);
|
||||||
|
if(admin.Count == 0)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Admin created.");
|
||||||
|
await _RoleManager.CreateAsync(new IdentityRole(Roles.ServerAdmin));
|
||||||
|
await _userManager.AddToRoleAsync(user, Roles.ServerAdmin);
|
||||||
|
}
|
||||||
|
|
||||||
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
|
var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
|
||||||
RegisteredUserId = user.Id;
|
RegisteredUserId = user.Id;
|
||||||
await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);
|
await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);
|
||||||
|
|||||||
12
BTCPayServer/Roles.cs
Normal file
12
BTCPayServer/Roles.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BTCPayServer
|
||||||
|
{
|
||||||
|
public class Roles
|
||||||
|
{
|
||||||
|
public const string ServerAdmin = "ServerAdmin";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
@inject SignInManager<ApplicationUser> SignInManager
|
@inject SignInManager<ApplicationUser> SignInManager
|
||||||
@inject UserManager<ApplicationUser> UserManager
|
@inject UserManager<ApplicationUser> UserManager
|
||||||
|
@inject RoleManager<IdentityRole> RoleManager
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@@ -50,6 +51,10 @@
|
|||||||
<ul class="navbar-nav ml-auto">
|
<ul class="navbar-nav ml-auto">
|
||||||
@if(SignInManager.IsSignedIn(User))
|
@if(SignInManager.IsSignedIn(User))
|
||||||
{
|
{
|
||||||
|
@if(User.IsInRole(Roles.ServerAdmin))
|
||||||
|
{
|
||||||
|
<li class="nav-item"><a asp-area="" asp-controller="Server" asp-action="Settings" class="nav-link js-scroll-trigger">Server settings</a></li>
|
||||||
|
}
|
||||||
<li class="nav-item"><a asp-area="" asp-controller="Stores" asp-action="ListStores" class="nav-link js-scroll-trigger">Stores</a></li>
|
<li class="nav-item"><a asp-area="" asp-controller="Stores" asp-action="ListStores" class="nav-link js-scroll-trigger">Stores</a></li>
|
||||||
<li class="nav-item"><a asp-area="" asp-controller="Invoice" asp-action="ListInvoices" class="nav-link js-scroll-trigger">Invoices</a></li>
|
<li class="nav-item"><a asp-area="" asp-controller="Invoice" asp-action="ListInvoices" class="nav-link js-scroll-trigger">Invoices</a></li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
|||||||
Reference in New Issue
Block a user