diff --git a/ASI.Basecode.WebApp/ASI.Basecode.WebApp.csproj b/ASI.Basecode.WebApp/ASI.Basecode.WebApp.csproj index ee031fa..4f21f09 100644 --- a/ASI.Basecode.WebApp/ASI.Basecode.WebApp.csproj +++ b/ASI.Basecode.WebApp/ASI.Basecode.WebApp.csproj @@ -6,6 +6,40 @@ 872bac6a-ed64-4226-a559-064bd37b166e + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -39,4 +73,12 @@ + + + + + + + <_ContentIncludedByDefault Remove="Views\Shared\Calendar.cshtml" /> + diff --git a/ASI.Basecode.WebApp/Controllers/AccountController.cs b/ASI.Basecode.WebApp/Controllers/AccountController.cs index 3a55a55..d2f3f36 100644 --- a/ASI.Basecode.WebApp/Controllers/AccountController.cs +++ b/ASI.Basecode.WebApp/Controllers/AccountController.cs @@ -26,6 +26,7 @@ public class AccountController : ControllerBase private readonly TokenProviderOptionsFactory _tokenProviderOptionsFactory; private readonly IConfiguration _appConfiguration; private readonly IUserService _userService; + private const string AdminUserId = "admin"; // Temporary admin user ID /// /// Initializes a new instance of the class. @@ -77,7 +78,7 @@ public ActionResult Login() /// The model. /// The return URL. /// Created response view - [HttpPost] + /*[HttpPost] [AllowAnonymous] public async Task Login(LoginViewModel model, string returnUrl) { @@ -92,7 +93,7 @@ public async Task Login(LoginViewModel model, string returnUrl) return RedirectToAction("Index", "Home"); - /*var loginResult = _userService.AuthenticateUser(model.UserId, model.Password, ref user); + *//*var loginResult = _userService.AuthenticateUser(model.UserId, model.Password, ref user); if (loginResult == LoginResult.Success) { // 認証OK @@ -106,7 +107,40 @@ public async Task Login(LoginViewModel model, string returnUrl) TempData["ErrorMessage"] = "Incorrect UserId or Password"; return View(); } - return View();*/ + return View();*//* + }*/ + + //the code above being commented is the original login logic of basecode. The code below this comment is the temporary solution for login para mapasok si admin + + [HttpPost] + [AllowAnonymous] + public async Task Login(LoginViewModel model, string returnUrl) + { + this._session.SetString("HasSession", "Exist"); + + // Temporary login logic + if (model.UserId == AdminUserId && model.Password == "adminpass") + { + // Admin login + User user = new() { Id = 1, UserId = AdminUserId, Name = "Admin User", Password = "adminpass" }; + await this._signInManager.SignInAsync(user); + this._session.SetString("UserName", user.Name); + this._session.SetString("UserRole", "Admin"); + return RedirectToAction("Index", "Admin"); + } + else if (!string.IsNullOrEmpty(model.UserId) && !string.IsNullOrEmpty(model.Password)) + { + // Regular user login + User user = new() { Id = 2, UserId = model.UserId, Name = model.UserId, Password = model.Password }; + await this._signInManager.SignInAsync(user); + this._session.SetString("UserName", user.Name); + this._session.SetString("UserRole", "User"); + return RedirectToAction("Index", "Home"); + } + + // Invalid login + TempData["ErrorMessage"] = "Incorrect UserId or Password"; + return View(); } [HttpGet] @@ -146,5 +180,17 @@ public async Task SignOutUser() await this._signInManager.SignOutAsync(); return RedirectToAction("Login", "Account"); } + + /// + /// Sign Out current admin and return login view. + /// + /// Created response view + [AllowAnonymous] + public async Task SignOutAdmin() + { + await this._signInManager.SignOutAsync(); + HttpContext.Session.Clear(); + return RedirectToAction("Login", "Account"); + } } } diff --git a/ASI.Basecode.WebApp/Controllers/AdminController.cs b/ASI.Basecode.WebApp/Controllers/AdminController.cs new file mode 100644 index 0000000..1c855cf --- /dev/null +++ b/ASI.Basecode.WebApp/Controllers/AdminController.cs @@ -0,0 +1,83 @@ +using ASI.Basecode.WebApp.Mvc; +using AutoMapper; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace ASI.Basecode.WebApp.Controllers +{ + /// + /// Admin Controller + /// + public class AdminController : ControllerBase + { + /// + /// Constructor + /// + /// + /// + /// + /// + /// + public AdminController(IHttpContextAccessor httpContextAccessor, + ILoggerFactory loggerFactory, + IConfiguration configuration, + IMapper mapper = null) : base(httpContextAccessor, loggerFactory, configuration, mapper) + { + + } + + /// + /// Returns Admin Home View. + /// + /// Admin Home View + public IActionResult Index() + { + if (HttpContext.Session.GetString("UserRole") != "Admin") + { + return RedirectToAction("Login", "Account"); + } + return View(); + } + + /// + /// Returns Admin Analytics View. + /// + /// Admin Analytics View + public IActionResult Analytics() + { + if (HttpContext.Session.GetString("UserRole") != "Admin") + { + return RedirectToAction("Login", "Account"); + } + return View(); + } + + /// + /// Returns Manage Roles View. + /// + /// Manage Roles View + public IActionResult ManageRoles() + { + if (HttpContext.Session.GetString("UserRole") != "Admin") + { + return RedirectToAction("Login", "Account"); + } + return View(); + } + + /// + /// Returns Admin Settings View. + /// + /// Admin Settings View + public IActionResult AdminSettings() + { + if (HttpContext.Session.GetString("UserRole") != "Admin") + { + return RedirectToAction("Login", "Account"); + } + return View(); + } + } +} diff --git a/ASI.Basecode.WebApp/Controllers/HomeController.cs b/ASI.Basecode.WebApp/Controllers/HomeController.cs index b0c6e99..19d579a 100644 --- a/ASI.Basecode.WebApp/Controllers/HomeController.cs +++ b/ASI.Basecode.WebApp/Controllers/HomeController.cs @@ -1,40 +1,52 @@ -using ASI.Basecode.WebApp.Mvc; -using AutoMapper; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; + using ASI.Basecode.WebApp.Mvc; + using AutoMapper; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; -namespace ASI.Basecode.WebApp.Controllers -{ - /// - /// Home Controller - /// - public class HomeController : ControllerBase + namespace ASI.Basecode.WebApp.Controllers { /// - /// Constructor + /// Home Controller /// - /// - /// - /// - /// - /// - public HomeController(IHttpContextAccessor httpContextAccessor, - ILoggerFactory loggerFactory, - IConfiguration configuration, - IMapper mapper = null) : base(httpContextAccessor, loggerFactory, configuration, mapper) + public class HomeController : ControllerBase { + /// + /// Constructor + /// + /// + /// + /// + /// + /// + public HomeController(IHttpContextAccessor httpContextAccessor, + ILoggerFactory loggerFactory, + IConfiguration configuration, + IMapper mapper = null) : base(httpContextAccessor, loggerFactory, configuration, mapper) + { - } + } - /// - /// Returns Home View. - /// - /// Home View - public IActionResult Index() - { - return View(); - } + /// + /// Returns Home View. + /// + /// Home View + public IActionResult Index() + { + return View(); + } + public IActionResult ViewBookings() + { + return View(); + } + public IActionResult Calendar() + { + return View(); + } + public IActionResult UserSettings() + { + return View(); + } + } } -} diff --git a/ASI.Basecode.WebApp/Controllers/ViewBookingsController.cs b/ASI.Basecode.WebApp/Controllers/ViewBookingsController.cs new file mode 100644 index 0000000..8c7d170 --- /dev/null +++ b/ASI.Basecode.WebApp/Controllers/ViewBookingsController.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + +namespace ASI.Basecode.WebApp.Controllers +{ + public class ViewBookingsController : Controller + { + public IActionResult ViewBookings() + { + return View(); + } + } +} diff --git a/ASI.Basecode.WebApp/Program.cs b/ASI.Basecode.WebApp/Program.cs index c31c03e..3277f46 100644 --- a/ASI.Basecode.WebApp/Program.cs +++ b/ASI.Basecode.WebApp/Program.cs @@ -36,5 +36,19 @@ app.MapControllers(); app.MapRazorPages(); + +app.UseEndpoints(endpoints => +{ + endpoints.MapControllerRoute( + name: "admin", + pattern: "Admin/{action=Index}/{id?}", + defaults: new { controller = "Admin" }); + + endpoints.MapControllerRoute( + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); +}); + + // Run application app.Run(); diff --git a/ASI.Basecode.WebApp/Startup.cs b/ASI.Basecode.WebApp/Startup.cs index a997939..a42d089 100644 --- a/ASI.Basecode.WebApp/Startup.cs +++ b/ASI.Basecode.WebApp/Startup.cs @@ -119,6 +119,15 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton( new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"))); + + + //gi add ni for session services + services.AddSession(options => + { + options.IdleTimeout = TimeSpan.FromMinutes(30); + options.Cookie.HttpOnly = true; + options.Cookie.IsEssential = true; + }); } /// @@ -152,6 +161,9 @@ public void ConfigureApp(IApplicationBuilder app, IWebHostEnvironment env) this._app.UseAuthentication(); this._app.UseAuthorization(); + + //for session use + this._app.UseSession(); } } } diff --git a/ASI.Basecode.WebApp/Views/Admin/AdminSettings.cshtml b/ASI.Basecode.WebApp/Views/Admin/AdminSettings.cshtml new file mode 100644 index 0000000..9f081b6 --- /dev/null +++ b/ASI.Basecode.WebApp/Views/Admin/AdminSettings.cshtml @@ -0,0 +1,63 @@ +@{ + ViewData["Title"] = "Admin Settings"; +} +
+
+

