User Roles restored

This commit is contained in:
Paul Schneider
2024-11-06 18:45:32 +00:00
parent 2043dbfce6
commit 55623410ab
5 changed files with 4081 additions and 63 deletions

View File

@ -52,7 +52,10 @@ namespace Yavsc.Controllers
private readonly IClientStore _clientStore;
private readonly IAuthenticationSchemeProvider _schemeProvider;
private readonly IEventService _events;
private readonly RoleManager<IdentityRole> _roleManager;
public AccountController(
RoleManager<IdentityRole> roleManager,
IIdentityServerInteractionService interaction,
IClientStore clientStore,
IAuthenticationSchemeProvider schemeProvider,
@ -69,6 +72,7 @@ namespace Yavsc.Controllers
_clientStore = clientStore;
_schemeProvider = schemeProvider;
_events = events;
_roleManager = roleManager;
_userManager = userManager;
_signInManager = signInManager;
@ -106,6 +110,7 @@ namespace Yavsc.Controllers
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginInputModel model, string button)
{
// check if we are in the context of an authorization request
var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);
@ -143,8 +148,8 @@ namespace Yavsc.Controllers
if (user!=null) {
var signin = await _signInManager.CheckPasswordSignInAsync(user, model.Password, true);
var signin = await _signInManager.CheckPasswordSignInAsync(user, model.Password, true);
// validate username/password against in-memory store
if (signin.Succeeded)
{
@ -158,17 +163,34 @@ namespace Yavsc.Controllers
props = new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration)
ExpiresUtc = DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration),
// Parameters =
};
};
// roles
var roles = _dbContext.UserRoles.Where(r=>r.UserId == user.Id).ToArray();
// issue authentication cookie with subject ID and username
var isuser = new IdentityServerUser(user.Id)
List<Claim> additionalClaims = new List<Claim>();
foreach (var role in roles)
{
DisplayName = user.UserName
var idRole = await _roleManager.Roles.SingleOrDefaultAsync(i=>i.Id == role.RoleId);
if (idRole != null)
{
additionalClaims.Add(new Claim(ClaimTypes.Role, idRole.Name));
}
}
additionalClaims.Add(new Claim(ClaimTypes.Name, user.UserName));
var isUser = new IdentityServerUser(user.Id)
{
DisplayName = user.UserName,
AdditionalClaims = additionalClaims.ToArray()
};
await HttpContext.SignInAsync(isuser, props);
await HttpContext.SignInAsync(isUser, props);
if (context != null)
{

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,439 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Yavsc.Migrations
{
/// <inheritdoc />
public partial class dismiss : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Bug_Feature_FeatureId",
table: "Bug");
migrationBuilder.DropForeignKey(
name: "FK_HairCutQueries_Locations_LocationId",
table: "HairCutQueries");
migrationBuilder.DropTable(
name: "DimissClicked");
migrationBuilder.DropColumn(
name: "RejectedAt",
table: "RdvQueries");
migrationBuilder.DropColumn(
name: "RejectedAt",
table: "Project");
migrationBuilder.DropColumn(
name: "RejectedAt",
table: "HairMultiCutQueries");
migrationBuilder.DropColumn(
name: "RejectedAt",
table: "HairCutQueries");
migrationBuilder.DropColumn(
name: "DateCreated",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "DateModified",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "UserCreated",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "UserModified",
table: "AspNetUsers");
migrationBuilder.RenameColumn(
name: "Rejected",
table: "RdvQueries",
newName: "Decided");
migrationBuilder.RenameColumn(
name: "Rejected",
table: "Project",
newName: "Decided");
migrationBuilder.RenameColumn(
name: "Rejected",
table: "HairMultiCutQueries",
newName: "Decided");
migrationBuilder.RenameColumn(
name: "Rejected",
table: "HairCutQueries",
newName: "Decided");
migrationBuilder.AddColumn<bool>(
name: "Accepted",
table: "RdvQueries",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "Accepted",
table: "Project",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "Accepted",
table: "HairMultiCutQueries",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AlterColumn<long>(
name: "LocationId",
table: "HairCutQueries",
type: "bigint",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AddColumn<bool>(
name: "Accepted",
table: "HairCutQueries",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AlterColumn<long>(
name: "FeatureId",
table: "Bug",
type: "bigint",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.AlterColumn<string>(
name: "Secret",
table: "Applications",
type: "character varying(512)",
maxLength: 512,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "RedirectUri",
table: "Applications",
type: "character varying(512)",
maxLength: 512,
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "LogoutRedirectUri",
table: "Applications",
type: "character varying(512)",
maxLength: 512,
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);
migrationBuilder.AlterColumn<string>(
name: "DisplayName",
table: "Applications",
type: "character varying(128)",
maxLength: 128,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AddColumn<int>(
name: "AccessTokenLifetime",
table: "Applications",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "DismissClicked",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
NotificationId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DismissClicked", x => new { x.UserId, x.NotificationId });
table.ForeignKey(
name: "FK_DismissClicked_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DismissClicked_Notification_NotificationId",
column: x => x.NotificationId,
principalTable: "Notification",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Scopes",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Scopes", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_DismissClicked_NotificationId",
table: "DismissClicked",
column: "NotificationId");
migrationBuilder.AddForeignKey(
name: "FK_Bug_Feature_FeatureId",
table: "Bug",
column: "FeatureId",
principalTable: "Feature",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_HairCutQueries_Locations_LocationId",
table: "HairCutQueries",
column: "LocationId",
principalTable: "Locations",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Bug_Feature_FeatureId",
table: "Bug");
migrationBuilder.DropForeignKey(
name: "FK_HairCutQueries_Locations_LocationId",
table: "HairCutQueries");
migrationBuilder.DropTable(
name: "DismissClicked");
migrationBuilder.DropTable(
name: "Scopes");
migrationBuilder.DropColumn(
name: "Accepted",
table: "RdvQueries");
migrationBuilder.DropColumn(
name: "Accepted",
table: "Project");
migrationBuilder.DropColumn(
name: "Accepted",
table: "HairMultiCutQueries");
migrationBuilder.DropColumn(
name: "Accepted",
table: "HairCutQueries");
migrationBuilder.DropColumn(
name: "AccessTokenLifetime",
table: "Applications");
migrationBuilder.RenameColumn(
name: "Decided",
table: "RdvQueries",
newName: "Rejected");
migrationBuilder.RenameColumn(
name: "Decided",
table: "Project",
newName: "Rejected");
migrationBuilder.RenameColumn(
name: "Decided",
table: "HairMultiCutQueries",
newName: "Rejected");
migrationBuilder.RenameColumn(
name: "Decided",
table: "HairCutQueries",
newName: "Rejected");
migrationBuilder.AddColumn<DateTime>(
name: "RejectedAt",
table: "RdvQueries",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<DateTime>(
name: "RejectedAt",
table: "Project",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<DateTime>(
name: "RejectedAt",
table: "HairMultiCutQueries",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AlterColumn<long>(
name: "LocationId",
table: "HairCutQueries",
type: "bigint",
nullable: false,
defaultValue: 0L,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "RejectedAt",
table: "HairCutQueries",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AlterColumn<long>(
name: "FeatureId",
table: "Bug",
type: "bigint",
nullable: false,
defaultValue: 0L,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "DateCreated",
table: "AspNetUsers",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<DateTime>(
name: "DateModified",
table: "AspNetUsers",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<string>(
name: "UserCreated",
table: "AspNetUsers",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "UserModified",
table: "AspNetUsers",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AlterColumn<string>(
name: "Secret",
table: "Applications",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(512)",
oldMaxLength: 512);
migrationBuilder.AlterColumn<string>(
name: "RedirectUri",
table: "Applications",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "character varying(512)",
oldMaxLength: 512,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "LogoutRedirectUri",
table: "Applications",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(512)",
oldMaxLength: 512);
migrationBuilder.AlterColumn<string>(
name: "DisplayName",
table: "Applications",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(128)",
oldMaxLength: 128);
migrationBuilder.CreateTable(
name: "DimissClicked",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
NotificationId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DimissClicked", x => new { x.UserId, x.NotificationId });
table.ForeignKey(
name: "FK_DimissClicked_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DimissClicked_Notification_NotificationId",
column: x => x.NotificationId,
principalTable: "Notification",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DimissClicked_NotificationId",
table: "DimissClicked",
column: "NotificationId");
migrationBuilder.AddForeignKey(
name: "FK_Bug_Feature_FeatureId",
table: "Bug",
column: "FeatureId",
principalTable: "Feature",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_HairCutQueries_Locations_LocationId",
table: "HairCutQueries",
column: "LocationId",
principalTable: "Locations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -17,7 +17,7 @@ namespace Yavsc.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -298,12 +298,6 @@ namespace Yavsc.Migrations
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("DedicatedGoogleCalendar")
.HasMaxLength(512)
.HasColumnType("character varying(512)");
@ -363,14 +357,6 @@ namespace Yavsc.Migrations
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserCreated")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserModified")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
@ -394,30 +380,36 @@ namespace Yavsc.Migrations
modelBuilder.Entity("Yavsc.Models.Auth.Client", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text");
b.Property<int>("AccessTokenLifetime")
.HasColumnType("integer");
b.Property<bool>("Active")
.HasColumnType("boolean");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("LogoutRedirectUri")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<string>("RedirectUri")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<int>("RefreshTokenLifeTime")
.HasColumnType("integer");
b.Property<string>("Secret")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<int>("Type")
.HasColumnType("integer");
@ -486,6 +478,21 @@ namespace Yavsc.Migrations
b.ToTable("RefreshTokens");
});
modelBuilder.Entity("Yavsc.Models.Auth.Scope", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.HasKey("Id");
b.ToTable("Scopes");
});
modelBuilder.Entity("Yavsc.Models.BalanceImpact", b =>
{
b.Property<long>("Id")
@ -1131,6 +1138,9 @@ namespace Yavsc.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("ActivityCode")
.IsRequired()
.HasColumnType("text");
@ -1152,6 +1162,9 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Decided")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
@ -1160,7 +1173,6 @@ namespace Yavsc.Migrations
.HasColumnType("timestamp with time zone");
b.Property<long?>("LocationId")
.IsRequired()
.HasColumnType("bigint");
b.Property<string>("PaymentId")
@ -1177,12 +1189,6 @@ namespace Yavsc.Migrations
b.Property<decimal?>("Previsional")
.HasColumnType("numeric");
b.Property<bool>("Rejected")
.HasColumnType("boolean");
b.Property<DateTime>("RejectedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("SelectedProfileUserId")
.HasColumnType("text");
@ -1227,6 +1233,9 @@ namespace Yavsc.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("ActivityCode")
.IsRequired()
.HasColumnType("text");
@ -1244,6 +1253,9 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Decided")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
@ -1265,12 +1277,6 @@ namespace Yavsc.Migrations
b.Property<decimal?>("Previsional")
.HasColumnType("numeric");
b.Property<bool>("Rejected")
.HasColumnType("boolean");
b.Property<DateTime>("RejectedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
@ -1431,7 +1437,6 @@ namespace Yavsc.Migrations
.HasColumnType("text");
b.Property<long?>("FeatureId")
.IsRequired()
.HasColumnType("bigint");
b.Property<int>("Status")
@ -1587,7 +1592,7 @@ namespace Yavsc.Migrations
b.ToTable("Announce");
});
modelBuilder.Entity("Yavsc.Models.Messaging.DimissClicked", b =>
modelBuilder.Entity("Yavsc.Models.Messaging.DismissClicked", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
@ -1599,7 +1604,7 @@ namespace Yavsc.Migrations
b.HasIndex("NotificationId");
b.ToTable("DimissClicked");
b.ToTable("DismissClicked");
});
modelBuilder.Entity("Yavsc.Models.Messaging.Notification", b =>
@ -2251,6 +2256,9 @@ namespace Yavsc.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("ActivityCode")
.IsRequired()
.HasColumnType("text");
@ -2268,6 +2276,9 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Decided")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
@ -2296,12 +2307,6 @@ namespace Yavsc.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Rejected")
.HasColumnType("boolean");
b.Property<DateTime>("RejectedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
@ -2437,6 +2442,9 @@ namespace Yavsc.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("ActivityCode")
.IsRequired()
.HasColumnType("text");
@ -2454,6 +2462,9 @@ namespace Yavsc.Migrations
b.Property<DateTime>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Decided")
.HasColumnType("boolean");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
@ -2480,12 +2491,6 @@ namespace Yavsc.Migrations
b.Property<decimal?>("Previsional")
.HasColumnType("numeric");
b.Property<bool>("Rejected")
.HasColumnType("boolean");
b.Property<DateTime>("RejectedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
@ -2909,9 +2914,7 @@ namespace Yavsc.Migrations
b.HasOne("Yavsc.Models.Relationship.Location", "Location")
.WithMany()
.HasForeignKey("LocationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("LocationId");
b.HasOne("Yavsc.Models.Payment.PayPalPayment", "Regularisation")
.WithMany()
@ -3046,9 +3049,7 @@ namespace Yavsc.Migrations
{
b.HasOne("Yavsc.Models.IT.Evolution.Feature", "False")
.WithMany()
.HasForeignKey("FeatureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("FeatureId");
b.Navigation("False");
});
@ -3086,7 +3087,7 @@ namespace Yavsc.Migrations
b.Navigation("Owner");
});
modelBuilder.Entity("Yavsc.Models.Messaging.DimissClicked", b =>
modelBuilder.Entity("Yavsc.Models.Messaging.DismissClicked", b =>
{
b.HasOne("Yavsc.Models.Messaging.Notification", "Notified")
.WithMany()

View File

@ -11,7 +11,7 @@
}
}
@if (SignInManager.IsSignedIn(User))
@if (name!=null)
{
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown04" data-bs-toggle="dropdown" aria-expanded="false">Plateforme</a>