Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a6ab150e8d | |||
| b2afa672fc | |||
| 41e70fab62 | |||
| 8bbb114c04 | |||
| 435d12cb5b | |||
| d40cb20693 | |||
| 0fd554464e | |||
| ea04ae6245 | |||
| 4d717e9237 | |||
| e6589a5438 | |||
| 787283d239 | |||
| 3f97f11c41 | |||
| cc62039aa4 | |||
| 839ef56668 | |||
| a86eb452de | |||
| 318be3f7e0 | |||
| 4c1ed660b2 | |||
| 1778dd9290 | |||
| fef078b3bb | |||
| d3ebef281b | |||
| f9999e6900 | |||
| 74ba4373f3 | |||
| 79436685d7 | |||
| e9173e9735 | |||
| d59ba7525f | |||
| 38d7f0e8a0 | |||
| b25aeaa312 | |||
| 227e7ded81 | |||
| 65c17437f8 | |||
| c14f031fc5 | |||
| f6ecbb5761 | |||
| 9150df1286 | |||
| d0ab2df2ba | |||
| d364a16a58 | |||
| 75ab78ace4 | |||
| 0d34e61940 | |||
| 104e4acd93 | |||
| bf7acb2b08 | |||
| 5e6453f53e | |||
| d0e29fa6b4 | |||
| 32162c66ec | |||
| b01703f12f | |||
| 0db3604ade | |||
| 379723889e | |||
| 17f3aa7c6e | |||
| ab0c242e6d | |||
| cdba46bc45 | |||
| 40353cfc03 | |||
| be46d09654 | |||
| ef54e6f0cc | |||
| 29b084ae0e | |||
| 6564077260 | |||
| 9f495197d0 | |||
| a9286062c1 | |||
| 1ea8e13a14 | |||
| de0e9b990c | |||
| c63116f871 | |||
| f956f010c3 | |||
| 42e3e44cd2 | |||
| 6717945249 |
-90
@@ -4,96 +4,6 @@
|
|||||||
*.pdb
|
*.pdb
|
||||||
.vs/*
|
.vs/*
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area VersGen
|
|
||||||
#--------------------------------
|
|
||||||
/VersGen/bin/*
|
|
||||||
/VersGen/obj/*
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# area MapoDb
|
|
||||||
#--------------------------------
|
|
||||||
/MapoDb/bin/*
|
|
||||||
/MapoDb/obj/*
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# area MP
|
|
||||||
#--------------------------------
|
|
||||||
/MP/bin/*
|
|
||||||
/MP/obj/*
|
|
||||||
MP/logs/*.txt
|
|
||||||
MP/logs/*.zip
|
|
||||||
MP-LAND/logs/
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area MP-MON (MoonPro-MONitor)
|
|
||||||
#--------------------------------
|
|
||||||
/MP-MON/logs/*.zip
|
|
||||||
/MP-MON/logs/*.txt
|
|
||||||
/MP-MON/bin/*
|
|
||||||
/MP-MON/obj/*
|
|
||||||
/MP-MON/WebCharts/*.png
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area MP-IO (MoonPro-IO)
|
|
||||||
#--------------------------------
|
|
||||||
/MP-IO/logs/*.zip
|
|
||||||
/MP-IO/logs/*.txt
|
|
||||||
/MP-IO/bin/*
|
|
||||||
/MP-IO/obj/*
|
|
||||||
/MP-IO/fileUpload/
|
|
||||||
!/MP-IO/fileUpload/.PlaceHolder.file
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area MP-Admin
|
|
||||||
#--------------------------------
|
|
||||||
/MP-Admin/logs/*.zip
|
|
||||||
/MP-Admin/logs/*.txt
|
|
||||||
/MP-Admin/bin/*
|
|
||||||
/MP-Admin/obj/*
|
|
||||||
/MP-ADM/logs/*.zip
|
|
||||||
/MP-ADM/logs/*.txt
|
|
||||||
/MP-ADM/bin/*
|
|
||||||
/MP-ADM/obj/*
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area ES3
|
|
||||||
#--------------------------------
|
|
||||||
/ES3/logs/*.zip
|
|
||||||
/ES3/logs/*.txt
|
|
||||||
/ES3/bin/*
|
|
||||||
/ES3/obj/*
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area MoonProTablet
|
|
||||||
#--------------------------------
|
|
||||||
/MP-TAB/logs/*.zip
|
|
||||||
/MP-TAB/logs/*.txt
|
|
||||||
/MP-TAB/bin/*
|
|
||||||
/MP-TAB/obj/*
|
|
||||||
/MP-TAB/WebCharts/*.png
|
|
||||||
/MP-TAB/images/macchine/*.*
|
|
||||||
!/MP-TAB/images/macchine/Steamware.png
|
|
||||||
/MP-TAB/Files/Disegni/*.pdf
|
|
||||||
!/MP-TAB/Files/Disegni/ND.pdf
|
|
||||||
MP-TAB/logs/
|
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
# Area MoonPro
|
|
||||||
#--------------------------------
|
|
||||||
/MP-Site/logs/*.zip
|
|
||||||
/MP-Site/logs/*.txt
|
|
||||||
/MP-Site/bin/*
|
|
||||||
/MP-Site/obj/*
|
|
||||||
/MP-Site/WebCharts/*.png
|
|
||||||
/MP-Site/images/macchine/*.*
|
|
||||||
!/MP-Site/images/macchine/Steamware.png
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---> VisualStudio
|
# ---> VisualStudio
|
||||||
## Ignore Visual Studio temporary files, build results, and
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
## files generated by popular Visual Studio add-ons.
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|||||||
+3
-3
@@ -72,9 +72,9 @@ build:
|
|||||||
stage: build
|
stage: build
|
||||||
before_script:
|
before_script:
|
||||||
- *nuget-fix
|
- *nuget-fix
|
||||||
- dotnet restore
|
- dotnet restore GWMS.sln
|
||||||
script:
|
script:
|
||||||
- dotnet build
|
- dotnet build -p:Configuration=Release GWMS.UI/GWMS.UI.csproj
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
@@ -82,7 +82,7 @@ test:
|
|||||||
- develop
|
- develop
|
||||||
needs: ["build"]
|
needs: ["build"]
|
||||||
script:
|
script:
|
||||||
- dotnet test
|
- dotnet test -p:Configuration=Release GWMS.UI/GWMS.UI.csproj
|
||||||
|
|
||||||
# IIS01:deploy:
|
# IIS01:deploy:
|
||||||
# stage: deploy
|
# stage: deploy
|
||||||
|
|||||||
@@ -327,10 +327,16 @@ namespace GWMS.Data.Controllers
|
|||||||
|
|
||||||
public List<WeekPlanModel> GetWeekPlan()
|
public List<WeekPlanModel> GetWeekPlan()
|
||||||
{
|
{
|
||||||
var dbResult = dbCtx
|
List<WeekPlanModel> dbResult = new List<WeekPlanModel>();
|
||||||
.DbSetPlantSupplWeekPlan
|
using (GWMSContext localDbCtx = new GWMSContext(_configuration))
|
||||||
.ToList();
|
{
|
||||||
|
dbResult = dbCtx
|
||||||
|
.DbSetPlantSupplWeekPlan
|
||||||
|
.Include(p => p.Plant)
|
||||||
|
.Include(s => s.Supplier)
|
||||||
|
.Include(t => t.Transporter)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
return dbResult;
|
return dbResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,25 +428,9 @@ namespace GWMS.Data.Controllers
|
|||||||
localDbCtx.Entry(updItem).State = EntityState.Modified;
|
localDbCtx.Entry(updItem).State = EntityState.Modified;
|
||||||
localDbCtx.SaveChanges();
|
localDbCtx.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
//// se ho modificato data --> cambio codice ordine!
|
|
||||||
//if (!dbCtx.Entry(updItem).OriginalValues["DtOrder"].Equals(dbCtx.Entry(updItem).CurrentValues["DtOrder"]))
|
|
||||||
//{
|
|
||||||
// updItem.OrderCode = $"O{updItem.Plant.PlantCode}{updItem.DtOrder:yyMMddHHmm}";
|
|
||||||
// updItem.OrderDesc = $"Ordine {updItem.Plant.PlantDesc} - {updItem.DtOrder}";
|
|
||||||
//}
|
|
||||||
//dbCtx.Entry(updItem).State = EntityState.Modified;
|
|
||||||
//dbCtx.SaveChanges();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//using (GWMSContext localDbCtx = new GWMSContext(_configuration))
|
|
||||||
//{
|
|
||||||
// localDbCtx
|
|
||||||
// .DbSetOrders
|
|
||||||
// .Add(updItem);
|
|
||||||
// localDbCtx.SaveChanges();
|
|
||||||
//}
|
|
||||||
dbCtx
|
dbCtx
|
||||||
.DbSetOrders
|
.DbSetOrders
|
||||||
.Add(updItem);
|
.Add(updItem);
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace GWMS.Data.DatabaseModels
|
namespace GWMS.Data.DatabaseModels
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Classe fake x il conteggio tabelle e check preliminari
|
||||||
|
/// </summary>
|
||||||
[Keyless]
|
[Keyless]
|
||||||
public class TableCount
|
public class TableCount
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="2.15.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using MailKit.Net.Smtp;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using MimeKit;
|
||||||
|
using MimeKit.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GWMS.Data
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implementazione interfaccia email con pacchetto MailKIT
|
||||||
|
///
|
||||||
|
/// https://www.ryadel.com/en/asp-net-core-send-email-messages-smtp-mailkit/
|
||||||
|
/// </summary>
|
||||||
|
public class MailKitEmailSender : IEmailSender
|
||||||
|
{
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public MailKitEmailSender(IOptions<MailKitEmailSenderOptions> options)
|
||||||
|
{
|
||||||
|
this.Options = options.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public MailKitEmailSenderOptions Options { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public Task Execute(string to, string subject, string message)
|
||||||
|
{
|
||||||
|
// create message
|
||||||
|
var email = new MimeMessage();
|
||||||
|
email.Sender = MailboxAddress.Parse(Options.Sender_EMail);
|
||||||
|
if (!string.IsNullOrEmpty(Options.Sender_Name))
|
||||||
|
email.Sender.Name = Options.Sender_Name;
|
||||||
|
email.From.Add(email.Sender);
|
||||||
|
email.To.Add(MailboxAddress.Parse(to));
|
||||||
|
email.Subject = subject;
|
||||||
|
email.Body = new TextPart(TextFormat.Html) { Text = message };
|
||||||
|
|
||||||
|
// send email
|
||||||
|
using (var smtp = new SmtpClient())
|
||||||
|
{
|
||||||
|
smtp.Connect(Options.Host_Address, Options.Host_Port, Options.Host_SecureSocketOptions);
|
||||||
|
smtp.Authenticate(Options.Host_Username, Options.Host_Password);
|
||||||
|
smtp.Send(email);
|
||||||
|
smtp.Disconnect(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task SendEmailAsync(string email, string subject, string message)
|
||||||
|
{
|
||||||
|
return Execute(email, subject, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using MailKit.Security;
|
||||||
|
|
||||||
|
namespace GWMS.Data
|
||||||
|
{
|
||||||
|
public class MailKitEmailSenderOptions
|
||||||
|
{
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public MailKitEmailSenderOptions()
|
||||||
|
{
|
||||||
|
Host_SecureSocketOptions = SecureSocketOptions.Auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public string Host_Address { get; set; }
|
||||||
|
|
||||||
|
public string Host_Password { get; set; }
|
||||||
|
public int Host_Port { get; set; }
|
||||||
|
|
||||||
|
public SecureSocketOptions Host_SecureSocketOptions { get; set; }
|
||||||
|
public string Host_Username { get; set; }
|
||||||
|
public string Sender_EMail { get; set; }
|
||||||
|
|
||||||
|
public string Sender_Name { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,301 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using GWMS.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace GWMS.User.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserIdentityDbContext))]
|
||||||
|
[Migration("20210824132434_RolesAdded")]
|
||||||
|
partial class RolesAdded
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 64)
|
||||||
|
.HasAnnotation("ProductVersion", "5.0.8");
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("RoleNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoles");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "24a790ae-8eac-4c9f-9043-aa688b626169",
|
||||||
|
ConcurrencyStamp = "c9adff6c-ffac-48e3-899b-8549ca443071",
|
||||||
|
Name = "ExtUser",
|
||||||
|
NormalizedName = "EXTUSER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "7a024dca-5e5d-47be-b754-75c8921d88bf",
|
||||||
|
ConcurrencyStamp = "3b9aab89-73b6-4051-9825-d5381d2896da",
|
||||||
|
Name = "User",
|
||||||
|
NormalizedName = "USER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "0a5335f9-64b2-4196-9d5b-db873cb48d94",
|
||||||
|
ConcurrencyStamp = "25097cab-df45-4bdd-8616-041962c72050",
|
||||||
|
Name = "Admin",
|
||||||
|
NormalizedName = "ADMIN"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "f6aa57e0-fac5-45b7-8e27-fd01d8eff87d",
|
||||||
|
ConcurrencyStamp = "3c222fe9-d5e5-4ba0-9767-4c1777677105",
|
||||||
|
Name = "SuperAdmin",
|
||||||
|
NormalizedName = "SUPERADMIN"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoleClaims");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<int>("AccessFailedCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<bool>("EmailConfirmed")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<bool>("LockoutEnabled")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedEmail")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedUserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("PhoneNumberConfirmed")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityStamp")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("TwoFactorEnabled")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("UserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedEmail")
|
||||||
|
.HasDatabaseName("EmailIndex");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedUserName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("UserNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUsers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserClaims");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderKey")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderDisplayName")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("LoginProvider", "ProviderKey");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserLogins");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserRoles");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "LoginProvider", "Name");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace GWMS.User.Migrations
|
||||||
|
{
|
||||||
|
public partial class RolesAdded : Migration
|
||||||
|
{
|
||||||
|
#region Protected Methods
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "0a5335f9-64b2-4196-9d5b-db873cb48d94");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "24a790ae-8eac-4c9f-9043-aa688b626169");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "7a024dca-5e5d-47be-b754-75c8921d88bf");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "f6aa57e0-fac5-45b7-8e27-fd01d8eff87d");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ "24a790ae-8eac-4c9f-9043-aa688b626169", "c9adff6c-ffac-48e3-899b-8549ca443071", "ExtUser", "EXTUSER" },
|
||||||
|
{ "7a024dca-5e5d-47be-b754-75c8921d88bf", "3b9aab89-73b6-4051-9825-d5381d2896da", "User", "USER" },
|
||||||
|
{ "0a5335f9-64b2-4196-9d5b-db873cb48d94", "25097cab-df45-4bdd-8616-041962c72050", "Admin", "ADMIN" },
|
||||||
|
{ "f6aa57e0-fac5-45b7-8e27-fd01d8eff87d", "3c222fe9-d5e5-4ba0-9767-4c1777677105", "SuperAdmin", "SUPERADMIN" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Protected Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,308 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using GWMS.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace GWMS.User.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserIdentityDbContext))]
|
||||||
|
[Migration("20210824143900_UndefRoleAdd")]
|
||||||
|
partial class UndefRoleAdd
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 64)
|
||||||
|
.HasAnnotation("ProductVersion", "5.0.8");
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("RoleNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoles");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "bf698c1c-ead1-4d88-83ef-536098876807",
|
||||||
|
ConcurrencyStamp = "28d97b49-8df4-4d20-8680-1d3abbf4ed94",
|
||||||
|
Name = "Undef",
|
||||||
|
NormalizedName = "UNDEF"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "a1280bf2-7e5a-447b-b070-3bea27ba2239",
|
||||||
|
ConcurrencyStamp = "d361332c-1ae0-486c-b1d8-1f2c9c36ad88",
|
||||||
|
Name = "ExtUser",
|
||||||
|
NormalizedName = "EXTUSER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "533995b8-8561-471a-b613-a03685141065",
|
||||||
|
ConcurrencyStamp = "773db769-a518-406f-9144-31e1fd9f7a76",
|
||||||
|
Name = "User",
|
||||||
|
NormalizedName = "USER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "d4790e4e-600b-4bae-876d-04c619adc9b0",
|
||||||
|
ConcurrencyStamp = "70529623-7648-4640-b69e-a1e0ddff10ed",
|
||||||
|
Name = "Admin",
|
||||||
|
NormalizedName = "ADMIN"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "3e7ddc7b-94eb-4364-b4d5-311c76dad5b1",
|
||||||
|
ConcurrencyStamp = "1d59afd3-30f6-492c-87eb-cddf0b251f85",
|
||||||
|
Name = "SuperAdmin",
|
||||||
|
NormalizedName = "SUPERADMIN"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoleClaims");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<int>("AccessFailedCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<bool>("EmailConfirmed")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<bool>("LockoutEnabled")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedEmail")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedUserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("PhoneNumberConfirmed")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityStamp")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("TwoFactorEnabled")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("UserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedEmail")
|
||||||
|
.HasDatabaseName("EmailIndex");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedUserName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("UserNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUsers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserClaims");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderKey")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderDisplayName")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("LoginProvider", "ProviderKey");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserLogins");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserRoles");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "LoginProvider", "Name");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace GWMS.User.Migrations
|
||||||
|
{
|
||||||
|
public partial class UndefRoleAdd : Migration
|
||||||
|
{
|
||||||
|
#region Protected Methods
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "bf698c1c-ead1-4d88-83ef-536098876807");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ "bf698c1c-ead1-4d88-83ef-536098876807", "28d97b49-8df4-4d20-8680-1d3abbf4ed94", "Undef", "UNDEF" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Protected Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,308 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using GWMS.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace GWMS.User.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserIdentityDbContext))]
|
||||||
|
[Migration("20210824155840_FixRolesName")]
|
||||||
|
partial class FixRolesName
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 64)
|
||||||
|
.HasAnnotation("ProductVersion", "5.0.8");
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("RoleNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoles");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "5287113c-6493-4419-bbc9-2cb2f6455006",
|
||||||
|
ConcurrencyStamp = "00059b0a-3e8c-406e-a578-2ae40c52435a",
|
||||||
|
Name = "Undef",
|
||||||
|
NormalizedName = "UNDEF"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "f27a0416-02cc-4e4c-8983-29cb51eb4f9a",
|
||||||
|
ConcurrencyStamp = "b58874fc-02b5-4efa-b4d5-61bfda8b7c67",
|
||||||
|
Name = "ExtUser",
|
||||||
|
NormalizedName = "EXTUSER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "00e6b3ed-dd0e-4cd5-8d3d-f88d8ae5e145",
|
||||||
|
ConcurrencyStamp = "cd1f0ba9-9f42-42f3-8271-1627ef55d36f",
|
||||||
|
Name = "User",
|
||||||
|
NormalizedName = "USER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "5b928219-a530-49c6-be33-f65253865a98",
|
||||||
|
ConcurrencyStamp = "6de09bee-9a83-416a-90c4-27bb643519f6",
|
||||||
|
Name = "Admin",
|
||||||
|
NormalizedName = "ADMIN"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "e9befc87-9732-4c21-b91e-7aea6a289d35",
|
||||||
|
ConcurrencyStamp = "f2bf6c1c-4043-4344-8b68-c8b2122ab88f",
|
||||||
|
Name = "SuperAdmin",
|
||||||
|
NormalizedName = "SUPERADMIN"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoleClaims");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<int>("AccessFailedCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<bool>("EmailConfirmed")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<bool>("LockoutEnabled")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedEmail")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedUserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("PhoneNumberConfirmed")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityStamp")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("TwoFactorEnabled")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("UserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedEmail")
|
||||||
|
.HasDatabaseName("EmailIndex");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedUserName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("UserNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUsers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserClaims");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderKey")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderDisplayName")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("LoginProvider", "ProviderKey");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserLogins");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserRoles");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("varchar(255)");
|
||||||
|
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("varchar(128)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "LoginProvider", "Name");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace GWMS.User.Migrations
|
||||||
|
{
|
||||||
|
public partial class FixRolesName : Migration
|
||||||
|
{
|
||||||
|
#region Protected Methods
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "00e6b3ed-dd0e-4cd5-8d3d-f88d8ae5e145");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "5287113c-6493-4419-bbc9-2cb2f6455006");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "5b928219-a530-49c6-be33-f65253865a98");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "e9befc87-9732-4c21-b91e-7aea6a289d35");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "f27a0416-02cc-4e4c-8983-29cb51eb4f9a");
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ "bf698c1c-ead1-4d88-83ef-536098876807", "28d97b49-8df4-4d20-8680-1d3abbf4ed94", "Undef", "UNDEF" },
|
||||||
|
{ "24a790ae-8eac-4c9f-9043-aa688b626169", "c9adff6c-ffac-48e3-899b-8549ca443071", "ExtUser", "EXTUSER" },
|
||||||
|
{ "7a024dca-5e5d-47be-b754-75c8921d88bf", "3b9aab89-73b6-4051-9825-d5381d2896da", "User", "USER" },
|
||||||
|
{ "0a5335f9-64b2-4196-9d5b-db873cb48d94", "25097cab-df45-4bdd-8616-041962c72050", "Admin", "ADMIN" },
|
||||||
|
{ "f6aa57e0-fac5-45b7-8e27-fd01d8eff87d", "3c222fe9-d5e5-4ba0-9767-4c1777677105", "SuperAdmin", "SUPERADMIN" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "0a5335f9-64b2-4196-9d5b-db873cb48d94");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "24a790ae-8eac-4c9f-9043-aa688b626169");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "7a024dca-5e5d-47be-b754-75c8921d88bf");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "bf698c1c-ead1-4d88-83ef-536098876807");
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: "f6aa57e0-fac5-45b7-8e27-fd01d8eff87d");
|
||||||
|
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "AspNetRoles",
|
||||||
|
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ "5287113c-6493-4419-bbc9-2cb2f6455006", "00059b0a-3e8c-406e-a578-2ae40c52435a", "Undef", "UNDEF" },
|
||||||
|
{ "f27a0416-02cc-4e4c-8983-29cb51eb4f9a", "b58874fc-02b5-4efa-b4d5-61bfda8b7c67", "ExtUser", "EXTUSER" },
|
||||||
|
{ "00e6b3ed-dd0e-4cd5-8d3d-f88d8ae5e145", "cd1f0ba9-9f42-42f3-8271-1627ef55d36f", "User", "USER" },
|
||||||
|
{ "5b928219-a530-49c6-be33-f65253865a98", "6de09bee-9a83-416a-90c4-27bb643519f6", "Admin", "ADMIN" },
|
||||||
|
{ "e9befc87-9732-4c21-b91e-7aea6a289d35", "f2bf6c1c-4043-4344-8b68-c8b2122ab88f", "SuperAdmin", "SUPERADMIN" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Protected Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ namespace GWMS.User.Migrations
|
|||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 64)
|
.HasAnnotation("Relational:MaxIdentifierLength", 64)
|
||||||
.HasAnnotation("ProductVersion", "5.0.7");
|
.HasAnnotation("ProductVersion", "5.0.8");
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||||
{
|
{
|
||||||
@@ -41,6 +41,43 @@ namespace GWMS.User.Migrations
|
|||||||
.HasDatabaseName("RoleNameIndex");
|
.HasDatabaseName("RoleNameIndex");
|
||||||
|
|
||||||
b.ToTable("AspNetRoles");
|
b.ToTable("AspNetRoles");
|
||||||
|
|
||||||
|
b.HasData(
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "5287113c-6493-4419-bbc9-2cb2f6455006",
|
||||||
|
ConcurrencyStamp = "00059b0a-3e8c-406e-a578-2ae40c52435a",
|
||||||
|
Name = "Undef",
|
||||||
|
NormalizedName = "UNDEF"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "f27a0416-02cc-4e4c-8983-29cb51eb4f9a",
|
||||||
|
ConcurrencyStamp = "b58874fc-02b5-4efa-b4d5-61bfda8b7c67",
|
||||||
|
Name = "ExtUser",
|
||||||
|
NormalizedName = "EXTUSER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "00e6b3ed-dd0e-4cd5-8d3d-f88d8ae5e145",
|
||||||
|
ConcurrencyStamp = "cd1f0ba9-9f42-42f3-8271-1627ef55d36f",
|
||||||
|
Name = "User",
|
||||||
|
NormalizedName = "USER"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "5b928219-a530-49c6-be33-f65253865a98",
|
||||||
|
ConcurrencyStamp = "6de09bee-9a83-416a-90c4-27bb643519f6",
|
||||||
|
Name = "Admin",
|
||||||
|
NormalizedName = "ADMIN"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = "e9befc87-9732-4c21-b91e-7aea6a289d35",
|
||||||
|
ConcurrencyStamp = "f2bf6c1c-4043-4344-8b68-c8b2122ab88f",
|
||||||
|
Name = "SuperAdmin",
|
||||||
|
NormalizedName = "SUPERADMIN"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GWMS.Data
|
||||||
|
{
|
||||||
|
public class RoleConfiguration : IEntityTypeConfiguration<IdentityRole>
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void Configure(EntityTypeBuilder<IdentityRole> builder)
|
||||||
|
{
|
||||||
|
builder.HasData(
|
||||||
|
new IdentityRole { Name = "Undef", NormalizedName = "UNDEF" },
|
||||||
|
new IdentityRole { Name = "ExtUser", NormalizedName = "EXTUSER" },
|
||||||
|
new IdentityRole { Name = "User", NormalizedName = "USER" },
|
||||||
|
new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" },
|
||||||
|
new IdentityRole { Name = "SuperAdmin", NormalizedName = "SUPERADMIN" }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GWMS.Data
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Classe generalizzaizone identity (user + roles + claims) x gestione semplificata in editing
|
||||||
|
/// </summary>
|
||||||
|
public class UserData
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public List<System.Security.Claims.Claim> Claims { get; set; }
|
||||||
|
|
||||||
|
public IdentityUser Identity { get; set; }
|
||||||
|
|
||||||
|
public List<string> Roles { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,13 +14,29 @@ namespace GWMS.Data
|
|||||||
|
|
||||||
public UserIdentityDbContext()
|
public UserIdentityDbContext()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// se non ci fosse... crea o migra!
|
||||||
|
Database.Migrate();
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options)
|
public UserIdentityDbContext(DbContextOptions<UserIdentityDbContext> options)
|
||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
|
#if false
|
||||||
// se non ci fosse... crea!
|
// se non ci fosse... crea!
|
||||||
Database.EnsureCreated();
|
Database.EnsureCreated();
|
||||||
|
#endif
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// se non ci fosse... crea o migra!
|
||||||
|
Database.Migrate();
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Constructors
|
#endregion Public Constructors
|
||||||
@@ -43,6 +59,13 @@ namespace GWMS.Data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(builder);
|
||||||
|
|
||||||
|
builder.ApplyConfiguration(new RoleConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Protected Methods
|
#endregion Protected Methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-10
@@ -1,10 +1,12 @@
|
|||||||
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
|
<CascadingAuthenticationState>
|
||||||
<Found Context="routeData">
|
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
|
||||||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
<Found Context="routeData">
|
||||||
</Found>
|
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||||
<NotFound>
|
</Found>
|
||||||
<LayoutView Layout="@typeof(MainLayout)">
|
<NotFound>
|
||||||
<p>Sorry, there's nothing at this address.</p>
|
<LayoutView Layout="@typeof(MainLayout)">
|
||||||
</LayoutView>
|
<p>Sorry, there's nothing at this address.</p>
|
||||||
</NotFound>
|
</LayoutView>
|
||||||
</Router>
|
</NotFound>
|
||||||
|
</Router>
|
||||||
|
</CascadingAuthenticationState>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
|
||||||
|
<Found Context="routeData">
|
||||||
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
|
||||||
|
</Found>
|
||||||
|
<NotFound>
|
||||||
|
<LayoutView Layout="@typeof(MainLayout)">
|
||||||
|
<p>Sorry, there's nothing at this address.</p>
|
||||||
|
</LayoutView>
|
||||||
|
</NotFound>
|
||||||
|
</Router>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using GWMS.Data;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
[assembly: HostingStartup(typeof(GWMS.UI.Areas.Identity.IdentityHostingStartup))]
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity
|
||||||
|
{
|
||||||
|
public class IdentityHostingStartup : IHostingStartup
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void Configure(IWebHostBuilder builder)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@page
|
||||||
|
@model AccessDeniedModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Access denied";
|
||||||
|
}
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<h1 class="text-danger">@ViewData["Title"]</h1>
|
||||||
|
<p class="text-danger">You do not have access to this resource.</p>
|
||||||
|
</header>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
public class AccessDeniedModel : PageModel
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
@page
|
||||||
|
@model ConfirmEmailModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Confirm email";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ConfirmEmailModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ConfirmEmailModel(UserManager<IdentityUser> userManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync(string userId, string code)
|
||||||
|
{
|
||||||
|
if (userId == null || code == null)
|
||||||
|
{
|
||||||
|
return RedirectToPage("/Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.FindByIdAsync(userId);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{userId}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
|
||||||
|
var result = await _userManager.ConfirmEmailAsync(user, code);
|
||||||
|
StatusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email.";
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@page
|
||||||
|
@model ConfirmEmailChangeModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Confirm email change";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<partial name="_StatusMessage" model="Model.StatusMessage" />
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ConfirmEmailChangeModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ConfirmEmailChangeModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync(string userId, string email, string code)
|
||||||
|
{
|
||||||
|
if (userId == null || email == null || code == null)
|
||||||
|
{
|
||||||
|
return RedirectToPage("/Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.FindByIdAsync(userId);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{userId}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
|
||||||
|
var result = await _userManager.ChangeEmailAsync(user, email, code);
|
||||||
|
if (!result.Succeeded)
|
||||||
|
{
|
||||||
|
StatusMessage = "Error changing email.";
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
// In our UI email and user name are one and the same, so when we update the email
|
||||||
|
// we need to update the user name.
|
||||||
|
var setUserNameResult = await _userManager.SetUserNameAsync(user, email);
|
||||||
|
if (!setUserNameResult.Succeeded)
|
||||||
|
{
|
||||||
|
StatusMessage = "Error changing user name.";
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
StatusMessage = "Thank you for confirming your email change.";
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
@page
|
||||||
|
@model ExternalLoginModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Register";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<h4 id="external-login-title">Associate your @Model.ProviderDisplayName account.</h4>
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<p id="external-login-description" class="text-info">
|
||||||
|
You've successfully authenticated with <strong>@Model.ProviderDisplayName</strong>.
|
||||||
|
Please enter an email address for this site below and click the Register button to finish
|
||||||
|
logging in.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form asp-page-handler="Confirmation" asp-route-returnUrl="@Model.ReturnUrl" method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Email"></label>
|
||||||
|
<input asp-for="Input.Email" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ExternalLoginModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IEmailSender _emailSender;
|
||||||
|
private readonly ILogger<ExternalLoginModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ExternalLoginModel(
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
ILogger<ExternalLoginModel> logger,
|
||||||
|
IEmailSender emailSender)
|
||||||
|
{
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_userManager = userManager;
|
||||||
|
_logger = logger;
|
||||||
|
_emailSender = emailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public string ProviderDisplayName { get; set; }
|
||||||
|
|
||||||
|
public string ReturnUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public IActionResult OnGetAsync()
|
||||||
|
{
|
||||||
|
return RedirectToPage("./Login");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
|
||||||
|
{
|
||||||
|
returnUrl = returnUrl ?? Url.Content("~/");
|
||||||
|
if (remoteError != null)
|
||||||
|
{
|
||||||
|
ErrorMessage = $"Error from external provider: {remoteError}";
|
||||||
|
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
|
||||||
|
}
|
||||||
|
var info = await _signInManager.GetExternalLoginInfoAsync();
|
||||||
|
if (info == null)
|
||||||
|
{
|
||||||
|
ErrorMessage = "Error loading external login information.";
|
||||||
|
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign in the user with this external login provider if the user already has a login.
|
||||||
|
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true);
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
|
||||||
|
return LocalRedirect(returnUrl);
|
||||||
|
}
|
||||||
|
if (result.IsLockedOut)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./Lockout");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the user does not have an account, then ask the user to create an account.
|
||||||
|
ReturnUrl = returnUrl;
|
||||||
|
ProviderDisplayName = info.ProviderDisplayName;
|
||||||
|
if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
|
||||||
|
{
|
||||||
|
Input = new InputModel
|
||||||
|
{
|
||||||
|
Email = info.Principal.FindFirstValue(ClaimTypes.Email)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult OnPost(string provider, string returnUrl = null)
|
||||||
|
{
|
||||||
|
// Request a redirect to the external login provider.
|
||||||
|
var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
|
||||||
|
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
|
||||||
|
return new ChallengeResult(provider, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
returnUrl = returnUrl ?? Url.Content("~/");
|
||||||
|
// Get the information about the user from the external login provider
|
||||||
|
var info = await _signInManager.GetExternalLoginInfoAsync();
|
||||||
|
if (info == null)
|
||||||
|
{
|
||||||
|
ErrorMessage = "Error loading external login information during confirmation.";
|
||||||
|
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var user = new IdentityUser { UserName = Input.Email, Email = Input.Email };
|
||||||
|
|
||||||
|
var result = await _userManager.CreateAsync(user);
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
result = await _userManager.AddLoginAsync(user, info);
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
|
||||||
|
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
var callbackUrl = Url.Page(
|
||||||
|
"/Account/ConfirmEmail",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
|
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
||||||
|
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
||||||
|
|
||||||
|
// If account confirmation is required, we need to show the link if we don't have a real email sender
|
||||||
|
if (_userManager.Options.SignIn.RequireConfirmedAccount)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email });
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider);
|
||||||
|
|
||||||
|
return LocalRedirect(returnUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var error in result.Errors)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, error.Description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProviderDisplayName = info.ProviderDisplayName;
|
||||||
|
ReturnUrl = returnUrl;
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
@page
|
||||||
|
@model ForgotPasswordModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Forgot your password?";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<h4>Enter your email.</h4>
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form method="post">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Email"></label>
|
||||||
|
<input asp-for="Input.Email" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ForgotPasswordModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IEmailSender _emailSender;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ForgotPasswordModel(UserManager<IdentityUser> userManager, IEmailSender emailSender)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_emailSender = emailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var user = await _userManager.FindByEmailAsync(Input.Email);
|
||||||
|
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
|
||||||
|
{
|
||||||
|
// Don't reveal that the user does not exist or is not confirmed
|
||||||
|
return RedirectToPage("./ForgotPasswordConfirmation");
|
||||||
|
}
|
||||||
|
|
||||||
|
// For more information on how to enable account confirmation and password reset please
|
||||||
|
// visit https://go.microsoft.com/fwlink/?LinkID=532713
|
||||||
|
var code = await _userManager.GeneratePasswordResetTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
var callbackUrl = Url.Page(
|
||||||
|
"/Account/ResetPassword",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { area = "Identity", code },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
|
await _emailSender.SendEmailAsync(
|
||||||
|
Input.Email,
|
||||||
|
"Reset Password",
|
||||||
|
$"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
||||||
|
|
||||||
|
return RedirectToPage("./ForgotPasswordConfirmation");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
@page
|
||||||
|
@model ForgotPasswordConfirmation
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Forgot password confirmation";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<p>
|
||||||
|
Please check your email to reset your password.
|
||||||
|
</p>
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ForgotPasswordConfirmation : PageModel
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@page
|
||||||
|
@model LockoutModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Locked out";
|
||||||
|
}
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<h1 class="text-danger">@ViewData["Title"]</h1>
|
||||||
|
<p class="text-danger">This account has been locked out, please try again later.</p>
|
||||||
|
</header>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class LockoutModel : PageModel
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,21 @@
|
|||||||
@page
|
@page
|
||||||
@using Microsoft.AspNetCore.Identity
|
@model LogoutModel
|
||||||
@attribute [IgnoreAntiforgeryToken]
|
@{
|
||||||
@inject SignInManager<IdentityUser> SignInManager
|
ViewData["Title"] = "Log out";
|
||||||
@functions {
|
|
||||||
public async Task<IActionResult> OnPost()
|
|
||||||
{
|
|
||||||
if (SignInManager.IsSignedIn(User))
|
|
||||||
{
|
|
||||||
await SignInManager.SignOutAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Redirect("~/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
@{
|
||||||
|
if (User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
<form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Page("/", new { area = "" })" method="post">
|
||||||
|
<button type="submit" class="nav-link btn btn-warning">Click here to Logout</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<p>You have successfully logged out of the application.</p>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</header>
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
@page
|
||||||
|
@model LoginModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Log in";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<section>
|
||||||
|
<form id="account" method="post">
|
||||||
|
<h4>Use a local account to log in.</h4>
|
||||||
|
<hr />
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Email"></label>
|
||||||
|
<input asp-for="Input.Email" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Password"></label>
|
||||||
|
<input asp-for="Input.Password" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Password" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="checkbox">
|
||||||
|
<label asp-for="Input.RememberMe">
|
||||||
|
<input asp-for="Input.RememberMe" />
|
||||||
|
@Html.DisplayNameFor(m => m.Input.RememberMe)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-primary">Log in</button>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<p>
|
||||||
|
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
@*<div class="col-md-6 col-md-offset-2">
|
||||||
|
<section>
|
||||||
|
<h4>Use another service to log in.</h4>
|
||||||
|
<hr />
|
||||||
|
@{
|
||||||
|
if ((Model.ExternalLogins?.Count ?? 0) == 0)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
There are no external authentication services configured. See <a href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</a>
|
||||||
|
for details on setting up this ASP.NET application to support logging in via external services.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
@foreach (var provider in Model.ExternalLogins)
|
||||||
|
{
|
||||||
|
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
</div>*@
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class LoginModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<LoginModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public LoginModel(SignInManager<IdentityUser> signInManager,
|
||||||
|
ILogger<LoginModel> logger,
|
||||||
|
UserManager<IdentityUser> userManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
public IList<AuthenticationScheme> ExternalLogins { get; set; }
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public string ReturnUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private async Task CheckSuperAdmin()
|
||||||
|
{
|
||||||
|
// se non ci fosse --> creo samuele come superadmin
|
||||||
|
string superUser = "samuele@steamware.net";
|
||||||
|
string superPwd = "viaDante16!";
|
||||||
|
string ADMIN_ROLE = "SuperAdmin";
|
||||||
|
var user = await _userManager.FindByEmailAsync(superUser);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
// Insert new user
|
||||||
|
var NewUser =
|
||||||
|
new IdentityUser
|
||||||
|
{
|
||||||
|
UserName = superUser,
|
||||||
|
Email = superUser,
|
||||||
|
EmailConfirmed = true
|
||||||
|
};
|
||||||
|
var CreateResult = await _userManager.CreateAsync(NewUser, superPwd);
|
||||||
|
if (CreateResult.Succeeded)
|
||||||
|
{
|
||||||
|
user = await _userManager.FindByEmailAsync(superUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// verifico ruoli...
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
// Gestione salvataggio ruoli... SE VARIATO...
|
||||||
|
var UserRoles = await _userManager.GetRolesAsync(user);
|
||||||
|
if (UserRoles != null && UserRoles.Count > 0)
|
||||||
|
{
|
||||||
|
var oldRole = UserRoles.Where(x => x == ADMIN_ROLE).FirstOrDefault();
|
||||||
|
if (oldRole == null)
|
||||||
|
{
|
||||||
|
// aggiungo a ruolo admin
|
||||||
|
await _userManager.AddToRoleAsync(user, ADMIN_ROLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Private Methods
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task OnGetAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
CheckSuperAdmin();
|
||||||
|
if (!string.IsNullOrEmpty(ErrorMessage))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, ErrorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
returnUrl ??= Url.Content("~/");
|
||||||
|
|
||||||
|
// Clear the existing external cookie to ensure a clean login process
|
||||||
|
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
||||||
|
|
||||||
|
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
|
||||||
|
|
||||||
|
ReturnUrl = returnUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
returnUrl ??= Url.Content("~/");
|
||||||
|
|
||||||
|
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
|
||||||
|
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
// This doesn't count login failures towards account lockout
|
||||||
|
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
|
||||||
|
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("User logged in.");
|
||||||
|
return LocalRedirect(returnUrl);
|
||||||
|
}
|
||||||
|
if (result.RequiresTwoFactor)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
|
||||||
|
}
|
||||||
|
if (result.IsLockedOut)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("User account locked out.");
|
||||||
|
return RedirectToPage("./Lockout");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we got this far, something failed, redisplay form
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
[Display(Name = "Remember me?")]
|
||||||
|
public bool RememberMe { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
@page
|
||||||
|
@model LoginWith2faModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Two-factor authentication";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<hr />
|
||||||
|
<p>Your login is protected with an authenticator app. Enter your authenticator code below.</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form method="post" asp-route-returnUrl="@Model.ReturnUrl">
|
||||||
|
<input asp-for="RememberMe" type="hidden" />
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.TwoFactorCode"></label>
|
||||||
|
<input asp-for="Input.TwoFactorCode" class="form-control" autocomplete="off" />
|
||||||
|
<span asp-validation-for="Input.TwoFactorCode" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="checkbox">
|
||||||
|
<label asp-for="Input.RememberMachine">
|
||||||
|
<input asp-for="Input.RememberMachine" />
|
||||||
|
@Html.DisplayNameFor(m => m.Input.RememberMachine)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-primary">Log in</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
Don't have access to your authenticator device? You can
|
||||||
|
<a id="recovery-code-login" asp-page="./LoginWithRecoveryCode" asp-route-returnUrl="@Model.ReturnUrl">log in with a recovery code</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class LoginWith2faModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<LoginWith2faModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public LoginWith2faModel(SignInManager<IdentityUser> signInManager, ILogger<LoginWith2faModel> logger)
|
||||||
|
{
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public bool RememberMe { get; set; }
|
||||||
|
|
||||||
|
public string ReturnUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync(bool rememberMe, string returnUrl = null)
|
||||||
|
{
|
||||||
|
// Ensure the user has gone through the username & password screen first
|
||||||
|
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unable to load two-factor authentication user.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnUrl = returnUrl;
|
||||||
|
RememberMe = rememberMe;
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync(bool rememberMe, string returnUrl = null)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
returnUrl = returnUrl ?? Url.Content("~/");
|
||||||
|
|
||||||
|
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unable to load two-factor authentication user.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);
|
||||||
|
|
||||||
|
var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, rememberMe, Input.RememberMachine);
|
||||||
|
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", user.Id);
|
||||||
|
return LocalRedirect(returnUrl);
|
||||||
|
}
|
||||||
|
else if (result.IsLockedOut)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
|
||||||
|
return RedirectToPage("./Lockout");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id);
|
||||||
|
ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Display(Name = "Remember this machine")]
|
||||||
|
public bool RememberMachine { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||||
|
[DataType(DataType.Text)]
|
||||||
|
[Display(Name = "Authenticator code")]
|
||||||
|
public string TwoFactorCode { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
@page
|
||||||
|
@model LoginWithRecoveryCodeModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Recovery code verification";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<hr />
|
||||||
|
<p>
|
||||||
|
You have requested to log in with a recovery code. This login will not be remembered until you provide
|
||||||
|
an authenticator app code at log in or disable 2FA and log in again.
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form method="post">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.RecoveryCode"></label>
|
||||||
|
<input asp-for="Input.RecoveryCode" class="form-control" autocomplete="off" />
|
||||||
|
<span asp-validation-for="Input.RecoveryCode" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Log in</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class LoginWithRecoveryCodeModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<LoginWithRecoveryCodeModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public LoginWithRecoveryCodeModel(SignInManager<IdentityUser> signInManager, ILogger<LoginWithRecoveryCodeModel> logger)
|
||||||
|
{
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public string ReturnUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
// Ensure the user has gone through the username & password screen first
|
||||||
|
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unable to load two-factor authentication user.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnUrl = returnUrl;
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unable to load two-factor authentication user.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty);
|
||||||
|
|
||||||
|
var result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode);
|
||||||
|
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' logged in with a recovery code.", user.Id);
|
||||||
|
return LocalRedirect(returnUrl ?? Url.Content("~/"));
|
||||||
|
}
|
||||||
|
if (result.IsLockedOut)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
|
||||||
|
return RedirectToPage("./Lockout");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", user.Id);
|
||||||
|
ModelState.AddModelError(string.Empty, "Invalid recovery code entered.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
[Required]
|
||||||
|
[DataType(DataType.Text)]
|
||||||
|
[Display(Name = "Recovery Code")]
|
||||||
|
public string RecoveryCode { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class LogoutModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<LogoutModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public LogoutModel(SignInManager<IdentityUser> signInManager, ILogger<LogoutModel> logger)
|
||||||
|
{
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPost(string returnUrl = null)
|
||||||
|
{
|
||||||
|
await _signInManager.SignOutAsync();
|
||||||
|
_logger.LogInformation("User logged out.");
|
||||||
|
if (returnUrl != null)
|
||||||
|
{
|
||||||
|
return LocalRedirect(returnUrl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
@page
|
||||||
|
@model ChangePasswordModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Change password";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.ChangePassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<form id="change-password-form" method="post">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.OldPassword"></label>
|
||||||
|
<input asp-for="Input.OldPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.OldPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.NewPassword"></label>
|
||||||
|
<input asp-for="Input.NewPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.NewPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.ConfirmPassword"></label>
|
||||||
|
<input asp-for="Input.ConfirmPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Update password</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class ChangePasswordModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<ChangePasswordModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ChangePasswordModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
ILogger<ChangePasswordModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasPassword = await _userManager.HasPasswordAsync(user);
|
||||||
|
if (!hasPassword)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./SetPassword");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var changePasswordResult = await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword);
|
||||||
|
if (!changePasswordResult.Succeeded)
|
||||||
|
{
|
||||||
|
foreach (var error in changePasswordResult.Errors)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, error.Description);
|
||||||
|
}
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
_logger.LogInformation("User changed their password successfully.");
|
||||||
|
StatusMessage = "Your password has been changed.";
|
||||||
|
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Confirm new password")]
|
||||||
|
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||||
|
public string ConfirmPassword { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "New password")]
|
||||||
|
public string NewPassword { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Current password")]
|
||||||
|
public string OldPassword { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
@page
|
||||||
|
@model DeletePersonalDataModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete Personal Data";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.PersonalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<p>
|
||||||
|
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<form id="delete-user" method="post" class="form-group">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
@if (Model.RequirePassword)
|
||||||
|
{
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Password"></label>
|
||||||
|
<input asp-for="Input.Password" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Password" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<button class="btn btn-danger" type="submit">Delete data and close my account</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class DeletePersonalDataModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<DeletePersonalDataModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public DeletePersonalDataModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
ILogger<DeletePersonalDataModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public bool RequirePassword { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
RequirePassword = await _userManager.HasPasswordAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
RequirePassword = await _userManager.HasPasswordAsync(user);
|
||||||
|
if (RequirePassword)
|
||||||
|
{
|
||||||
|
if (!await _userManager.CheckPasswordAsync(user, Input.Password))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, "Incorrect password.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _userManager.DeleteAsync(user);
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
if (!result.Succeeded)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.SignOutAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);
|
||||||
|
|
||||||
|
return Redirect("~/");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
@page
|
||||||
|
@model Disable2faModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Disable two-factor authentication (2FA)";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<h2>@ViewData["Title"]</h2>
|
||||||
|
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<p>
|
||||||
|
<strong>This action only disables 2FA.</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Disabling 2FA does not change the keys used in authenticator apps. If you wish to change the key
|
||||||
|
used in an authenticator app you should <a asp-page="./ResetAuthenticator">reset your authenticator keys.</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<form method="post" class="form-group">
|
||||||
|
<button class="btn btn-danger" type="submit">Disable 2FA</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class Disable2faModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<Disable2faModel> _logger;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public Disable2faModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
ILogger<Disable2faModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!await _userManager.GetTwoFactorEnabledAsync(user))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false);
|
||||||
|
if (!disable2faResult.Succeeded)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", _userManager.GetUserId(User));
|
||||||
|
StatusMessage = "2fa has been disabled. You can reenable 2fa when you setup an authenticator app";
|
||||||
|
return RedirectToPage("./TwoFactorAuthentication");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
@page
|
||||||
|
@model DownloadPersonalDataModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Download Your Data";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.PersonalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class DownloadPersonalDataModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<DownloadPersonalDataModel> _logger;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public DownloadPersonalDataModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
ILogger<DownloadPersonalDataModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' asked for their personal data.", _userManager.GetUserId(User));
|
||||||
|
|
||||||
|
// Only include personal data for download
|
||||||
|
var personalData = new Dictionary<string, string>();
|
||||||
|
var personalDataProps = typeof(IdentityUser).GetProperties().Where(
|
||||||
|
prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute)));
|
||||||
|
foreach (var p in personalDataProps)
|
||||||
|
{
|
||||||
|
personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
|
||||||
|
}
|
||||||
|
|
||||||
|
var logins = await _userManager.GetLoginsAsync(user);
|
||||||
|
foreach (var l in logins)
|
||||||
|
{
|
||||||
|
personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
|
||||||
|
return new FileContentResult(JsonSerializer.SerializeToUtf8Bytes(personalData), "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
@page
|
||||||
|
@model EmailModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Manage Email";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.Email;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<partial name="_StatusMessage" model="Model.StatusMessage" />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<form id="email-form" method="post">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Email"></label>
|
||||||
|
@if (Model.IsEmailConfirmed)
|
||||||
|
{
|
||||||
|
<div class="input-group">
|
||||||
|
<input asp-for="Email" class="form-control" disabled />
|
||||||
|
<div class="input-group-append">
|
||||||
|
<span class="input-group-text text-success font-weight-bold">✓</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<input asp-for="Email" class="form-control" disabled />
|
||||||
|
<button id="email-verification" type="submit" asp-page-handler="SendVerificationEmail" class="btn btn-link">Send verification email</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.NewEmail"></label>
|
||||||
|
<input asp-for="Input.NewEmail" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="btn btn-primary">Change email</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public partial class EmailModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IEmailSender _emailSender;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public EmailModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
IEmailSender emailSender)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_emailSender = emailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public bool IsEmailConfirmed { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private async Task LoadAsync(IdentityUser user)
|
||||||
|
{
|
||||||
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
|
Email = email;
|
||||||
|
|
||||||
|
Input = new InputModel
|
||||||
|
{
|
||||||
|
NewEmail = email,
|
||||||
|
};
|
||||||
|
|
||||||
|
IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Private Methods
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostChangeEmailAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
|
if (Input.NewEmail != email)
|
||||||
|
{
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
var code = await _userManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
var callbackUrl = Url.Page(
|
||||||
|
"/Account/ConfirmEmailChange",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { userId = userId, email = Input.NewEmail, code = code },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
await _emailSender.SendEmailAsync(
|
||||||
|
Input.NewEmail,
|
||||||
|
"Confirm your email",
|
||||||
|
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
||||||
|
|
||||||
|
StatusMessage = "Confirmation link to change email sent. Please check your email.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusMessage = "Your email is unchanged.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostSendVerificationEmailAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
var callbackUrl = Url.Page(
|
||||||
|
"/Account/ConfirmEmail",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { area = "Identity", userId = userId, code = code },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
await _emailSender.SendEmailAsync(
|
||||||
|
email,
|
||||||
|
"Confirm your email",
|
||||||
|
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
||||||
|
|
||||||
|
StatusMessage = "Verification email sent. Please check your email.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
[Display(Name = "New email")]
|
||||||
|
public string NewEmail { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
@page
|
||||||
|
@model EnableAuthenticatorModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Configure authenticator app";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<div>
|
||||||
|
<p>To use an authenticator app go through the following steps:</p>
|
||||||
|
<ol class="list">
|
||||||
|
<li>
|
||||||
|
<p>
|
||||||
|
Download a two-factor authenticator app like Microsoft Authenticator for
|
||||||
|
<a href="https://go.microsoft.com/fwlink/?Linkid=825072">Android</a> and
|
||||||
|
<a href="https://go.microsoft.com/fwlink/?Linkid=825073">iOS</a> or
|
||||||
|
Google Authenticator for
|
||||||
|
<a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en">Android</a> and
|
||||||
|
<a href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</a>.
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>Scan the QR Code or enter this key <kbd>@Model.SharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p>
|
||||||
|
@*<div class="alert alert-info">Learn how to <a href="https://go.microsoft.com/fwlink/?Linkid=852423">enable QR code generation</a>.</div>*@
|
||||||
|
<div id="qrCode"></div>
|
||||||
|
<div id="qrCodeData" data-url="@Html.Raw(@Model.AuthenticatorUri)"></div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>
|
||||||
|
Once you have scanned the QR code or input the key above, your two factor authentication app will provide you
|
||||||
|
with a unique code. Enter the code in the confirmation box below.
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<form id="send-code" method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Code" class="control-label">Verification Code</label>
|
||||||
|
<input asp-for="Input.Code" class="form-control" autocomplete="off" />
|
||||||
|
<span asp-validation-for="Input.Code" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Verify</button>
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
|
||||||
|
<script type="text/javascript" src="~/lib/qrcode.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
new QRCode(document.getElementById("qrCode"),
|
||||||
|
{
|
||||||
|
text: "@Html.Raw(Model.AuthenticatorUri)",
|
||||||
|
width: 150,
|
||||||
|
height: 150
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class EnableAuthenticatorModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
|
||||||
|
private readonly ILogger<EnableAuthenticatorModel> _logger;
|
||||||
|
private readonly UrlEncoder _urlEncoder;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public EnableAuthenticatorModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
ILogger<EnableAuthenticatorModel> logger,
|
||||||
|
UrlEncoder urlEncoder)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_logger = logger;
|
||||||
|
_urlEncoder = urlEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public string AuthenticatorUri { get; set; }
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string[] RecoveryCodes { get; set; }
|
||||||
|
|
||||||
|
public string SharedKey { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private string FormatKey(string unformattedKey)
|
||||||
|
{
|
||||||
|
var result = new StringBuilder();
|
||||||
|
int currentPosition = 0;
|
||||||
|
while (currentPosition + 4 < unformattedKey.Length)
|
||||||
|
{
|
||||||
|
result.Append(unformattedKey.Substring(currentPosition, 4)).Append(" ");
|
||||||
|
currentPosition += 4;
|
||||||
|
}
|
||||||
|
if (currentPosition < unformattedKey.Length)
|
||||||
|
{
|
||||||
|
result.Append(unformattedKey.Substring(currentPosition));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.ToString().ToLowerInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateQrCodeUri(string email, string unformattedKey)
|
||||||
|
{
|
||||||
|
return string.Format(
|
||||||
|
AuthenticatorUriFormat,
|
||||||
|
_urlEncoder.Encode("GWMS.UI"),
|
||||||
|
_urlEncoder.Encode(email),
|
||||||
|
unformattedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadSharedKeyAndQrCodeUriAsync(IdentityUser user)
|
||||||
|
{
|
||||||
|
// Load the authenticator key & QR code URI to display on the form
|
||||||
|
var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
|
||||||
|
if (string.IsNullOrEmpty(unformattedKey))
|
||||||
|
{
|
||||||
|
await _userManager.ResetAuthenticatorKeyAsync(user);
|
||||||
|
unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedKey = FormatKey(unformattedKey);
|
||||||
|
|
||||||
|
var email = await _userManager.GetEmailAsync(user);
|
||||||
|
AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Private Methods
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await LoadSharedKeyAndQrCodeUriAsync(user);
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadSharedKeyAndQrCodeUriAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip spaces and hypens
|
||||||
|
var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
|
||||||
|
|
||||||
|
var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync(
|
||||||
|
user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);
|
||||||
|
|
||||||
|
if (!is2faTokenValid)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Input.Code", "Verification code is invalid.");
|
||||||
|
await LoadSharedKeyAndQrCodeUriAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _userManager.SetTwoFactorEnabledAsync(user, true);
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId);
|
||||||
|
|
||||||
|
StatusMessage = "Your authenticator app has been verified.";
|
||||||
|
|
||||||
|
if (await _userManager.CountRecoveryCodesAsync(user) == 0)
|
||||||
|
{
|
||||||
|
var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
|
||||||
|
RecoveryCodes = recoveryCodes.ToArray();
|
||||||
|
return RedirectToPage("./ShowRecoveryCodes");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RedirectToPage("./TwoFactorAuthentication");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||||
|
[DataType(DataType.Text)]
|
||||||
|
[Display(Name = "Verification Code")]
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
@page
|
||||||
|
@model ExternalLoginsModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Manage your external logins";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.ExternalLogins;
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
@if (Model.CurrentLogins?.Count > 0)
|
||||||
|
{
|
||||||
|
<h4>Registered Logins</h4>
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
@foreach (var login in Model.CurrentLogins)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td id="@($"login-provider-{login.LoginProvider}")">@login.ProviderDisplayName</td>
|
||||||
|
<td>
|
||||||
|
@if (Model.ShowRemoveButton)
|
||||||
|
{
|
||||||
|
<form id="@($"remove-login-{login.LoginProvider}")" asp-page-handler="RemoveLogin" method="post">
|
||||||
|
<div>
|
||||||
|
<input asp-for="@login.LoginProvider" name="LoginProvider" type="hidden" />
|
||||||
|
<input asp-for="@login.ProviderKey" name="ProviderKey" type="hidden" />
|
||||||
|
<button type="submit" class="btn btn-primary" title="Remove this @login.ProviderDisplayName login from your account">Remove</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@:
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
@if (Model.OtherLogins?.Count > 0)
|
||||||
|
{
|
||||||
|
<h4>Add another service to log in.</h4>
|
||||||
|
<hr />
|
||||||
|
<form id="link-login-form" asp-page-handler="LinkLogin" method="post" class="form-horizontal">
|
||||||
|
<div id="socialLoginList">
|
||||||
|
<p>
|
||||||
|
@foreach (var provider in Model.OtherLogins)
|
||||||
|
{
|
||||||
|
<button id="@($"link-login-button-{provider.Name}")" type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class ExternalLoginsModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ExternalLoginsModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public IList<UserLoginInfo> CurrentLogins { get; set; }
|
||||||
|
|
||||||
|
public IList<AuthenticationScheme> OtherLogins { get; set; }
|
||||||
|
|
||||||
|
public bool ShowRemoveButton { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID 'user.Id'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLogins = await _userManager.GetLoginsAsync(user);
|
||||||
|
OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync())
|
||||||
|
.Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider))
|
||||||
|
.ToList();
|
||||||
|
ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1;
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetLinkLoginCallbackAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID 'user.Id'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var info = await _signInManager.GetExternalLoginInfoAsync(user.Id);
|
||||||
|
if (info == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _userManager.AddLoginAsync(user, info);
|
||||||
|
if (!result.Succeeded)
|
||||||
|
{
|
||||||
|
StatusMessage = "The external login was not added. External logins can only be associated with one account.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the existing external cookie to ensure a clean login process
|
||||||
|
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
||||||
|
|
||||||
|
StatusMessage = "The external login was added.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostLinkLoginAsync(string provider)
|
||||||
|
{
|
||||||
|
// Clear the existing external cookie to ensure a clean login process
|
||||||
|
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
||||||
|
|
||||||
|
// Request a redirect to the external login provider to link a login for the current user
|
||||||
|
var redirectUrl = Url.Page("./ExternalLogins", pageHandler: "LinkLoginCallback");
|
||||||
|
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User));
|
||||||
|
return new ChallengeResult(provider, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostRemoveLoginAsync(string loginProvider, string providerKey)
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID 'user.Id'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
|
||||||
|
if (!result.Succeeded)
|
||||||
|
{
|
||||||
|
StatusMessage = "The external login was not removed.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
StatusMessage = "The external login was removed.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
@page
|
||||||
|
@model GenerateRecoveryCodesModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Generate two-factor authentication (2FA) recovery codes";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<p>
|
||||||
|
<span class="glyphicon glyphicon-warning-sign"></span>
|
||||||
|
<strong>Put these codes in a safe place.</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
If you lose your device and don't have the recovery codes you will lose access to your account.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Generating new recovery codes does not change the keys used in authenticator apps. If you wish to change the key
|
||||||
|
used in an authenticator app you should <a asp-page="./ResetAuthenticator">reset your authenticator keys.</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<form method="post" class="form-group">
|
||||||
|
<button class="btn btn-danger" type="submit">Generate Recovery Codes</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class GenerateRecoveryCodesModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<GenerateRecoveryCodesModel> _logger;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public GenerateRecoveryCodesModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
ILogger<GenerateRecoveryCodesModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string[] RecoveryCodes { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
|
||||||
|
if (!isTwoFactorEnabled)
|
||||||
|
{
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
throw new InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' because they do not have 2FA enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
if (!isTwoFactorEnabled)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' as they do not have 2FA enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
|
||||||
|
RecoveryCodes = recoveryCodes.ToArray();
|
||||||
|
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' has generated new 2FA recovery codes.", userId);
|
||||||
|
StatusMessage = "You have generated new recovery codes.";
|
||||||
|
return RedirectToPage("./ShowRecoveryCodes");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
@page
|
||||||
|
@model IndexModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Profile";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.Index;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<partial name="_StatusMessage" model="Model.StatusMessage" />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<form id="profile-form" method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Username"></label>
|
||||||
|
<input asp-for="Username" class="form-control" disabled />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.PhoneNumber"></label>
|
||||||
|
<input asp-for="Input.PhoneNumber" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.PhoneNumber" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button id="update-profile-button" type="submit" class="btn btn-primary">Save</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public partial class IndexModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public IndexModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private async Task LoadAsync(IdentityUser user)
|
||||||
|
{
|
||||||
|
var userName = await _userManager.GetUserNameAsync(user);
|
||||||
|
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
||||||
|
|
||||||
|
Username = userName;
|
||||||
|
|
||||||
|
Input = new InputModel
|
||||||
|
{
|
||||||
|
PhoneNumber = phoneNumber
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Private Methods
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
await LoadAsync(user);
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
||||||
|
if (Input.PhoneNumber != phoneNumber)
|
||||||
|
{
|
||||||
|
var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
|
||||||
|
if (!setPhoneResult.Succeeded)
|
||||||
|
{
|
||||||
|
StatusMessage = "Unexpected error when trying to set phone number.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
StatusMessage = "Your profile has been updated";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Phone]
|
||||||
|
[Display(Name = "Phone number")]
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public static class ManageNavPages
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public static string ChangePassword => "ChangePassword";
|
||||||
|
public static string DeletePersonalData => "DeletePersonalData";
|
||||||
|
public static string DownloadPersonalData => "DownloadPersonalData";
|
||||||
|
public static string Email => "Email";
|
||||||
|
public static string ExternalLogins => "ExternalLogins";
|
||||||
|
public static string Index => "Index";
|
||||||
|
public static string PersonalData => "PersonalData";
|
||||||
|
|
||||||
|
public static string TwoFactorAuthentication => "TwoFactorAuthentication";
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private static string PageNavClass(ViewContext viewContext, string page)
|
||||||
|
{
|
||||||
|
var activePage = viewContext.ViewData["ActivePage"] as string
|
||||||
|
?? System.IO.Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName);
|
||||||
|
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Private Methods
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public static string ChangePasswordNavClass(ViewContext viewContext) => PageNavClass(viewContext, ChangePassword);
|
||||||
|
|
||||||
|
public static string DeletePersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DeletePersonalData);
|
||||||
|
|
||||||
|
public static string DownloadPersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DownloadPersonalData);
|
||||||
|
|
||||||
|
public static string EmailNavClass(ViewContext viewContext) => PageNavClass(viewContext, Email);
|
||||||
|
|
||||||
|
public static string ExternalLoginsNavClass(ViewContext viewContext) => PageNavClass(viewContext, ExternalLogins);
|
||||||
|
|
||||||
|
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
|
||||||
|
|
||||||
|
public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);
|
||||||
|
|
||||||
|
public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) => PageNavClass(viewContext, TwoFactorAuthentication);
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
@page
|
||||||
|
@model PersonalDataModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Personal Data";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.PersonalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p>
|
||||||
|
<p>
|
||||||
|
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
|
||||||
|
</p>
|
||||||
|
<form id="download-data" asp-page="DownloadPersonalData" method="post" class="form-group">
|
||||||
|
<button class="btn btn-primary" type="submit">Download</button>
|
||||||
|
</form>
|
||||||
|
<p>
|
||||||
|
<a id="delete" asp-page="DeletePersonalData" class="btn btn-secondary">Delete</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class PersonalDataModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILogger<PersonalDataModel> _logger;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public PersonalDataModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
ILogger<PersonalDataModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
@page
|
||||||
|
@model ResetAuthenticatorModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Reset authenticator key";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<p>
|
||||||
|
<span class="glyphicon glyphicon-warning-sign"></span>
|
||||||
|
<strong>If you reset your authenticator key your authenticator app will not work until you reconfigure it.</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
This process disables 2FA until you verify your authenticator app.
|
||||||
|
If you do not complete your authenticator app configuration you may lose access to your account.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<form id="reset-authenticator-form" method="post" class="form-group">
|
||||||
|
<button id="reset-authenticator-button" class="btn btn-danger" type="submit">Reset authenticator key</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class ResetAuthenticatorModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private ILogger<ResetAuthenticatorModel> _logger;
|
||||||
|
private UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ResetAuthenticatorModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
ILogger<ResetAuthenticatorModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await _userManager.SetTwoFactorEnabledAsync(user, false);
|
||||||
|
await _userManager.ResetAuthenticatorKeyAsync(user);
|
||||||
|
_logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", user.Id);
|
||||||
|
|
||||||
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
StatusMessage = "Your authenticator app key has been reset, you will need to configure your authenticator app using the new key.";
|
||||||
|
|
||||||
|
return RedirectToPage("./EnableAuthenticator");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
@page
|
||||||
|
@model SetPasswordModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Set password";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.ChangePassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
<h4>Set your password</h4>
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<p class="text-info">
|
||||||
|
You do not have a local username/password for this site. Add a local
|
||||||
|
account so you can log in without an external login.
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<form id="set-password-form" method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.NewPassword"></label>
|
||||||
|
<input asp-for="Input.NewPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.NewPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.ConfirmPassword"></label>
|
||||||
|
<input asp-for="Input.ConfirmPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Set password</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class SetPasswordModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public SetPasswordModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasPassword = await _userManager.HasPasswordAsync(user);
|
||||||
|
|
||||||
|
if (hasPassword)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./ChangePassword");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var addPasswordResult = await _userManager.AddPasswordAsync(user, Input.NewPassword);
|
||||||
|
if (!addPasswordResult.Succeeded)
|
||||||
|
{
|
||||||
|
foreach (var error in addPasswordResult.Errors)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, error.Description);
|
||||||
|
}
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.RefreshSignInAsync(user);
|
||||||
|
StatusMessage = "Your password has been set.";
|
||||||
|
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Confirm new password")]
|
||||||
|
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||||
|
public string ConfirmPassword { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "New password")]
|
||||||
|
public string NewPassword { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
@page
|
||||||
|
@model ShowRecoveryCodesModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Recovery codes";
|
||||||
|
ViewData["ActivePage"] = "TwoFactorAuthentication";
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
<p>
|
||||||
|
<strong>Put these codes in a safe place.</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
If you lose your device and don't have the recovery codes you will lose access to your account.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
@for (var row = 0; row < Model.RecoveryCodes.Length; row += 2)
|
||||||
|
{
|
||||||
|
<code class="recovery-code">@Model.RecoveryCodes[row]</code><text> </text><code class="recovery-code">@Model.RecoveryCodes[row + 1]</code><br />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class ShowRecoveryCodesModel : PageModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string[] RecoveryCodes { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public IActionResult OnGet()
|
||||||
|
{
|
||||||
|
if (RecoveryCodes == null || RecoveryCodes.Length == 0)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./TwoFactorAuthentication");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
@page
|
||||||
|
@model TwoFactorAuthenticationModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Two-factor authentication (2FA)";
|
||||||
|
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
<partial name="_StatusMessage" for="StatusMessage" />
|
||||||
|
<h4>@ViewData["Title"]</h4>
|
||||||
|
@if (Model.Is2faEnabled)
|
||||||
|
{
|
||||||
|
if (Model.RecoveryCodesLeft == 0)
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<strong>You have no recovery codes left.</strong>
|
||||||
|
<p>You must <a asp-page="./GenerateRecoveryCodes">generate a new set of recovery codes</a> before you can log in with a recovery code.</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else if (Model.RecoveryCodesLeft == 1)
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<strong>You have 1 recovery code left.</strong>
|
||||||
|
<p>You can <a asp-page="./GenerateRecoveryCodes">generate a new set of recovery codes</a>.</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else if (Model.RecoveryCodesLeft <= 3)
|
||||||
|
{
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
<strong>You have @Model.RecoveryCodesLeft recovery codes left.</strong>
|
||||||
|
<p>You should <a asp-page="./GenerateRecoveryCodes">generate a new set of recovery codes</a>.</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Model.IsMachineRemembered)
|
||||||
|
{
|
||||||
|
<form method="post" style="display: inline-block">
|
||||||
|
<button type="submit" class="btn btn-warning">Forget this browser</button>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
<a asp-page="./Disable2fa" class="btn btn-danger">Disable 2FA</a>
|
||||||
|
<a asp-page="./GenerateRecoveryCodes" class="btn btn-warning">Reset recovery codes</a>
|
||||||
|
}
|
||||||
|
|
||||||
|
<h5>Authenticator app</h5>
|
||||||
|
@if (!Model.HasAuthenticator)
|
||||||
|
{
|
||||||
|
<a id="enable-authenticator" asp-page="./EnableAuthenticator" class="btn btn-primary">Add authenticator app</a>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<a id="enable-authenticator" asp-page="./EnableAuthenticator" class="btn btn-primary">Setup authenticator app</a>
|
||||||
|
<a id="reset-authenticator" asp-page="./ResetAuthenticator" class="btn btn-primary">Reset authenticator app</a>
|
||||||
|
}
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
|
{
|
||||||
|
public class TwoFactorAuthenticationModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private const string AuthenicatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}";
|
||||||
|
|
||||||
|
private readonly ILogger<TwoFactorAuthenticationModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public TwoFactorAuthenticationModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
ILogger<TwoFactorAuthenticationModel> logger)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public bool HasAuthenticator { get; set; }
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public bool Is2faEnabled { get; set; }
|
||||||
|
|
||||||
|
public bool IsMachineRemembered { get; set; }
|
||||||
|
public int RecoveryCodesLeft { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
|
public string StatusMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null;
|
||||||
|
Is2faEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
|
||||||
|
IsMachineRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user);
|
||||||
|
RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user);
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPost()
|
||||||
|
{
|
||||||
|
var user = await _userManager.GetUserAsync(User);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await _signInManager.ForgetTwoFactorClientAsync();
|
||||||
|
StatusMessage = "The current browser has been forgotten. When you login again from this browser you will be prompted for your 2fa code.";
|
||||||
|
return RedirectToPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
@{
|
||||||
|
if (ViewData.TryGetValue("ParentLayout", out var parentLayout))
|
||||||
|
{
|
||||||
|
Layout = (string)parentLayout;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Layout = "/Areas/Identity/Pages/_Layout.cshtml";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Manage your account</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4>Change your account settings</h4>
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<partial name="_ManageNav" />
|
||||||
|
</div>
|
||||||
|
<div class="col-md-9">
|
||||||
|
@RenderBody()
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@RenderSection("Scripts", required: false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
|
@{
|
||||||
|
var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
|
||||||
|
}
|
||||||
|
<ul class="nav nav-pills flex-column">
|
||||||
|
<li class="nav-item"><a class="nav-link @ManageNavPages.IndexNavClass(ViewContext)" id="profile" asp-page="./Index">Profile</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link @ManageNavPages.EmailNavClass(ViewContext)" id="email" asp-page="./Email">Email</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link @ManageNavPages.ChangePasswordNavClass(ViewContext)" id="change-password" asp-page="./ChangePassword">Password</a></li>
|
||||||
|
@if (hasExternalLogins)
|
||||||
|
{
|
||||||
|
<li id="external-logins" class="nav-item"><a id="external-login" class="nav-link @ManageNavPages.ExternalLoginsNavClass(ViewContext)" asp-page="./ExternalLogins">External logins</a></li>
|
||||||
|
}
|
||||||
|
<li class="nav-item"><a class="nav-link @ManageNavPages.TwoFactorAuthenticationNavClass(ViewContext)" id="two-factor" asp-page="./TwoFactorAuthentication">Two-factor authentication</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link @ManageNavPages.PersonalDataNavClass(ViewContext)" id="personal-data" asp-page="./PersonalData">Personal data</a></li>
|
||||||
|
</ul>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@model string
|
||||||
|
|
||||||
|
@if (!String.IsNullOrEmpty(Model))
|
||||||
|
{
|
||||||
|
var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success";
|
||||||
|
<div class="alert alert-@statusMessageClass alert-dismissible" role="alert">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
@Model
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@using GWMS.UI.Areas.Identity.Pages.Account.Manage
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
@page
|
||||||
|
@model RegisterModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Register";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form asp-route-returnUrl="@Model.ReturnUrl" method="post">
|
||||||
|
<h4>Create a new account.</h4>
|
||||||
|
<hr />
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Email"></label>
|
||||||
|
<input asp-for="Input.Email" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Password"></label>
|
||||||
|
<input asp-for="Input.Password" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Password" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.ConfirmPassword"></label>
|
||||||
|
<input asp-for="Input.ConfirmPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-md-offset-2">
|
||||||
|
<section>
|
||||||
|
<h4>Use another service to register.</h4>
|
||||||
|
<hr />
|
||||||
|
@{
|
||||||
|
if ((Model.ExternalLogins?.Count ?? 0) == 0)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
There are no external authentication services configured. See <a href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</a>
|
||||||
|
for details on setting up this ASP.NET application to support logging in via external services.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
@foreach (var provider in Model.ExternalLogins)
|
||||||
|
{
|
||||||
|
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class RegisterModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IEmailSender _emailSender;
|
||||||
|
private readonly ILogger<RegisterModel> _logger;
|
||||||
|
private readonly SignInManager<IdentityUser> _signInManager;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public RegisterModel(
|
||||||
|
UserManager<IdentityUser> userManager,
|
||||||
|
SignInManager<IdentityUser> signInManager,
|
||||||
|
ILogger<RegisterModel> logger,
|
||||||
|
IEmailSender emailSender)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_signInManager = signInManager;
|
||||||
|
_logger = logger;
|
||||||
|
_emailSender = emailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public IList<AuthenticationScheme> ExternalLogins { get; set; }
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
public string ReturnUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task OnGetAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
ReturnUrl = returnUrl;
|
||||||
|
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
||||||
|
{
|
||||||
|
returnUrl ??= Url.Content("~/");
|
||||||
|
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var user = new IdentityUser { UserName = Input.Email, Email = Input.Email };
|
||||||
|
var result = await _userManager.CreateAsync(user, Input.Password);
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("User created a new account with password.");
|
||||||
|
|
||||||
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
var callbackUrl = Url.Page(
|
||||||
|
"/Account/ConfirmEmail",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
|
||||||
|
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
||||||
|
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
||||||
|
|
||||||
|
if (_userManager.Options.SignIn.RequireConfirmedAccount)
|
||||||
|
{
|
||||||
|
return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// aggiunta ruolo UNDEF (da sistemare poi)
|
||||||
|
// https://code-maze.com/using-roles-in-blazor-webassembly-hosted-applications/
|
||||||
|
await _userManager.AddToRoleAsync(user, "Undef");
|
||||||
|
// continuo come default
|
||||||
|
await _signInManager.SignInAsync(user, isPersistent: false);
|
||||||
|
return LocalRedirect(returnUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var error in result.Errors)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, error.Description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we got this far, something failed, redisplay form
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Confirm password")]
|
||||||
|
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
||||||
|
public string ConfirmPassword { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
[Display(Name = "Email")]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Password")]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
@page
|
||||||
|
@model RegisterConfirmationModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Register confirmation";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
@{
|
||||||
|
if (@Model.DisplayConfirmAccountLink)
|
||||||
|
{
|
||||||
|
<p>
|
||||||
|
This app does not currently have a real email sender registered, see <a href="https://aka.ms/aspaccountconf">these docs</a> for how to configure a real email sender.
|
||||||
|
Normally this would be emailed: <a id="confirm-link" href="@Model.EmailConfirmationUrl">Click here to confirm your account</a>
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<p>
|
||||||
|
Please check your email to confirm your account.
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class RegisterConfirmationModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IEmailSender _sender;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public RegisterConfirmationModel(UserManager<IdentityUser> userManager, IEmailSender sender)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public bool DisplayConfirmAccountLink { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string EmailConfirmationUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGetAsync(string email, string returnUrl = null)
|
||||||
|
{
|
||||||
|
if (email == null)
|
||||||
|
{
|
||||||
|
return RedirectToPage("/Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.FindByEmailAsync(email);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return NotFound($"Unable to load user with email '{email}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Email = email;
|
||||||
|
// Once you add a real email sender, you should remove this code that lets you confirm the account
|
||||||
|
DisplayConfirmAccountLink = false;
|
||||||
|
if (DisplayConfirmAccountLink)
|
||||||
|
{
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
EmailConfirmationUrl = Url.Page(
|
||||||
|
"/Account/ConfirmEmail",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
@page
|
||||||
|
@model ResendEmailConfirmationModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Resend email confirmation";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<h4>Enter your email.</h4>
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form method="post">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Email"></label>
|
||||||
|
<input asp-for="Input.Email" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Resend</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ResendEmailConfirmationModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IEmailSender _emailSender;
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ResendEmailConfirmationModel(UserManager<IdentityUser> userManager, IEmailSender emailSender)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
_emailSender = emailSender;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.FindByEmailAsync(Input.Email);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, "Verification email sent. Please check your email.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var userId = await _userManager.GetUserIdAsync(user);
|
||||||
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
|
||||||
|
var callbackUrl = Url.Page(
|
||||||
|
"/Account/ConfirmEmail",
|
||||||
|
pageHandler: null,
|
||||||
|
values: new { userId = userId, code = code },
|
||||||
|
protocol: Request.Scheme);
|
||||||
|
await _emailSender.SendEmailAsync(
|
||||||
|
Input.Email,
|
||||||
|
"Confirm your email",
|
||||||
|
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
||||||
|
|
||||||
|
ModelState.AddModelError(string.Empty, "Verification email sent. Please check your email.");
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
@page
|
||||||
|
@model ResetPasswordModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Reset password";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<h4>Reset your password.</h4>
|
||||||
|
<hr />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form method="post">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<input asp-for="Input.Code" type="hidden" />
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Email"></label>
|
||||||
|
<input asp-for="Input.Email" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.Password"></label>
|
||||||
|
<input asp-for="Input.Password" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.Password" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Input.ConfirmPassword"></label>
|
||||||
|
<input asp-for="Input.ConfirmPassword" class="form-control" />
|
||||||
|
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Reset</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ResetPasswordModel : PageModel
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly UserManager<IdentityUser> _userManager;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public ResetPasswordModel(UserManager<IdentityUser> userManager)
|
||||||
|
{
|
||||||
|
_userManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public InputModel Input { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public IActionResult OnGet(string code = null)
|
||||||
|
{
|
||||||
|
if (code == null)
|
||||||
|
{
|
||||||
|
return BadRequest("A code must be supplied for password reset.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Input = new InputModel
|
||||||
|
{
|
||||||
|
Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code))
|
||||||
|
};
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostAsync()
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await _userManager.FindByEmailAsync(Input.Email);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
// Don't reveal that the user does not exist
|
||||||
|
return RedirectToPage("./ResetPasswordConfirmation");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);
|
||||||
|
if (result.Succeeded)
|
||||||
|
{
|
||||||
|
return RedirectToPage("./ResetPasswordConfirmation");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var error in result.Errors)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError(string.Empty, error.Description);
|
||||||
|
}
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Public Classes
|
||||||
|
|
||||||
|
public class InputModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
[Display(Name = "Confirm password")]
|
||||||
|
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
||||||
|
public string ConfirmPassword { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[EmailAddress]
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||||
|
[DataType(DataType.Password)]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Classes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@page
|
||||||
|
@model ResetPasswordConfirmationModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Reset password confirmation";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
<p>
|
||||||
|
Your password has been reset. Please <a asp-page="./Login">click here to log in</a>.
|
||||||
|
</p>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages.Account
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
public class ResetPasswordConfirmationModel : PageModel
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@model string
|
||||||
|
|
||||||
|
@if (!String.IsNullOrEmpty(Model))
|
||||||
|
{
|
||||||
|
var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success";
|
||||||
|
<div class="alert alert-@statusMessageClass alert-dismissible" role="alert">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
@Model
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@using GWMS.UI.Areas.Identity.Pages.Account
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
@page
|
||||||
|
@model ErrorModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1 class="text-danger">Error.</h1>
|
||||||
|
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||||
|
|
||||||
|
@if (Model.ShowRequestId)
|
||||||
|
{
|
||||||
|
<p>
|
||||||
|
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<h3>Development Mode</h3>
|
||||||
|
<p>
|
||||||
|
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
|
||||||
|
</p>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace GWMS.UI.Areas.Identity.Pages
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
public class ErrorModel : PageModel
|
||||||
|
{
|
||||||
|
#region Public Properties
|
||||||
|
|
||||||
|
public string RequestId { get; set; }
|
||||||
|
|
||||||
|
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||||
|
|
||||||
|
#endregion Public Properties
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
@using Microsoft.AspNetCore.Identity
|
||||||
|
@using GWMS.UI.Areas.Identity
|
||||||
|
@using GWMS.UI.Areas.Identity.Pages
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
@{
|
||||||
|
Layout = "/Pages/Shared/_Layout.cshtml";
|
||||||
|
}
|
||||||
@@ -7,14 +7,13 @@
|
|||||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||||
|
|
||||||
<div class="row pt-3">
|
<div class="row pt-3">
|
||||||
<div class="col-3">
|
<div class="col-6 col-md-5 col-lg-4 col-xl-3 px-0 text-truncate">
|
||||||
<i class="fas fa-user-alt"></i> <b>@userName</b>
|
<LoginDisplay></LoginDisplay>
|
||||||
@*<LoginDisplay />*@
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 text-center h4">
|
<div class="col-12 col-md-2 col-lg-4 col-xl-6 d-none d-lg-block text-center h4 px-1 text-truncate">
|
||||||
<span class="@PageIcon" aria-hidden="true"></span> @PageName
|
<span class="@PageIcon" aria-hidden="true"></span> @PageName
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3 text-right">
|
<div class="col-6 col-md-5 col-lg-4 col-xl-3 text-right pl-0">
|
||||||
@if (ShowSearch)
|
@if (ShowSearch)
|
||||||
{
|
{
|
||||||
<SearchMod></SearchMod>
|
<SearchMod></SearchMod>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
foreach (var item in _currList)
|
foreach (var item in _currList)
|
||||||
{
|
{
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<button class="btn btn-block btn-outline-dark" @onclick="() => Edit(item)">
|
<button class="btn btn-block btn-outline-dark px-1" @onclick="() => Edit(item)">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="px-1">
|
<div class="px-1">
|
||||||
<i class="fas fa-gas-pump" aria-hidden="true"></i> @item.Plant.PlantDesc
|
<i class="fas fa-gas-pump" aria-hidden="true"></i> @item.Plant.PlantDesc
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _currList = null;
|
return _currList;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,54 @@
|
|||||||
<AuthorizeView>
|
@using Microsoft.AspNetCore.Components.Authorization
|
||||||
|
|
||||||
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||||
|
|
||||||
|
<AuthorizeView>
|
||||||
<Authorized>
|
<Authorized>
|
||||||
<a href="Identity/Account/Manage">Hello, @context.User.Identity.Name !!!</a>
|
<div class="input-group">
|
||||||
<form method="post" action="Identity/Account/LogOut">
|
<div class="input-group-prepend">
|
||||||
<button type="submit" class="nav-link btn btn-link">Log out</button>
|
<a title="LogOut" href="Identity/Account/LogOut" class="btn btn-sm btn-danger ml-3"><i class="fas fa-sign-out-alt"></i></a>
|
||||||
</form>
|
</div>
|
||||||
|
<a title="Manage" href="Identity/Account/Manage" class="btn btn-sm btn-outline-dark mx-0 px-1">
|
||||||
|
<i class="fas fa-user-alt"></i> @userName
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
<a href="Identity/Account/Register">Register</a>
|
<div class="input-group">
|
||||||
<a href="Identity/Account/Login">Log in</a>
|
<div class="input-group-prepend">
|
||||||
|
<a title="LogIn" href="Identity/Account/LogIn" class="btn btn-sm btn-success ml-3"><i class="fas fa-sign-in-alt"></i></a>
|
||||||
|
</div>
|
||||||
|
<div class="form-control form-control-sm">
|
||||||
|
<i class="fas fa-user-alt"></i> @userName
|
||||||
|
</div>
|
||||||
|
<div class="input-group-append">
|
||||||
|
<a title="Register" href="Identity/Account/Register" class="btn btn-sm btn-primary ml-0"><i class="fas fa-edit"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</NotAuthorized>
|
</NotAuthorized>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
|
||||||
|
@code{
|
||||||
|
|
||||||
|
private string userName = "";
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await forceReload();
|
||||||
|
}
|
||||||
|
private async Task forceReload()
|
||||||
|
{
|
||||||
|
|
||||||
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
|
var user = authState.User;
|
||||||
|
|
||||||
|
if (user.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
userName = $"{user.Identity.Name}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
userName = "Non Autenticato";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -777,7 +777,7 @@ namespace GWMS.UI.Data
|
|||||||
dbResult = dbController.GetWeekPlan();
|
dbResult = dbController.GetWeekPlan();
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
TimeSpan ts = stopWatch.Elapsed;
|
TimeSpan ts = stopWatch.Elapsed;
|
||||||
Log.Info($"Effettuata lettura da DB + caching per WeekPlanGet: {ts.TotalMilliseconds} ms");
|
Log.Info($"Effettuata lettura da DB per WeekPlanGet: {ts.TotalMilliseconds} ms");
|
||||||
return await Task.FromResult(dbResult);
|
return await Task.FromResult(dbResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<Version>1.0.2108.2410</Version>
|
<Version>1.0.2108.2516</Version>
|
||||||
<UserSecretsId>95c9f021-52d1-4390-a670-5810b7b777b0</UserSecretsId>
|
<UserSecretsId>95c9f021-52d1-4390-a670-5810b7b777b0</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
@inject GWMSDataService DataService
|
@inject GWMSDataService DataService
|
||||||
@inject MessageService AppMService
|
@inject MessageService AppMService
|
||||||
|
|
||||||
|
@attribute [AllowAnonymous]
|
||||||
|
|
||||||
<div class="jumbotron py-4">
|
<div class="jumbotron py-4">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-lg-4">
|
<div class="col-12 col-lg-4">
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
@using Microsoft.AspNetCore.Hosting
|
||||||
|
@using Microsoft.AspNetCore.Mvc.ViewEngines
|
||||||
|
|
||||||
|
@using GWMS.UI.Components
|
||||||
|
|
||||||
|
@inject IWebHostEnvironment Environment
|
||||||
|
@inject ICompositeViewEngine Engine
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
|
@*<meta name="viewport" content="width=device-width, initial-scale=1.0" />*@
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
|
<title>GWMS User Management</title>
|
||||||
|
<base href="~/" />
|
||||||
|
<link rel="stylesheet" href="~/Identity/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||||
|
<link rel="stylesheet" href="~/Identity/css/site.css" />
|
||||||
|
<link rel="stylesheet" href="~/css/site.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="navbar navbar-expand-sm bg-dark navbar-dark navbar-toggleable-sm border-bottom box-shadow py-0 my-0 fixed-top">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="~/"><img src="./img/LogoBlu.svg" class="img-fluid" width="32" /> MAPO.GWMS</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||||
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||||
|
@{
|
||||||
|
var result = Engine.FindView(ViewContext, "_LoginPartial", isMainPage: false);
|
||||||
|
}
|
||||||
|
@if (result.Success)
|
||||||
|
{
|
||||||
|
await Html.RenderPartialAsync("_LoginPartial");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("The default Identity UI layout requires a partial view '_LoginPartial' " +
|
||||||
|
"usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration " +
|
||||||
|
$"we have looked at it in the following locations: {System.Environment.NewLine}{string.Join(System.Environment.NewLine, result.SearchedLocations)}.");
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<main role="main" class="pb-3">
|
||||||
|
@RenderBody()
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
<footer class="footer border-top text-muted fixed-bottom bottom-row bg-dark py-0 my-0">
|
||||||
|
<div class="container py-1">
|
||||||
|
© 2021 - GWMS User Management- <a asp-area="" asp-page="Privacy">Privacy</a>
|
||||||
|
</div>
|
||||||
|
<CmpFooter></CmpFooter>
|
||||||
|
</footer>
|
||||||
|
<script src="~/Identity/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
<script src="~/Identity/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="~/Identity/js/site.js" asp-append-version="true"></script>
|
||||||
|
@RenderSection("Scripts", required: false)
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
@using Microsoft.AspNetCore.Identity
|
||||||
|
|
||||||
|
@inject SignInManager<IdentityUser> SignInManager
|
||||||
|
@inject UserManager<IdentityUser> UserManager
|
||||||
|
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
@if (SignInManager.IsSignedIn(User))
|
||||||
|
{
|
||||||
|
<li class="nav-item">
|
||||||
|
<a id="manage" class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @UserManager.GetUserName(User)!</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<form id="logoutForm" class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Page("/Index", new { area = "" })">
|
||||||
|
<button id="logout" type="submit" class="nav-link btn btn-link text-dark">Logout</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" id="register" asp-area="Identity" asp-page="/Account/Register">Register</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" id="login" asp-area="Identity" asp-page="/Account/Login">Login</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<environment include="Development">
|
||||||
|
<script src="~/Identity/lib/jquery-validation/dist/jquery.validate.js"></script>
|
||||||
|
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
||||||
|
</environment>
|
||||||
|
<environment exclude="Development">
|
||||||
|
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.17.0/jquery.validate.min.js"
|
||||||
|
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
|
||||||
|
asp-fallback-test="window.jQuery && window.jQuery.validator"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
integrity="sha384-rZfj/ogBloos6wzLGpPkkOr/gpkBNLZ6b6yLy4o+ok+t/SAKlL5mvXLr0OXNi1Hp">
|
||||||
|
</script>
|
||||||
|
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.9/jquery.validate.unobtrusive.min.js"
|
||||||
|
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
|
||||||
|
asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
integrity="sha384-ifv0TYDWxBHzvAk2Z0n8R434FL1Rlv/Av18DXE43N/1rvHyOG4izKst0f2iSLdds">
|
||||||
|
</script>
|
||||||
|
</environment>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user