Admin Settings

+ +
+
+ +@section Styles { + +} \ No newline at end of file diff --git a/ASI.Basecode.WebApp/Views/Admin/Analytics.cshtml b/ASI.Basecode.WebApp/Views/Admin/Analytics.cshtml new file mode 100644 index 0000000..b14ff3e --- /dev/null +++ b/ASI.Basecode.WebApp/Views/Admin/Analytics.cshtml @@ -0,0 +1,63 @@ +@{ + ViewData["Title"] = "Analytics"; +} +
+
+

Report and Analytics

+ +
+
+ +@section Styles { + +} \ No newline at end of file diff --git a/ASI.Basecode.WebApp/Views/Admin/Index.cshtml b/ASI.Basecode.WebApp/Views/Admin/Index.cshtml new file mode 100644 index 0000000..368a7b2 --- /dev/null +++ b/ASI.Basecode.WebApp/Views/Admin/Index.cshtml @@ -0,0 +1,62 @@ +@{ + ViewData["Title"] = "Admin Home Page"; +} +
+
+

Admin Home

+ +
+
+ +@section Styles { + +} \ No newline at end of file diff --git a/ASI.Basecode.WebApp/Views/Admin/ManageRoles.cshtml b/ASI.Basecode.WebApp/Views/Admin/ManageRoles.cshtml new file mode 100644 index 0000000..50b6ae8 --- /dev/null +++ b/ASI.Basecode.WebApp/Views/Admin/ManageRoles.cshtml @@ -0,0 +1,64 @@ +@{ + ViewData["Title"] = "Manage Roles"; +} +
+
+

Manage Roles

+ +
+
+ +@section Styles { + +} \ No newline at end of file diff --git a/ASI.Basecode.WebApp/Views/Home/Calendar.cshtml b/ASI.Basecode.WebApp/Views/Home/Calendar.cshtml new file mode 100644 index 0000000..3d2b2fc --- /dev/null +++ b/ASI.Basecode.WebApp/Views/Home/Calendar.cshtml @@ -0,0 +1,63 @@ +@{ + ViewData["Title"] = "Calendar"; +} +
+
+

Calendar

+ +
+
+ +@section Styles { + +} \ No newline at end of file diff --git a/ASI.Basecode.WebApp/Views/Home/Index.cshtml b/ASI.Basecode.WebApp/Views/Home/Index.cshtml index d2d19bd..0a8353d 100644 --- a/ASI.Basecode.WebApp/Views/Home/Index.cshtml +++ b/ASI.Basecode.WebApp/Views/Home/Index.cshtml @@ -1,8 +1,500 @@ @{ - ViewData["Title"] = "Home Page"; + ViewData["Title"] = "User Home Page"; } +
+
+
+
+ + Add Booking +
+
+ + My Bookings +
+
+
+
+
+
+
+ 11:11
+ Tuesday, June 18 +
+
+ +
+
+
+
+
+
+

