forked from ddrilling/AsbCloudServer
Merge pull request 'Статусы пользователя + проверка статуса пользователя в AddJWTAuthentication' (#74) from feature/blocked-user into dev
Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/74
This commit is contained in:
commit
4778e98a16
@ -62,8 +62,11 @@ namespace AsbCloudApp.Data.User
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Id состояния пользователя
|
/// Id состояния пользователя
|
||||||
|
/// 0 - не активен,
|
||||||
|
/// 1 - активен,
|
||||||
|
/// 2 - заблокирован
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short? IdState { get; set; }
|
public short IdState { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DTO компании
|
/// DTO компании
|
||||||
|
8226
AsbCloudDb/Migrations/20230711130529_Update_IdState_For_User.Designer.cs
generated
Normal file
8226
AsbCloudDb/Migrations/20230711130529_Update_IdState_For_User.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class Update_IdState_For_User : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user",
|
||||||
|
keyColumn: "state",
|
||||||
|
keyValue: null,
|
||||||
|
column: "state",
|
||||||
|
value: (short)1);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<short>(
|
||||||
|
name: "state",
|
||||||
|
table: "t_user",
|
||||||
|
type: "smallint",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: (short)0,
|
||||||
|
comment: "состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован",
|
||||||
|
oldClrType: typeof(short),
|
||||||
|
oldType: "smallint",
|
||||||
|
oldNullable: true,
|
||||||
|
oldComment: "состояние:\n100 - удален");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id_category",
|
||||||
|
table: "t_help_page",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
comment: "Id категории файла",
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldComment: "id категории файла");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<short>(
|
||||||
|
name: "state",
|
||||||
|
table: "t_user",
|
||||||
|
type: "smallint",
|
||||||
|
nullable: true,
|
||||||
|
comment: "состояние:\n100 - удален",
|
||||||
|
oldClrType: typeof(short),
|
||||||
|
oldType: "smallint",
|
||||||
|
oldComment: "состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id_category",
|
||||||
|
table: "t_help_page",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
comment: "id категории файла",
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldComment: "Id категории файла");
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 1,
|
||||||
|
column: "state",
|
||||||
|
value: null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4768,10 +4768,10 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_company");
|
.HasColumnName("id_company");
|
||||||
|
|
||||||
b.Property<short?>("IdState")
|
b.Property<short>("IdState")
|
||||||
.HasColumnType("smallint")
|
.HasColumnType("smallint")
|
||||||
.HasColumnName("state")
|
.HasColumnName("state")
|
||||||
.HasComment("состояние:\n100 - удален");
|
.HasComment("состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован");
|
||||||
|
|
||||||
b.Property<string>("Login")
|
b.Property<string>("Login")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
@ -4833,6 +4833,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
Id = 1,
|
Id = 1,
|
||||||
Email = "",
|
Email = "",
|
||||||
IdCompany = 1,
|
IdCompany = 1,
|
||||||
|
IdState = (short)1,
|
||||||
Login = "dev",
|
Login = "dev",
|
||||||
Name = "Разработчик",
|
Name = "Разработчик",
|
||||||
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072"
|
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072"
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
Login = "dev",
|
Login = "dev",
|
||||||
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072",
|
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072",
|
||||||
Name = "Разработчик",
|
Name = "Разработчик",
|
||||||
|
IdState = 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ namespace AsbCloudDb.Model
|
|||||||
[Table("t_user"), Comment("Пользователи облака")]
|
[Table("t_user"), Comment("Пользователи облака")]
|
||||||
public partial class User : IId
|
public partial class User : IId
|
||||||
{
|
{
|
||||||
|
public const int ActiveStateId = 1;
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -23,8 +25,8 @@ namespace AsbCloudDb.Model
|
|||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
public string PasswordHash { get; set; } = null!;
|
public string PasswordHash { get; set; } = null!;
|
||||||
|
|
||||||
[Column("state"), Comment("состояние:\n100 - удален")]
|
[Column("state"), Comment("состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован")]
|
||||||
public short? IdState { get; set; }
|
public short IdState { get; set; }
|
||||||
|
|
||||||
[Column("name"), Comment("имя")]
|
[Column("name"), Comment("имя")]
|
||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using AsbCloudApp.Data.GTR;
|
using AsbCloudApp.Data.GTR;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Services;
|
using AsbCloudInfrastructure.Services;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
@ -19,7 +22,8 @@ namespace AsbCloudWebApi
|
|||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
c.MapType<DateOnly>(() => new OpenApiSchema { Type = "string", Format = "date" });
|
c.MapType<DateOnly>(() => new OpenApiSchema { Type = "string", Format = "date" });
|
||||||
c.MapType<JsonValue>(() => new OpenApiSchema {
|
c.MapType<JsonValue>(() => new OpenApiSchema
|
||||||
|
{
|
||||||
AnyOf = new OpenApiSchema[]
|
AnyOf = new OpenApiSchema[]
|
||||||
{
|
{
|
||||||
new OpenApiSchema {Type = "string", Format = "string" },
|
new OpenApiSchema {Type = "string", Format = "string" },
|
||||||
@ -98,6 +102,30 @@ namespace AsbCloudWebApi
|
|||||||
context.Token = accessToken;
|
context.Token = accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
},
|
||||||
|
OnTokenValidated = context =>
|
||||||
|
{
|
||||||
|
var idUser = context.Principal?.GetUserId();
|
||||||
|
if (idUser is null)
|
||||||
|
{
|
||||||
|
context.Fail("idUser is null");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.HttpContext.RequestServices.GetRequiredService<IUserRepository>();
|
||||||
|
var userService = services.BuildServiceProvider().GetRequiredService<IUserRepository>();
|
||||||
|
var user = userService.GetOrDefault(idUser.Value);
|
||||||
|
|
||||||
|
if (user is null)
|
||||||
|
{
|
||||||
|
context.Fail("user is null");
|
||||||
|
}
|
||||||
|
else if (user.IdState != User.ActiveStateId)
|
||||||
|
{
|
||||||
|
context.Fail("user is not active");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user