Started to create authorization portion pt.2

This commit is contained in:
2019-05-05 18:37:22 -05:00
parent 2fc646ff8b
commit 23e518d225
34 changed files with 435 additions and 27 deletions

View File

@@ -9,12 +9,5 @@
},
"ConnectionStrings": {
"DefaultConnection": "Filename=../BrightGlimmer.Data/bright_glimmer.db"
},
"amqp": {
"username": "guest",
"password": "guest",
"hostname": "localhost",
"uri": "amqp://localhost:5672/",
"virtualhost": "/"
}
}

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BrightGlimmer.Data\BrightGlimmer.Data.csproj" />
<ProjectReference Include="..\BrightGlimmer.Domain\BrightGlimmer.Domain.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace BrightGlimmer.Auth.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace BrightGlimmer.Auth
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}

View File

@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53671",
"sslPort": 44369
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BrightGlimmer.Auth": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BrightGlimmer.Data;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace BrightGlimmer.Auth
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
/* Configure EF Core DbContext */
services.AddDbContext<AuthContext>(options => options.UseLazyLoadingProxies()
.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<AuthContext, AuthContext>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
// Makes sure that the database is in fact created
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<AuthContext>();
context.Database.EnsureCreated();
}
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

View File

@@ -0,0 +1,13 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Filename=../BrightGlimmer.Data/bright_glimmer_auth.db"
}
}

View File

@@ -0,0 +1,25 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain.Auth;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
namespace BrightGlimmer.Data
{
public class AuthContext : DbContext, IUnitOfWork
{
public AuthContext(DbContextOptions<AuthContext> options)
: base(options)
{
}
// dotnet ef migrations add NAME --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Auth --context AuthContext
// dotnet ef database update --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Auth --context AuthContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
public DbSet<User> Users { get; set; }
}
}

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
@@ -15,9 +15,8 @@ namespace BrightGlimmer.Data
{
}
// dotnet ef migrations add NAME --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api
// dotnet ef database update --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api
// dotnet ef migrations add NAME --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api --context BgContext
// dotnet ef database update --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api --context BgContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>(entity =>

View File

@@ -0,0 +1,57 @@
// <auto-generated />
using System;
using BrightGlimmer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations.Auth
{
[DbContext(typeof(AuthContext))]
[Migration("20190505233325_Create-Database")]
partial class CreateDatabase
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("BrightGlimmer.Domain.Auth.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<bool>("AccountLocked");
b.Property<DateTime>("CreatedDate");
b.Property<string>("Email");
b.Property<bool>("EmailConfirmed");
b.Property<string>("FirstName");
b.Property<bool>("IsDeleted");
b.Property<string>("LastName");
b.Property<string>("MiddleName");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("PasswordHash");
b.Property<int>("RetryAttempts");
b.Property<string>("Username");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace BrightGlimmer.Data.Migrations.Auth
{
public partial class CreateDatabase : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
ModifiedDate = table.Column<DateTime>(nullable: false),
Username = table.Column<string>(nullable: true),
Email = table.Column<string>(nullable: true),
FirstName = table.Column<string>(nullable: true),
MiddleName = table.Column<string>(nullable: true),
LastName = table.Column<string>(nullable: true),
PasswordHash = table.Column<string>(nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
AccountLocked = table.Column<bool>(nullable: false),
RetryAttempts = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@@ -0,0 +1,55 @@
// <auto-generated />
using System;
using BrightGlimmer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations.Auth
{
[DbContext(typeof(AuthContext))]
partial class AuthContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("BrightGlimmer.Domain.Auth.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<bool>("AccountLocked");
b.Property<DateTime>("CreatedDate");
b.Property<string>("Email");
b.Property<bool>("EmailConfirmed");
b.Property<string>("FirstName");
b.Property<bool>("IsDeleted");
b.Property<string>("LastName");
b.Property<string>("MiddleName");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("PasswordHash");
b.Property<int>("RetryAttempts");
b.Property<string>("Username");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BrightGlimmer.Data.Services
{
public class UserService
{
}
}

Binary file not shown.

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BrightGlimmer.Domain.Auth
{
public class User : Entity
{
public string Username { get; private set; }
public string Email { get; private set; }
public string FirstName { get; private set; }
public string MiddleName { get; private set; }
public string LastName { get; private set; }
public string PasswordHash { get; private set; }
public bool EmailConfirmed { get; private set; }
public bool AccountLocked { get; private set; }
public int RetryAttempts { get; private set; }
}
}

View File

@@ -29,6 +29,7 @@ namespace BrightGlimmer.Domain
IsDeleted = true;
}
/* TODO: Currently not working when entities modified */
protected void MarkModified()
{
ModifiedDate = DateTime.UtcNow;

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BrightGlimmer.Domain
namespace BrightGlimmer.Domain.Service
{
[Table("Addresses")]
public class Address : Entity

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BrightGlimmer.Domain
namespace BrightGlimmer.Domain.Service
{
[Table("AssignedCourses")]
public class AssignedCourse : Entity

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BrightGlimmer.Domain
namespace BrightGlimmer.Domain.Service
{
[Table("Courses")]
public class Course : Entity

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace BrightGlimmer.Domain
namespace BrightGlimmer.Domain.Service
{
[Table("Phones")]
public class Phone : Entity

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
namespace BrightGlimmer.Domain
namespace BrightGlimmer.Domain.Service
{
public enum PhoneType
{

View File

@@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
namespace BrightGlimmer.Domain
namespace BrightGlimmer.Domain.Service
{
[Table("Students")]
public class Student : Entity

View File

@@ -1,4 +1,4 @@
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using MediatR;
using System.Collections.Generic;

View File

@@ -1,4 +1,4 @@
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using MediatR;
using System;
using System.Collections.Generic;

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using BrightGlimmer.Service.Commands;
using MediatR;
using System.Threading;

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using BrightGlimmer.Service.Commands;
using MediatR;
using System;

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using BrightGlimmer.Service.Commands;
using MediatR;
using System;

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using BrightGlimmer.Service.Queries;
using MediatR;
using System.Threading;

View File

@@ -1,5 +1,5 @@
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using BrightGlimmer.Service.Queries;
using MediatR;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,4 +1,4 @@
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using MediatR;
using System;

View File

@@ -1,4 +1,4 @@
using BrightGlimmer.Domain;
using BrightGlimmer.Domain.Service;
using MediatR;
using System.Collections.Generic;

View File

@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrightGlimmer.Service", "Br
EndProject
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "BrightGlimmer.Client", "BrightGlimmer.Client\BrightGlimmer.Client.njsproj", "{6971AB72-FBC2-4F3F-A59C-319E377A9A51}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrightGlimmer.Auth", "BrightGlimmer.Auth\BrightGlimmer.Auth.csproj", "{E3265892-2D6C-4D51-A7A4-DF845C17CF49}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
{6971AB72-FBC2-4F3F-A59C-319E377A9A51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6971AB72-FBC2-4F3F-A59C-319E377A9A51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6971AB72-FBC2-4F3F-A59C-319E377A9A51}.Release|Any CPU.Build.0 = Release|Any CPU
{E3265892-2D6C-4D51-A7A4-DF845C17CF49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3265892-2D6C-4D51-A7A4-DF845C17CF49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3265892-2D6C-4D51-A7A4-DF845C17CF49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3265892-2D6C-4D51-A7A4-DF845C17CF49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE