aboutsummaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2020-08-02 00:04:06 +0200
committerivarlovlie <git@ivarlovlie.no>2020-08-02 00:04:06 +0200
commitc7d72be2d1eed9b7fbfe719752ff800653d8c089 (patch)
tree6c92e3e434bb49efc84a84c3c170a560728df93e /src/server
parentf055808ca22d3df5e5984a1e27ef6aa49bcc5b9b (diff)
downloaddough-c7d72be2d1eed9b7fbfe719752ff800653d8c089.tar.xz
dough-c7d72be2d1eed9b7fbfe719752ff800653d8c089.zip
change db, set cookie
Diffstat (limited to 'src/server')
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/.gitignore13
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/.idea.Dough.dir.iml8
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/.name1
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/encodings.xml4
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/indexLayout.xml8
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/misc.xml6
-rw-r--r--src/server/.idea/.idea.Dough.dir/.idea/vcs.xml6
-rw-r--r--src/server/.idea/.idea.Dough.dir/riderModule.iml7
-rw-r--r--src/server/Controllers/AccountController.cs16
-rw-r--r--src/server/Controllers/BaseController.cs1
-rw-r--r--src/server/Dough.csproj30
-rw-r--r--src/server/Migrations/20200801205356_INITIAL_MIGRATION.Designer.cs (renamed from src/server/Migrations/20200729090558_Initial.Designer.cs)75
-rw-r--r--src/server/Migrations/20200801205356_INITIAL_MIGRATION.cs (renamed from src/server/Migrations/20200729090558_Initial.cs)4
-rw-r--r--src/server/Migrations/MainDbContextModelSnapshot.cs71
-rw-r--r--src/server/Models/Constants.cs7
-rw-r--r--src/server/Models/DbSetOverrides.cs5
-rw-r--r--src/server/Models/Payloads/LoginPayload.cs8
-rw-r--r--src/server/Startup.cs25
18 files changed, 192 insertions, 103 deletions
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/.gitignore b/src/server/.idea/.idea.Dough.dir/.idea/.gitignore
new file mode 100644
index 0000000..f810591
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/contentModel.xml
+/modules.xml
+/projectSettingsUpdater.xml
+/.idea.Dough.iml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/.idea.Dough.dir.iml b/src/server/.idea/.idea.Dough.dir/.idea/.idea.Dough.dir.iml
new file mode 100644
index 0000000..e6bc2ca
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/.idea.Dough.dir.iml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="RIDER_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$" />
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module> \ No newline at end of file
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/.name b/src/server/.idea/.idea.Dough.dir/.idea/.name
new file mode 100644
index 0000000..4b5d0cd
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/.name
@@ -0,0 +1 @@
+Dough \ No newline at end of file
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/encodings.xml b/src/server/.idea/.idea.Dough.dir/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/encodings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
+</project> \ No newline at end of file
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/indexLayout.xml b/src/server/.idea/.idea.Dough.dir/.idea/indexLayout.xml
new file mode 100644
index 0000000..27ba142
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ContentModelUserStore">
+ <attachedFolders />
+ <explicitIncludes />
+ <explicitExcludes />
+ </component>
+</project> \ No newline at end of file
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/misc.xml b/src/server/.idea/.idea.Dough.dir/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="JavaScriptSettings">
+ <option name="languageLevel" value="ES6" />
+ </component>
+</project> \ No newline at end of file
diff --git a/src/server/.idea/.idea.Dough.dir/.idea/vcs.xml b/src/server/.idea/.idea.Dough.dir/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
+ </component>
+</project> \ No newline at end of file
diff --git a/src/server/.idea/.idea.Dough.dir/riderModule.iml b/src/server/.idea/.idea.Dough.dir/riderModule.iml
new file mode 100644
index 0000000..1a4e0d9
--- /dev/null
+++ b/src/server/.idea/.idea.Dough.dir/riderModule.iml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="RIDER_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$/../.." />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module> \ No newline at end of file
diff --git a/src/server/Controllers/AccountController.cs b/src/server/Controllers/AccountController.cs
index 58bb7b6..ee87a68 100644
--- a/src/server/Controllers/AccountController.cs
+++ b/src/server/Controllers/AccountController.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Dough.Models;
using Dough.Models.Database;
+using Dough.Models.Payloads;
using Dough.Models.Results;
using Dough.Utilities;
@@ -23,24 +24,25 @@ namespace Dough.Controllers
}
[HttpPost("login")]
- public async Task<ActionResult> Login(string username, string password)
+ public async Task<ActionResult> Login(LoginPayload payload)
{
- var user = _context.Users.SingleByNameOrDefault(username);
+ var user = _context.Users.SingleByNameOrDefault(payload.Username);
if (user == default)
return BadRequest(new ErrorResult("Ugyldig brukernavn eller passord",
"Verifiser at passord og brukernavn er riktig og prøv igjen"));
- if (!user.VerifyPassword(password))
+ if (!user.VerifyPassword(payload.Password))
return BadRequest(new ErrorResult("Ugyldig brukernavn eller passord",
"Verifiser at passord og brukernavn er riktig"));
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, user.Username),
- new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
+ new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
+ new Claim(ClaimTypes.AuthenticationInstant, DateTime.UtcNow.ToString("O"))
};
- var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
+ var claimsIdentity = new ClaimsIdentity(claims, Constants.AuthenticationScheme);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
var authenticationProperties = new AuthenticationProperties
@@ -51,7 +53,7 @@ namespace Dough.Controllers
ExpiresUtc = DateTime.UtcNow.AddDays(7),
};
- await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
+ await HttpContext.SignInAsync(Constants.AuthenticationScheme,
claimsPrincipal,
authenticationProperties);
@@ -61,7 +63,7 @@ namespace Dough.Controllers
[HttpGet("logout")]
public async Task<ActionResult> Logout(string continueTo = default)
{
- await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
+ await HttpContext.SignOutAsync(Constants.AuthenticationScheme);
if (continueTo.IsPresent() && continueTo.IsValidUrl()) return Redirect(continueTo);
return Ok();
}
diff --git a/src/server/Controllers/BaseController.cs b/src/server/Controllers/BaseController.cs
index 33f1e4b..046c060 100644
--- a/src/server/Controllers/BaseController.cs
+++ b/src/server/Controllers/BaseController.cs
@@ -1,7 +1,6 @@
using System;
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
-using Dough.Models.Database;
using Dough.Utilities;
namespace Dough.Controllers
diff --git a/src/server/Dough.csproj b/src/server/Dough.csproj
index ae3d56a..65911ed 100644
--- a/src/server/Dough.csproj
+++ b/src/server/Dough.csproj
@@ -1,16 +1,14 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
-
- <PropertyGroup>
- <TargetFramework>netcoreapp3.1</TargetFramework>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="BCrypt.Net-Core" Version="1.6.0" />
- <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
- <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.6" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.6" />
- </ItemGroup>
-
-
-</Project>
+<?xml version="1.0" encoding="utf-8"?>
+<Project Sdk="Microsoft.NET.Sdk.Web">
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+ <UserSecretsId>f009efdc-3998-4ef3-8617-b0a501f192cb</UserSecretsId>
+ </PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="BCrypt.Net-Core" Version="1.6.0" />
+ <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.2" />
+ <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.6" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/src/server/Migrations/20200729090558_Initial.Designer.cs b/src/server/Migrations/20200801205356_INITIAL_MIGRATION.Designer.cs
index 9657f66..b693783 100644
--- a/src/server/Migrations/20200729090558_Initial.Designer.cs
+++ b/src/server/Migrations/20200801205356_INITIAL_MIGRATION.Designer.cs
@@ -1,127 +1,128 @@
// <auto-generated />
using System;
+using Dough.Models.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Dough.Models.Database;
namespace Dough.Migrations
{
[DbContext(typeof(MainDbContext))]
- [Migration("20200729090558_Initial")]
- partial class Initial
+ [Migration("20200801205356_INITIAL_MIGRATION")]
+ partial class INITIAL_MIGRATION
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "3.1.6");
+ .HasAnnotation("ProductVersion", "3.1.6")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
- modelBuilder.Entity("MoneyManager.Models.Database.Category", b =>
+ modelBuilder.Entity("Dough.Models.Database.Category", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Name")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.ToTable("Categories");
});
- modelBuilder.Entity("MoneyManager.Models.Database.Payee", b =>
+ modelBuilder.Entity("Dough.Models.Database.Payee", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Name")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.ToTable("Payees");
});
- modelBuilder.Entity("MoneyManager.Models.Database.Transaction", b =>
+ modelBuilder.Entity("Dough.Models.Database.Transaction", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<double>("Amount")
- .HasColumnType("REAL");
+ .HasColumnType("double");
b.Property<Guid>("CategoryId")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Date")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Note")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid>("PayeeId")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<string>("Tags")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.ToTable("Transactions");
});
- modelBuilder.Entity("MoneyManager.Models.Database.User", b =>
+ modelBuilder.Entity("Dough.Models.Database.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Password")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Username")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
@@ -130,10 +131,10 @@ namespace Dough.Migrations
b.HasData(
new
{
- Id = new Guid("193053d0-4292-4dc5-baae-59a920b64891"),
- Created = new DateTime(2020, 7, 29, 9, 5, 57, 914, DateTimeKind.Utc).AddTicks(3427),
+ Id = new Guid("4fb39ecf-9619-42be-8852-81c48a9a9f72"),
+ Created = new DateTime(2020, 8, 1, 20, 53, 56, 576, DateTimeKind.Utc).AddTicks(931),
Hidden = false,
- Password = "$2b$10$RFdcYLeqporq94pUIOoJGOPnhUbpV7R4e.2Iz8ot02N2PqeCpDCA6",
+ Password = "$2b$10$v7e7AJc0atQvyvvwkvXAnuin0m75qRZSxcSAHdDiKcSHuByJpc0zy",
Username = "ivar"
});
});
diff --git a/src/server/Migrations/20200729090558_Initial.cs b/src/server/Migrations/20200801205356_INITIAL_MIGRATION.cs
index 5dc0b40..f6495ae 100644
--- a/src/server/Migrations/20200729090558_Initial.cs
+++ b/src/server/Migrations/20200801205356_INITIAL_MIGRATION.cs
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Dough.Migrations
{
- public partial class Initial : Migration
+ public partial class INITIAL_MIGRATION : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@@ -76,7 +76,7 @@ namespace Dough.Migrations
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "Created", "CreatedBy", "Hidden", "Password", "Username" },
- values: new object[] { new Guid("193053d0-4292-4dc5-baae-59a920b64891"), new DateTime(2020, 7, 29, 9, 5, 57, 914, DateTimeKind.Utc).AddTicks(3427), null, false, "$2b$10$RFdcYLeqporq94pUIOoJGOPnhUbpV7R4e.2Iz8ot02N2PqeCpDCA6", "ivar" });
+ values: new object[] { new Guid("4fb39ecf-9619-42be-8852-81c48a9a9f72"), new DateTime(2020, 8, 1, 20, 53, 56, 576, DateTimeKind.Utc).AddTicks(931), null, false, "$2b$10$v7e7AJc0atQvyvvwkvXAnuin0m75qRZSxcSAHdDiKcSHuByJpc0zy", "ivar" });
}
protected override void Down(MigrationBuilder migrationBuilder)
diff --git a/src/server/Migrations/MainDbContextModelSnapshot.cs b/src/server/Migrations/MainDbContextModelSnapshot.cs
index ad883c5..d4c6e7e 100644
--- a/src/server/Migrations/MainDbContextModelSnapshot.cs
+++ b/src/server/Migrations/MainDbContextModelSnapshot.cs
@@ -1,9 +1,9 @@
// <auto-generated />
using System;
+using Dough.Models.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Dough.Models.Database;
namespace Dough.Migrations
{
@@ -14,112 +14,113 @@ namespace Dough.Migrations
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "3.1.6");
+ .HasAnnotation("ProductVersion", "3.1.6")
+ .HasAnnotation("Relational:MaxIdentifierLength", 64);
- modelBuilder.Entity("MoneyManager.Models.Database.Category", b =>
+ modelBuilder.Entity("Dough.Models.Database.Category", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Name")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.ToTable("Categories");
});
- modelBuilder.Entity("MoneyManager.Models.Database.Payee", b =>
+ modelBuilder.Entity("Dough.Models.Database.Payee", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Name")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.ToTable("Payees");
});
- modelBuilder.Entity("MoneyManager.Models.Database.Transaction", b =>
+ modelBuilder.Entity("Dough.Models.Database.Transaction", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<double>("Amount")
- .HasColumnType("REAL");
+ .HasColumnType("double");
b.Property<Guid>("CategoryId")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Date")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Note")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid>("PayeeId")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<string>("Tags")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.ToTable("Transactions");
});
- modelBuilder.Entity("MoneyManager.Models.Database.User", b =>
+ modelBuilder.Entity("Dough.Models.Database.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<DateTime>("Created")
- .HasColumnType("TEXT");
+ .HasColumnType("datetime(6)");
b.Property<Guid?>("CreatedBy")
- .HasColumnType("TEXT");
+ .HasColumnType("char(36)");
b.Property<bool>("Hidden")
- .HasColumnType("INTEGER");
+ .HasColumnType("tinyint(1)");
b.Property<string>("Password")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Username")
- .HasColumnType("TEXT");
+ .HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
@@ -128,10 +129,10 @@ namespace Dough.Migrations
b.HasData(
new
{
- Id = new Guid("193053d0-4292-4dc5-baae-59a920b64891"),
- Created = new DateTime(2020, 7, 29, 9, 5, 57, 914, DateTimeKind.Utc).AddTicks(3427),
+ Id = new Guid("4fb39ecf-9619-42be-8852-81c48a9a9f72"),
+ Created = new DateTime(2020, 8, 1, 20, 53, 56, 576, DateTimeKind.Utc).AddTicks(931),
Hidden = false,
- Password = "$2b$10$RFdcYLeqporq94pUIOoJGOPnhUbpV7R4e.2Iz8ot02N2PqeCpDCA6",
+ Password = "$2b$10$v7e7AJc0atQvyvvwkvXAnuin0m75qRZSxcSAHdDiKcSHuByJpc0zy",
Username = "ivar"
});
});
diff --git a/src/server/Models/Constants.cs b/src/server/Models/Constants.cs
new file mode 100644
index 0000000..759030a
--- /dev/null
+++ b/src/server/Models/Constants.cs
@@ -0,0 +1,7 @@
+namespace Dough.Models
+{
+ public class Constants
+ {
+ public const string AuthenticationScheme = "Cookies";
+ }
+} \ No newline at end of file
diff --git a/src/server/Models/DbSetOverrides.cs b/src/server/Models/DbSetOverrides.cs
index 24622bc..fbab76d 100644
--- a/src/server/Models/DbSetOverrides.cs
+++ b/src/server/Models/DbSetOverrides.cs
@@ -18,8 +18,9 @@ namespace Dough.Models
public static User SingleByNameOrDefault(this DbSet<User> users, string username, bool includeHidden = false)
{
if (includeHidden)
- return users.SingleOrDefault(c => c.Username == username);
- return users.SingleOrDefault(c => c.Username == username && !c.Hidden);
+ return users.SingleOrDefault(c => string.Equals(c.Username, username, StringComparison.InvariantCultureIgnoreCase));
+ return users.SingleOrDefault(c => string.Equals(c.Username, username, StringComparison.InvariantCultureIgnoreCase)
+ && !c.Hidden);
}
}
}
diff --git a/src/server/Models/Payloads/LoginPayload.cs b/src/server/Models/Payloads/LoginPayload.cs
new file mode 100644
index 0000000..d7bc50b
--- /dev/null
+++ b/src/server/Models/Payloads/LoginPayload.cs
@@ -0,0 +1,8 @@
+namespace Dough.Models.Payloads
+{
+ public class LoginPayload
+ {
+ public string Username { get; set; }
+ public string Password { get; set; }
+ }
+} \ No newline at end of file
diff --git a/src/server/Startup.cs b/src/server/Startup.cs
index ad98370..7c7adf0 100644
--- a/src/server/Startup.cs
+++ b/src/server/Startup.cs
@@ -8,6 +8,8 @@ using Microsoft.Extensions.Hosting;
using Dough.Models;
using Dough.Utilities;
using Dough.Models.Database;
+using Microsoft.AspNetCore.CookiePolicy;
+using Microsoft.AspNetCore.Http;
namespace Dough
{
@@ -21,6 +23,16 @@ namespace Dough
public IConfiguration Configuration { get; }
private const string MainCorsPolicy = "MainCorsPolicy";
+ private string GetConnectionStringFromEnvironment()
+ {
+ var host = Configuration.GetValue<string>("DB_HOST");
+ var port = Configuration.GetValue("DB_PORT", "3306");
+ var user = Configuration.GetValue<string>("DB_USER");
+ var password = Configuration.GetValue<string>("DB_PASSWORD");
+ var name = Configuration.GetValue<string>("DB_NAME");
+ return $"Server={host},{port};Database={name};User={user};Password={password}";
+ }
+
public void ConfigureServices(IServiceCollection services)
{
@@ -37,14 +49,21 @@ namespace Dough
});
services.AddDbContext<MainDbContext>(options => {
- options.UseSqlite("Data Source=database.sqlite");
+ options.UseMySql(GetConnectionStringFromEnvironment(), settings =>
+ {
+ settings.EnableRetryOnFailure(3);
+ });
});
services.AddControllers();
- services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
- .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
+ services.AddAuthentication(Constants.AuthenticationScheme)
+ .AddCookie(Constants.AuthenticationScheme, options =>
{
+ options.Cookie.Name = "dough_session";
+ options.Cookie.HttpOnly = true;
+ options.Cookie.SameSite = SameSiteMode.Strict;
+ options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.LoginPath = "/api/account/login";
options.SlidingExpiration = true;
options.LogoutPath = "/api/account/logout";