Skip to content

Commit cb6fa79

Browse files
committedMar 31, 2020
netcore build error cleanup & better db table initialization
1 parent c6e7a1b commit cb6fa79

9 files changed

+16
-66
lines changed
 

‎Controllers/AuthController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,21 @@ public IActionResult Error()
153153
}
154154

155155
[HttpGet]
156-
public async Task<IActionResult> Google()
156+
public IActionResult Google()
157157
{
158158
string googleUrl = $"https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=https://{this.Request.Host}/Auth/GoogleCallback&scope=email+profile+openid&client_id={_oauthConfig.Value.Google.client_id}";
159159
return Redirect(googleUrl);
160160
}
161161

162162
[HttpGet]
163-
public async Task<IActionResult> Github()
163+
public IActionResult Github()
164164
{
165165
string GithubUrl = $"https://github.com/login/oauth/authorize?scope=user&client_id={_oauthConfig.Value.Github.client_id}";
166166
return Redirect(GithubUrl);
167167
}
168168

169169
[HttpGet]
170-
public async Task<IActionResult> Reddit()
170+
public IActionResult Reddit()
171171
{
172172
string RedditUrl = $"https://www.reddit.com/api/v1/authorize?scope=identity&client_id={_oauthConfig.Value.Reddit.client_id}&response_type=code&state={Guid.NewGuid().ToString()}&redirect_uri=https://{this.Request.Host}/Auth/RedditCallback&duration=temporary";
173173
return Redirect(RedditUrl);

‎Controllers/HomeController.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Dynamic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
7-
using Microsoft.AspNetCore.Http;
1+
using Microsoft.AspNetCore.Http;
82
using Microsoft.AspNetCore.Mvc;
93
using Microsoft.Extensions.Logging;
104
using netcore_postgres_oauth_boiler.Models;
5+
using System;
6+
using System.Diagnostics;
117

128
namespace netcore_postgres_oauth_boiler.Controllers
139
{

‎Models/DatabaseContext.cs

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
using Microsoft.EntityFrameworkCore;
22
using System;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using BCrypt;
74
using System.ComponentModel.DataAnnotations.Schema;
8-
using Microsoft.EntityFrameworkCore.Infrastructure;
9-
using Microsoft.EntityFrameworkCore.Storage;
105

116
namespace netcore_postgres_oauth_boiler.Models
127
{
@@ -15,19 +10,9 @@ public class DatabaseContext : DbContext
1510
public DatabaseContext(DbContextOptions<DatabaseContext> options)
1611
: base(options)
1712
{
18-
19-
try
20-
{
21-
var databaseCreator = (Database.GetService<IDatabaseCreator>() as RelationalDatabaseCreator);
22-
databaseCreator.CreateTables();
23-
}
24-
catch (Exception e)
25-
{
26-
// Ignoring exception if tables already exist.
27-
}
13+
this.Database.EnsureCreated();
2814
}
2915

30-
3116
public DbSet<User> Users { get; set; }
3217
public DbSet<Credential> Credentials { get; set; }
3318
}

‎Models/SampleDataModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
52

63
namespace netcore_postgres_oauth_boiler.Models
74
{

‎Program.cs

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
51
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.Extensions.Configuration;
72
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
93

104
namespace netcore_postgres_oauth_boiler
115
{

‎Startup.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
41
using Microsoft.AspNetCore.Builder;
52
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.HttpOverrides;
64
using Microsoft.EntityFrameworkCore;
75
using Microsoft.Extensions.Configuration;
86
using Microsoft.Extensions.DependencyInjection;
97
using Microsoft.Extensions.Hosting;
108
using netcore_postgres_oauth_boiler.Models;
11-
using Microsoft.AspNetCore.HttpOverrides;
12-
using System.Net;
139
using netcore_postgres_oauth_boiler.Models.Config;
10+
using System;
1411

1512
namespace netcore_postgres_oauth_boiler
1613
{

‎Utilities/Request.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Newtonsoft.Json;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
93
using System.Net.Http;
104
using System.Text;
115
using System.Threading.Tasks;

‎readme.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
# netcore-postgres-oauth-boiler
22

3-
A basic .NET Core website boilerplate using PostgreSQL for storage, adminer for db management, and Nginx for SSL certificates & routing.
3+
A basic .NET Core website boilerplate using PostgreSQL for storage, adminer for db management, Let's Encrypt for SSL certificates and Nginx for routing.
44

55
[Demo website.](https://netcore.demos.matasr.com)
66

77
## Features
88

99
- Vanilla .NET Core Server Setup:
10-
11-
- Razor pages for templating
10+
- Razor pages, upholstered with the Materialize css toolkit
1211
- Server -> client data rendering demo
1312
- Native Entity Framework database interface
1413
- Asynchronous design
1514
- Auth gated route examples
16-
1715
- User authentication via:
18-
1916
- Regular email/password
2017
- Google
2118
- Github
2219
- Reddit
23-
2420
- Auth method merging, linking and unlinking of social auth accounts
2521
- TLS/HTTPS:
2622
- Automatic certificate generation powered by Let's Encrypt
@@ -56,9 +52,9 @@ For an explanation of the docker-compose file separation, take a look at [Runnin
5652

5753
- Through Visual Studio:
5854

59-
1. Launch Visual Studio
60-
2. Right-click on the `docker-compose` section in the Solution Explorer, and click `Set as Startup Project`
61-
3. Select either Debug or Release at the top and click the `Docker Compose` button to run.
55+
1. Launch Visual Studio
56+
2. Right-click on the `docker-compose` section in the Solution Explorer, and click `Set as Startup Project`
57+
3. Select either Debug or Release at the top and click the `Docker Compose` button to run.
6258

6359
### Running the boilerplate independently
6460

‎run.sh

-9
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.