Some changes to get register/login flow working smoothly with Admin role.
This commit is contained in:
parent
259b954f26
commit
bb276a5984
6 changed files with 26 additions and 21 deletions
|
|
@ -1,5 +1,8 @@
|
|||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace API.Controllers
|
||||
|
|
@ -7,16 +10,26 @@ namespace API.Controllers
|
|||
public class AdminController : BaseApiController
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly UserManager<AppUser> _userManager;
|
||||
|
||||
public AdminController(IUserRepository userRepository)
|
||||
public AdminController(IUserRepository userRepository, UserManager<AppUser> userManager)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("exists")]
|
||||
public async Task<ActionResult<bool>> AdminExists()
|
||||
{
|
||||
return await _userRepository.AdminExists();
|
||||
var users = await _userManager.GetUsersInRoleAsync("Admin");
|
||||
return users.Count > 0;
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpDelete]
|
||||
public async Task<ActionResult> DeleteUser(string username)
|
||||
{
|
||||
return BadRequest("Not Implemented");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue