Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
97c4dd8
Get user list using token
Apr 19, 2020
12d9cc0
Update create user
Apr 24, 2020
090b12b
Update user
Apr 26, 2020
87ed338
User detail and paging
Apr 26, 2020
62548d4
Complete user delete
Apr 26, 2020
b7effc1
User filter
Apr 26, 2020
066d57c
Sending message to list using tempdata
Apr 26, 2020
aaa01de
Role assign
Apr 26, 2020
acb5899
Setting language to session and refactoring code
May 20, 2020
47b477c
Merge pull request #5 from teduinternational/feature/35_setting_language
teduvn May 20, 2020
9f3a43e
Product list manage
May 26, 2020
f809b4a
Merge branch 'develop' of https://github.com/teduinternational/eShopS…
Jul 30, 2020
769d605
Create product form
Aug 2, 2020
ab033ff
Add ckeditor
Aug 12, 2020
721db2f
Filtering product by categoryid
Aug 24, 2020
0fec157
Assign product to category
Aug 27, 2020
c93b436
Merge branch 'feature/40_assing_product_to_category' into develop
Aug 29, 2020
44ca14b
Add template to webportal
Aug 29, 2020
4c85176
Merge pull request #6 from teduinternational/feature/41_add_webportal…
teduvn Sep 1, 2020
7d074be
Add multiple languages
Sep 2, 2020
7adb21b
Merge pull request #7 from teduinternational/feature/42_multiple-lang…
teduvn Sep 2, 2020
be7c444
Move API integration to separate project
Sep 2, 2020
0913cd5
Update database
Sep 2, 2020
6f4f361
Binding featured products
Sep 2, 2020
c6293b4
Merge pull request #8 from teduinternational/feature/43-binding-home-…
teduvn Sep 7, 2020
3cb5230
Load categories product
Sep 7, 2020
ee93c53
Update product
Sep 20, 2020
40947ef
Merge pull request #9 from teduinternational/feature/45_update_product
teduvn Sep 20, 2020
7ba342e
Product category
Oct 25, 2020
6704155
fix bug
Oct 25, 2020
d313565
Login for webportal
Nov 10, 2020
5c3042c
Register
Nov 11, 2020
dcc22bd
Merge pull request #10 from teduinternational/feature/50_register
teduvn Nov 11, 2020
0e0be9b
add cart item
Nov 12, 2020
e9d25ab
List cart
Nov 14, 2020
5ee99c8
Update the cart
Nov 16, 2020
6ae29ca
Merge pull request #11 from teduinternational/feature/53_update_cart
teduvn Nov 16, 2020
8a7f150
Checkout the order
Nov 17, 2020
417e1bc
Deploy config
Nov 17, 2020
1f004dc
Merge pull request #12 from teduinternational/feature/55_deploy_to_iis
teduvn Nov 17, 2020
e008c40
Merge pull request #13 from teduinternational/develop
teduvn Nov 17, 2020
05205a1
Update README.md
teduvn Nov 25, 2020
01a8c00
Merge pull request #15 from teduinternational/master
teduvn Nov 26, 2020
8548bb0
Update to .NET 6
Dec 4, 2021
861c513
Merge branch 'feature/55_deploy_to_iis' into develop
Dec 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
- Run Update-database and Enter.
- After migrate database successful, set Startup Project is eShopSolution.WebApp
- Change database connection in appsettings.Development.json in eShopSolution.WebApp project.
- You need to change 3 projects to self-host profile.
- Set multiple run project: Right click to Solution and choose Properties and set Multiple Project, choose Start for 3 Projects: BackendApi, WebApp and AdminApp.
- Choose profile to run or press F5
## How to contribute
- Fork and create your branch
- Create Pull request to us.

## Admin template: https://startbootstrap.com/templates/sb-admin/
## Admin template: https://startbootstrap.com/templates/sb-admin/
## Portal template: https://www.free-css.com/free-css-templates/page194/bootstrap-shop

## I18N (Internalization)
- References: https://medium.com/swlh/step-by-step-tutorial-to-build-multi-cultural-asp-net-core-web-app-3fac9a960c43
- Source code: https://github.com/LazZiya/ExpressLocalizationSampleCore3
25 changes: 25 additions & 0 deletions eShopSolution.AdminApp/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace eShopSolution.AdminApp.Controllers
{
[Authorize]
public class BaseController : Controller
{
public override void OnActionExecuting(ActionExecutingContext context)
{
var sessions = context.HttpContext.Session.GetString("Token");
if (sessions == null)
{
context.Result = new RedirectToActionResult("Index", "Login", null);
}
base.OnActionExecuting(context);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using eShopSolution.AdminApp.Models;
using eShopSolution.ApiIntegration;
using eShopSolution.Utilities.Constants;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Linq;
using System.Threading.Tasks;

namespace eShopSolution.AdminApp.Controllers.Components
{
public class NavigationViewComponent : ViewComponent
{
private readonly ILanguageApiClient _languageApiClient;

public NavigationViewComponent(ILanguageApiClient languageApiClient)
{
_languageApiClient = languageApiClient;
}

public async Task<IViewComponentResult> InvokeAsync()
{
var languages = await _languageApiClient.GetAll();
var currentLanguageId = HttpContext
.Session
.GetString(SystemConstants.AppSettings.DefaultLanguageId);
var items = languages.ResultObj.Select(x => new SelectListItem()
{
Text = x.Name,
Value = x.Id.ToString(),
Selected = currentLanguageId == null ? x.IsDefault : currentLanguageId == x.Id.ToString()
});
var navigationVm = new NavigationViewModel()
{
CurrentLanguageId = currentLanguageId,
Languages = items.ToList()
};

return View("Default", navigationVm);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using eShopSolution.ViewModels.Common;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace eShopSolution.AdminApp.Controllers.Components
{
public class PagerViewComponent : ViewComponent
{
public Task<IViewComponentResult> InvokeAsync(PagedResultBase result)
{
return Task.FromResult((IViewComponentResult)View("Default", result));
}
}
}
14 changes: 12 additions & 2 deletions eShopSolution.AdminApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
using Microsoft.Extensions.Logging;
using eShopSolution.AdminApp.Models;
using Microsoft.AspNetCore.Authorization;
using eShopSolution.Utilities.Constants;
using Microsoft.AspNetCore.Http;

namespace eShopSolution.AdminApp.Controllers
{
[Authorize]
public class HomeController : Controller
public class HomeController : BaseController
{
private readonly ILogger<HomeController> _logger;

Expand All @@ -36,5 +37,14 @@ public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}

[HttpPost]
public IActionResult Language(NavigationViewModel viewModel)
{
HttpContext.Session.SetString(SystemConstants.AppSettings.DefaultLanguageId,
viewModel.CurrentLanguageId);

return Redirect(viewModel.ReturnUrl);
}
}
}
86 changes: 86 additions & 0 deletions eShopSolution.AdminApp/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using eShopSolution.ApiIntegration;
using eShopSolution.Utilities.Constants;
using eShopSolution.ViewModels.System.Users;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;

namespace eShopSolution.AdminApp.Controllers
{
public class LoginController : Controller
{
private readonly IUserApiClient _userApiClient;
private readonly IConfiguration _configuration;

public LoginController(IUserApiClient userApiClient,
IConfiguration configuration)
{
_userApiClient = userApiClient;
_configuration = configuration;
}

[HttpGet]
public async Task<IActionResult> Index()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return View();
}

[HttpPost]
public async Task<IActionResult> Index(LoginRequest request)
{
if (!ModelState.IsValid)
return View(ModelState);

var result = await _userApiClient.Authenticate(request);
if (result.ResultObj == null)
{
ModelState.AddModelError("", result.Message);
return View();
}
var userPrincipal = this.ValidateToken(result.ResultObj);
var authProperties = new AuthenticationProperties
{
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
IsPersistent = false
};
HttpContext.Session.SetString(SystemConstants.AppSettings.DefaultLanguageId, _configuration[SystemConstants.AppSettings.DefaultLanguageId]);
HttpContext.Session.SetString(SystemConstants.AppSettings.Token, result.ResultObj);
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
userPrincipal,
authProperties);

return RedirectToAction("Index", "Home");
}

private ClaimsPrincipal ValidateToken(string jwtToken)
{
IdentityModelEventSource.ShowPII = true;

SecurityToken validatedToken;
TokenValidationParameters validationParameters = new TokenValidationParameters();

validationParameters.ValidateLifetime = true;

validationParameters.ValidAudience = _configuration["Tokens:Issuer"];
validationParameters.ValidIssuer = _configuration["Tokens:Issuer"];
validationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Tokens:Key"]));

ClaimsPrincipal principal = new JwtSecurityTokenHandler().ValidateToken(jwtToken, validationParameters, out validatedToken);

return principal;
}
}
}
Loading