From 9404412a5336a3161da7591eec392683154d93b7 Mon Sep 17 00:00:00 2001 From: whizzywig Date: Thu, 27 Feb 2020 20:11:03 +0000 Subject: [PATCH 1/9] Added content and changed links to controller --- Views/Shared/_Layout.cshtml | 8 +++++--- wwwroot/css/site.css | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 1fb25bb..494fa04 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -6,14 +6,16 @@ @ViewData["Title"] - SM - +
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 8748128..c83b63b 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -1,6 +1,6 @@ body { font-family: 'Fira Code', monospace; - background-color: #222; + background-color: #222 !important; } main { @@ -47,4 +47,4 @@ footer { border-top-width: 1px; border-top-color: #fff; /* line-height: 1rem; */ -} \ No newline at end of file +} -- GitLab From e082594dc4961afd98602b33b3ddf57ce90dac88 Mon Sep 17 00:00:00 2001 From: whizzywig Date: Fri, 28 Feb 2020 11:08:04 +0000 Subject: [PATCH 2/9] Fixed the navbar not being interactable --- Views/Shared/_Layout.cshtml | 9 ++++---- wwwroot/css/site.css | 42 ++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 494fa04..7ff1d59 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -9,16 +9,17 @@ - -
+ +
@RenderBody()
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index c83b63b..541484b 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -1,33 +1,16 @@ -body { - font-family: 'Fira Code', monospace; - background-color: #222 !important; -} - -main { - margin: auto; - width: 70%; - padding: 5rem; -} - -.content { - margin-top: 8rem; - border-style: solid; - border-width: 1px; - border-color: #fff; -} - .navbar { overflow: hidden; position: fixed; top: 0; width: 100%; + height: 5rem; } .navbar a { float: left; display: block; text-align: center; - padding: 2rem 2rem; + padding: 1rem 2rem; text-decoration: none; color: #fff; } @@ -37,6 +20,27 @@ main { color: black; } +.content { + /* uses top to put it under the navbar*/ + top: 5rem; + border-style: none; +} + +html { + position: relative; + min-height: 100%; +} +body { + font-family: 'Fira Code', monospace; + background-color: #222 !important; +} + +main { + margin: auto; + width: 70%; + padding: 5rem; +} + footer { position: fixed; left: 0; -- GitLab From e61f33d68253c9a53de3adc2d6097173e4b0df97 Mon Sep 17 00:00:00 2001 From: whizzywig Date: Thu, 27 Feb 2020 20:11:03 +0000 Subject: [PATCH 3/9] Added content and changed links to controller --- Views/Shared/_Layout.cshtml | 8 +++++--- wwwroot/css/site.css | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 1fb25bb..494fa04 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -6,14 +6,16 @@ @ViewData["Title"] - SM - +
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 8748128..c83b63b 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -1,6 +1,6 @@ body { font-family: 'Fira Code', monospace; - background-color: #222; + background-color: #222 !important; } main { @@ -47,4 +47,4 @@ footer { border-top-width: 1px; border-top-color: #fff; /* line-height: 1rem; */ -} \ No newline at end of file +} -- GitLab From b48e60c2ec9a23b483e669db225b56fc6536a6bd Mon Sep 17 00:00:00 2001 From: whizzywig Date: Fri, 28 Feb 2020 11:08:04 +0000 Subject: [PATCH 4/9] Fixed the navbar not being interactable --- Views/Shared/_Layout.cshtml | 9 ++++---- wwwroot/css/site.css | 42 ++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 494fa04..7ff1d59 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -9,16 +9,17 @@ - -
+ +
@RenderBody()
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index c83b63b..541484b 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -1,33 +1,16 @@ -body { - font-family: 'Fira Code', monospace; - background-color: #222 !important; -} - -main { - margin: auto; - width: 70%; - padding: 5rem; -} - -.content { - margin-top: 8rem; - border-style: solid; - border-width: 1px; - border-color: #fff; -} - .navbar { overflow: hidden; position: fixed; top: 0; width: 100%; + height: 5rem; } .navbar a { float: left; display: block; text-align: center; - padding: 2rem 2rem; + padding: 1rem 2rem; text-decoration: none; color: #fff; } @@ -37,6 +20,27 @@ main { color: black; } +.content { + /* uses top to put it under the navbar*/ + top: 5rem; + border-style: none; +} + +html { + position: relative; + min-height: 100%; +} +body { + font-family: 'Fira Code', monospace; + background-color: #222 !important; +} + +main { + margin: auto; + width: 70%; + padding: 5rem; +} + footer { position: fixed; left: 0; -- GitLab From f40fd7f45ff9f8a818729d3dc645c6ec4cf21408 Mon Sep 17 00:00:00 2001 From: whizzywig Date: Fri, 28 Feb 2020 11:52:15 +0000 Subject: [PATCH 5/9] [Community Page] added the community page and removed unused css --- Controllers/HomeController.cs | 5 +++++ Views/Home/Community.cshtml | 9 +++++++++ Views/Shared/_Layout.cshtml | 18 ++++++++---------- wwwroot/css/site.css | 6 +++--- 4 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 Views/Home/Community.cshtml diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index bce5679..4f672a0 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -25,6 +25,11 @@ namespace SucsMembers.Controllers return View(); } + public IActionResult Community() + { + return View(); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Views/Home/Community.cshtml b/Views/Home/Community.cshtml new file mode 100644 index 0000000..b7aa185 --- /dev/null +++ b/Views/Home/Community.cshtml @@ -0,0 +1,9 @@ +@{ + ViewData["Title"] = "Community"; +} + +
+

The community page for Sucs

+

Join the discord - or find members on milliways

+

TODO

+
diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 7ff1d59..6405979 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -9,16 +9,14 @@ - - - +
@RenderBody() diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 541484b..9172df5 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -26,10 +26,10 @@ border-style: none; } -html { - position: relative; - min-height: 100%; +ol{ + list-style: none; } + body { font-family: 'Fira Code', monospace; background-color: #222 !important; -- GitLab From 8c45952e1a80bb9e61093dd76cdee0b968897408 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Fri, 28 Feb 2020 19:56:24 +0000 Subject: [PATCH 6/9] [readme] Add instructions on using DB --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4246438..4eb90ca 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,8 @@ For more detials see the [design brief spec](DESIGNBRIEF.md) # Contributing -If you want to get stuck in have a read of [CONTRIBUTING.md](CONTRIBUTING.md), make a fork, add your changes and get yourself a merge request! \ No newline at end of file +If you want to get stuck in have a read of [CONTRIBUTING.md](CONTRIBUTING.md), make a fork, add your changes and get yourself a merge request! + +# Database + +For now we're using a temporary SQLite database stored in the file `database.db`. If you want to make modifications to the database, install the application `DB Browser for SQLite` - You can find downloads and instructions [here](https://sqlitebrowser.org/dl/). \ No newline at end of file -- GitLab From e9f9f0a47fec358dca79687c6721a7a5de31c12e Mon Sep 17 00:00:00 2001 From: whizzywig Date: Mon, 2 Mar 2020 14:17:45 +0000 Subject: [PATCH 7/9] [Home page] updated home page and added new test user --- Views/Home/Index.cshtml | 5 +++-- Views/Users/Index.cshtml | 7 +++++++ database.db | Bin 61440 -> 61440 bytes 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index 0648eb1..82200ea 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -3,6 +3,7 @@ }
-

Hello!

-

Check out this awesome new website!

+

Welcome the new landing page for the sucs hub

+

Upcoming Events

+

TODO

diff --git a/Views/Users/Index.cshtml b/Views/Users/Index.cshtml index ad5cb0e..a26ef69 100644 --- a/Views/Users/Index.cshtml +++ b/Views/Users/Index.cshtml @@ -8,3 +8,10 @@

@Model.Firstname @Model.Lastname

@Model.Username :: @Model.GUID

+
    +
  1. Id :: @Model.GUID
  2. +
  3. Username :: @Model.Username
  4. + @if(Model.DiscordId != 0){ +
  5. Discord :: #@Model.DiscordId
  6. + } +
diff --git a/database.db b/database.db index deea2fc242d339b507a66e189315735d589f4d86..3c02b6f06b2d5d9fac3f3491ec09008540ffddc2 100644 GIT binary patch delta 211 zcmZp8z})bFd4e<}=R_H2M$U~1%i`I-GVp)pf3TTR;5z^0$N56yoUF{^jG@J;Ma4|K z3=9lR{2LkgukvpMDp<;|qQu0`AS*8{%~6tCT%wy;oKl{VSyfe8o|*2HnirIxoSl>V?;+&zysYS)S z3=9m6{8t(HuL7k{^H087ug}KF|A&G950L+fpO2ZDlamXq<|_mLSD@Hyeo-!FY0ku? lWL-leV~Erj2L3NVsaO0w+{|p8%z9V*f}I$c7BdPs005^OCKvz! -- GitLab From 34d2ac182057879380976c706ef0279e34488cc6 Mon Sep 17 00:00:00 2001 From: whizzywig Date: Mon, 9 Mar 2020 14:36:03 +0000 Subject: [PATCH 8/9] [Login] Added login page that will give the user an authentication cookie. This can then be used to check authentication and get the user that is logged in. Added a display for the logged in user on the navbar. Added a login model for the login page. Added authentication checking to the profile page. --- Controllers/UsersController.cs | 83 +++++++++++++++++++++++++++++++--- Database/SMDbContext.cs | 6 ++- Models/User.cs | 7 ++- Startup.cs | 10 ++++ Views/Shared/_Layout.cshtml | 7 +++ Views/Users/Login.cshtml | 9 ++++ wwwroot/css/site.css | 20 ++++++++ 7 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 Views/Users/Login.cshtml diff --git a/Controllers/UsersController.cs b/Controllers/UsersController.cs index 3836beb..e6b68e4 100644 --- a/Controllers/UsersController.cs +++ b/Controllers/UsersController.cs @@ -3,14 +3,20 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using System.Security.Claims; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SucsMembers.Models; using SucsMembers.Database; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Authorization; + namespace SucsMembers.Controllers { + [Authorize] public class UsersController : Controller { private SMDbContext _context; @@ -19,12 +25,77 @@ namespace SucsMembers.Controllers { _context = context; } - + [AllowAnonymous] public IActionResult Index() { - User user = _context.Users - .Where(u => u.Firstname == "Caleb") - .First(); - return View(user); + if (HttpContext.User.Identity.IsAuthenticated){ + string username = HttpContext.User.Identity.Name; + //Get the user with the same name as the cookie + User user = _context.Users + .Where(u => u.Username == username) + .First(); + return View(user); + } + //Render Login.cshtml + return View("Login"); + } + + [HttpPost] + [AllowAnonymous] + public async Task Login([FromForm]LoginModel model) + { + User user = null; + if (model.Username == null){ + //TODO replace with propper error handling + user = _context.Users + .Where(u => u.Username == "whizzywig") + .First(); + }else{ + user = _context.Users + .Where(u => u.Username == model.Username) + .First(); + } + var claims = new List + { + new Claim(ClaimTypes.Name, user.Username), + //If we want to add more claims + //new Claim("FirstName", user.Firstname), + //new Claim("LastName", user.Lastname), + }; + + var claimsIdentity = new ClaimsIdentity( + claims, CookieAuthenticationDefaults.AuthenticationScheme); + + var authProperties = new AuthenticationProperties + { + //AllowRefresh = , + // Refreshing the authentication session should be allowed. + + //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10), + // The time at which the authentication ticket expires. A + // value set here overrides the ExpireTimeSpan option of + // CookieAuthenticationOptions set with AddCookie. + + //IsPersistent = true, + // Whether the authentication session is persisted across + // multiple requests. When used with cookies, controls + // whether the cookie's lifetime is absolute (matching the + // lifetime of the authentication ticket) or session-based. + + //IssuedUtc = , + // The time at which the authentication ticket was issued. + + //RedirectUri = + // The full path or absolute URI to be used as an http + // redirect response value. + }; + //Gives the user their cookie + await HttpContext.SignInAsync( + CookieAuthenticationDefaults.AuthenticationScheme, + new ClaimsPrincipal(claimsIdentity), + authProperties); + + //return the user back to the profile page + return RedirectToAction("Index"); } } -} \ No newline at end of file +} diff --git a/Database/SMDbContext.cs b/Database/SMDbContext.cs index 04fb067..5cbfacc 100644 --- a/Database/SMDbContext.cs +++ b/Database/SMDbContext.cs @@ -6,8 +6,12 @@ namespace SucsMembers.Database { public class SMDbContext : DbContext { + public SMDbContext(DbContextOptions options) + : base(options) + { + } public DbSet Users { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite("Data Source=database.db"); } -} \ No newline at end of file +} diff --git a/Models/User.cs b/Models/User.cs index 8e6b936..758ea70 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -1,4 +1,3 @@ - namespace SucsMembers.Models { public class User { @@ -10,4 +9,8 @@ namespace SucsMembers.Models public string Lastname {get;set;} public ulong DiscordId {get;set;} } -} \ No newline at end of file + public class LoginModel { + public string Username {get;set;} + public string Password {get;set;} + } +} diff --git a/Startup.cs b/Startup.cs index 0a101b8..cd4eebb 100644 --- a/Startup.cs +++ b/Startup.cs @@ -8,6 +8,8 @@ using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Identity; using SucsMembers.Database; @@ -26,6 +28,12 @@ namespace SucsMembers public void ConfigureServices(IServiceCollection services) { services.AddDbContext(); + + services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) + .AddCookie( + //cookie options go here + ); + services.AddControllersWithViews(); } @@ -35,6 +43,7 @@ namespace SucsMembers if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); + //TODO add DB error page for debugging } else { @@ -47,6 +56,7 @@ namespace SucsMembers app.UseRouting(); + app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 6405979..8747efa 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -16,6 +16,13 @@ Games Community Join + @if(User.Identity.IsAuthenticated){ +
+

+ Logged in as, @User.Identity.Name +

+
+ }
diff --git a/Views/Users/Login.cshtml b/Views/Users/Login.cshtml new file mode 100644 index 0000000..a582407 --- /dev/null +++ b/Views/Users/Login.cshtml @@ -0,0 +1,9 @@ +@model SucsMembers.Models.LoginModel; + +
+
+
+
+
+
+
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index 9172df5..3c4b029 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -19,6 +19,12 @@ background: #ddd; color: black; } +.navbar div { + float: right; + display: block; + text-align: center; + padding: 1rem 2rem; +} .content { /* uses top to put it under the navbar*/ @@ -30,6 +36,20 @@ ol{ list-style: none; } +input[type=text]{ + background-color: #333; + color: #fff; +} +input[type=text]:focus{ + border: 1px solid #e86c39; +} +input[type=password]{ + background-color: #333; + color: #fff; +} +input[type=password]:focus{ + border: 1px solid #e86c39; +} body { font-family: 'Fira Code', monospace; background-color: #222 !important; -- GitLab From 989298a767c966fd908e4201f618d6f92bfa3ce7 Mon Sep 17 00:00:00 2001 From: whizzywig Date: Wed, 11 Mar 2020 20:28:35 +0000 Subject: [PATCH 9/9] [Logout] added the ability to logout using the asp.net Identity async signout method --- Controllers/UsersController.cs | 4 ++++ Views/Users/Index.cshtml | 1 + 2 files changed, 5 insertions(+) diff --git a/Controllers/UsersController.cs b/Controllers/UsersController.cs index e6b68e4..4bb0e0f 100644 --- a/Controllers/UsersController.cs +++ b/Controllers/UsersController.cs @@ -97,5 +97,9 @@ namespace SucsMembers.Controllers //return the user back to the profile page return RedirectToAction("Index"); } + public async Task Logout(){ + await HttpContext.SignOutAsync(); + return RedirectToAction("Index"); + } } } diff --git a/Views/Users/Index.cshtml b/Views/Users/Index.cshtml index a26ef69..701f7a1 100644 --- a/Views/Users/Index.cshtml +++ b/Views/Users/Index.cshtml @@ -15,3 +15,4 @@
  • Discord :: #@Model.DiscordId
  • } +Logout -- GitLab