Renvoit du rôle au frontend avec Get Login (UPDATE-DATABASE)
This commit is contained in:
@@ -14,11 +14,13 @@ using GrossesMitainesAPI.Models;
|
||||
Authorize(AuthenticationSchemes = "Identity.Application")]
|
||||
public class LoginController : Controller {
|
||||
private readonly UserManager<InventoryUser> _userMan;
|
||||
private readonly RoleManager<IdentityRole> _roleMan;
|
||||
private readonly SignInManager<InventoryUser> _signInMan;
|
||||
|
||||
public LoginController(SignInManager<InventoryUser> signin, UserManager<InventoryUser> userman) {
|
||||
public LoginController(SignInManager<InventoryUser> signin, UserManager<InventoryUser> userman, RoleManager<IdentityRole> roleMan) {
|
||||
this._signInMan = signin;
|
||||
this._userMan = userman;
|
||||
this._roleMan = roleMan;
|
||||
}
|
||||
|
||||
public class LoginUser {
|
||||
@@ -28,9 +30,16 @@ public class LoginController : Controller {
|
||||
|
||||
[HttpGet, Route("Login")]
|
||||
public ReturnUserViewModel WhoAmI() {
|
||||
var user = _userMan.GetUserAsync(_signInMan.Context.User);
|
||||
var user = _userMan.GetUserAsync(_signInMan.Context.User);
|
||||
user.Wait();
|
||||
return new ReturnUserViewModel(user.Result);
|
||||
var roles = _userMan.GetRolesAsync(user.Result);
|
||||
roles.Wait();
|
||||
|
||||
string role = "";
|
||||
if (roles.Result.Contains("Administrateur"))
|
||||
role = "Administrateur";
|
||||
else role = "Client";
|
||||
return new ReturnUserViewModel(user.Result, role);
|
||||
}
|
||||
|
||||
[HttpPost, Route("Login"), AllowAnonymous]
|
||||
|
Reference in New Issue
Block a user