Today's Booking

+
+ 09:00 + Project Management Mock Defense + Training Room +
+
+ 11:00 + C# Mock Defense + Training Room +
+
+
+
+ +
+
+ + + *@ \ No newline at end of file diff --git a/ASI.Basecode.WebApp/Views/Shared/_Layout.cshtml b/ASI.Basecode.WebApp/Views/Shared/_Layout.cshtml index cf2c918..aaf588f 100644 --- a/ASI.Basecode.WebApp/Views/Shared/_Layout.cshtml +++ b/ASI.Basecode.WebApp/Views/Shared/_Layout.cshtml @@ -1,6 +1,4 @@ -@using static ASI.Basecode.Resources.Views.Screen - - + @@ -15,16 +13,30 @@ @Html.Partial("_Header") -
+ @{ + var isAdmin = Context.Session.GetString("UserRole") == "Admin"; + var isLoginOrRegister = ViewContext.RouteData.Values["Controller"].ToString() == "Account" && + (ViewContext.RouteData.Values["Action"].ToString() == "Login" || + ViewContext.RouteData.Values["Action"].ToString() == "Register"); + } + + @if (!isLoginOrRegister) + { + if (isAdmin) + { + @Html.Partial("_AdminSidebar") + } + else + { + @Html.Partial("_UserSidebar") + } + } + +
@RenderBody()
-
-
- @Copyright -
-
diff --git a/ASI.Basecode.WebApp/Views/Shared/_UserSidebar.cshtml b/ASI.Basecode.WebApp/Views/Shared/_UserSidebar.cshtml new file mode 100644 index 0000000..aae0464 --- /dev/null +++ b/ASI.Basecode.WebApp/Views/Shared/_UserSidebar.cshtml @@ -0,0 +1,175 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ + +} + + diff --git a/ASI.Basecode.WebApp/wwwroot/css/site.css b/ASI.Basecode.WebApp/wwwroot/css/site.css index d3f4a7a..6e695e7 100644 --- a/ASI.Basecode.WebApp/wwwroot/css/site.css +++ b/ASI.Basecode.WebApp/wwwroot/css/site.css @@ -84,4 +84,7 @@ body { .w-1000px { width: 1000px; -} \ No newline at end of file +} + + + diff --git a/ASI.Basecode.WebApp/wwwroot/css/style.css b/ASI.Basecode.WebApp/wwwroot/css/style.css index 05d1acd..1758c8a 100644 --- a/ASI.Basecode.WebApp/wwwroot/css/style.css +++ b/ASI.Basecode.WebApp/wwwroot/css/style.css @@ -22,7 +22,7 @@ } body { - background-color: var(--background-color4); + background-color: black; max-width: 100%; overflow-x: hidden; } diff --git a/ASI.Basecode.WebApp/wwwroot/img/book.jpg b/ASI.Basecode.WebApp/wwwroot/img/book.jpg new file mode 100644 index 0000000..89442ac Binary files /dev/null and b/ASI.Basecode.WebApp/wwwroot/img/book.jpg differ diff --git a/ASI.Basecode.sln b/ASI.Basecode.sln index e20a71f..732d818 100644 --- a/ASI.Basecode.sln +++ b/ASI.Basecode.sln @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASI.Basecode.Services", "AS EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{65A10F5F-9790-475E-A544-DF3FF6A41A66}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASI.Basecode.Resources", "ASI.Basecode.Resources\ASI.Basecode.Resources.csproj", "{ED0C96A6-749E-413B-BF4D-8E405BEB172E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASI.Basecode.Resources", "ASI.Basecode.Resources\ASI.Basecode.Resources.csproj", "{ED0C96A6-749E-413B-BF4D-8E405BEB172E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution