diff --git a/IdentityServer.Api/appsettings.json b/IdentityServer.Api/appsettings.json index d907efa..88d9220 100644 --- a/IdentityServer.Api/appsettings.json +++ b/IdentityServer.Api/appsettings.json @@ -1,7 +1,7 @@ { "urls": "http://*:5063", "ConnectionStrings": { - "DatabaseConnection": "Server=***REMOVED***;Database=IdentityServer_dev;User Id=sa;Password=***REMOVED***;MultipleActiveResultSets=true" + "DatabaseConnection": "***REMOVED***" }, "Logging": { "LogLevel": { diff --git a/IdentityServer.Domain.Data/EntityTypeConfiguration/AppUserConfiguration.cs b/IdentityServer.Domain.Data/EntityTypeConfiguration/AppUserConfiguration.cs index 46add0c..d39232c 100644 --- a/IdentityServer.Domain.Data/EntityTypeConfiguration/AppUserConfiguration.cs +++ b/IdentityServer.Domain.Data/EntityTypeConfiguration/AppUserConfiguration.cs @@ -10,6 +10,7 @@ namespace IdentityServer.Domain.Data.EntityTypeConfiguration { builder.ToTable("AppUser").HasKey(key => key.UserId); builder.Property(z => z.UserId).ValueGeneratedOnAdd(); + builder.HasOne(z => z.Status).WithMany().HasForeignKey(z => z.StatusId); } } } diff --git a/IdentityServer.Domain.Data/EntityTypeConfiguration/UserStatusConfiguration.cs b/IdentityServer.Domain.Data/EntityTypeConfiguration/UserStatusConfiguration.cs new file mode 100644 index 0000000..f5433f9 --- /dev/null +++ b/IdentityServer.Domain.Data/EntityTypeConfiguration/UserStatusConfiguration.cs @@ -0,0 +1,15 @@ +using IdentityServer.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace IdentityServer.Domain.Data.EntityTypeConfiguration +{ + class UserStatusConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("UserStatus").HasKey(z => z.StatusId); + builder.Property(z => z.StatusId).ValueGeneratedOnAdd(); + } + } +} diff --git a/IdentityServer.Domain.Data/Scripts/1.0.1/01.UserStatus table.sql b/IdentityServer.Domain.Data/Scripts/1.0.1/01.UserStatus table.sql index 6abaab4..c8d6d7b 100644 --- a/IdentityServer.Domain.Data/Scripts/1.0.1/01.UserStatus table.sql +++ b/IdentityServer.Domain.Data/Scripts/1.0.1/01.UserStatus table.sql @@ -2,7 +2,7 @@ if not exists (select top 1 1 from sys.objects where name = 'UserStatus' and typ begin create table UserStatus ( - StatusId int identity(0, 1) constraint PK_UserStatus primary key, + StatusId int identity(1, 1) constraint PK_UserStatus primary key, StatusCode varchar(30) not null, StatusName varchar(50) not null ) diff --git a/IdentityServer.Domain.Data/Scripts/1.0.1/02.New structure for AppUser table.sql b/IdentityServer.Domain.Data/Scripts/1.0.1/02.New structure for AppUser table.sql index 289a436..21931f0 100644 --- a/IdentityServer.Domain.Data/Scripts/1.0.1/02.New structure for AppUser table.sql +++ b/IdentityServer.Domain.Data/Scripts/1.0.1/02.New structure for AppUser table.sql @@ -1,3 +1,10 @@ +if exists (select top 1 1 from sys.objects where name = 'AppUser' and type = 'U') + and not exists(select top 1 1 from sys.columns where name = 'SecurityStamp' and object_id = object_id('AppUser')) +begin + select * into #TmpAppUser from AppUser + drop table AppUser +end + if not exists (select top 1 1 from sys.objects where name = 'AppUser' and type = 'U') begin create table AppUser @@ -21,7 +28,13 @@ go if not exists (select top 1 1 from AppUser) begin - insert into AppUser(UserName, [Password]) - select '***REMOVED***', '***REMOVED***' + declare @activeStatusId int + select @activeStatusId = StatusId from UserStatus where StatusCode = 'ACTIVE' + + insert into AppUser(UserName, [Password], CreationDate, SecurityStamp, StatusId) + select UserName, [Password], CreationDate, cast(newid() as varchar(100)), @activeStatusId as StatusId + from #TmpAppUser + + drop table #TmpAppUser end go \ No newline at end of file diff --git a/IdentityServer.Domain/Entities/AppUser.cs b/IdentityServer.Domain/Entities/AppUser.cs index 50999f8..bdba9fa 100644 --- a/IdentityServer.Domain/Entities/AppUser.cs +++ b/IdentityServer.Domain/Entities/AppUser.cs @@ -7,8 +7,16 @@ namespace IdentityServer.Domain.Entities public int UserId { get; set; } public string UserName { get; set; } public string Password { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } public string Email { get; set; } public string ProfilePictureUrl { get; set; } + public string SecurityStamp { get; set; } + public int StatusId { get; set; } public DateTime CreationDate { get; set; } + public int FailedLoginAttempts { get; set; } + public DateTime LastLoginDate { get; set; } + public DateTime PasswordChangeDate { get; set; } + public UserStatus Status { get; set; } } } diff --git a/IdentityServer.Domain/Entities/UserStatus.cs b/IdentityServer.Domain/Entities/UserStatus.cs new file mode 100644 index 0000000..50c6622 --- /dev/null +++ b/IdentityServer.Domain/Entities/UserStatus.cs @@ -0,0 +1,9 @@ +namespace IdentityServer.Domain.Entities +{ + public class UserStatus + { + public int StatusId { get; set; } + public string StatusCode { get; set; } + public string StatusName { get; set; } + } +}