This commit is contained in:
Aurelien Rebourg 2021-03-23 18:53:03 +00:00
commit 65c3fe5f93
37 changed files with 2966 additions and 0 deletions

16
Back.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shop", "Shop\Shop.csproj", "{6CD64A6D-4A60-425D-8E06-1E28096A4D52}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6CD64A6D-4A60-425D-8E06-1E28096A4D52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CD64A6D-4A60-425D-8E06-1E28096A4D52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CD64A6D-4A60-425D-8E06-1E28096A4D52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CD64A6D-4A60-425D-8E06-1E28096A4D52}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,119 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shop.Data;
using Shop.DTO;
using Shop.Model;
namespace Shop.Controllers
{
[ApiController]
[Route("[controller]")]
public class CustomerController : ControllerBase
{
private readonly Context _context;
public CustomerController(Context context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Customer>>> GetCustomer()
{
return await _context.customer.ToListAsync();
}
[HttpGet("{id}")]
public ActionResult<CustomerDTO> GetCustomer_byId(int id)
{
var order = from orders in _context.orders
join product in _context.products on orders.products_id equals product.product_id
join customer in _context.customer on orders.customer_id equals customer.customer_id
select new OrderDTO
{
customer_id = customer.customer_id,
price = product.price,
order_id = orders.order_id,
product_id = product.product_id
};
var customers = from customer in _context.customer
join orders in _context.orders on customer.customer_id equals orders.customer_id
select new CustomerOrderListDTO()
{
Customer_id = customer.customer_id,
Name = customer.customer_name,
Orders = order.Where(x => x.customer_id == customer.customer_id).ToList()
};
var customer_by_id = customers.ToList().Find(x => x.Customer_id == id);
if (customer_by_id == null)
{
return NotFound();
}
return customer_by_id;
}
[HttpPost]
public async Task<ActionResult<Customer>> PostCustomer(Customer customer)
{
_context.customer.Add(customer);
await _context.SaveChangesAsync();
return CreatedAtAction("GetCustomer", new { id = customer.customer_id }, customer);
}
[HttpPut("{id}")]
public async Task<IActionResult> Put_Values(int id, Customer customer)
{
if (id != customer.customer_id)
{
return BadRequest();
}
_context.Entry(customer).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ValuesExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
private bool ValuesExists(int id)
{
return _context.customer.Any(e => e.customer_id == id);
}
[HttpDelete("{id}")]
public async Task<ActionResult<Customer>> Delete_values(int id)
{
var values = await _context.customer.FindAsync(id);
if (values == null)
{
return NotFound();
}
_context.customer.Remove(values);
await _context.SaveChangesAsync();
return values;
}
}
}

View File

@ -0,0 +1,119 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shop.Data;
using Shop.DTO;
using Shop.Models;
namespace Shop.Controllers
{
[ApiController]
[Route("[controller]")]
public class OrdersController : ControllerBase
{
private readonly Context _context;
public OrdersController(Context context)
{
_context = context;
}
[HttpGet]
public ActionResult<IEnumerable<OrderDTO>> GetOrder()
{
var order = from orders in _context.orders
join product in _context.products on orders.products_id equals product.product_id
select new OrderDTO()
{
customer_id = orders.customer_id,
order_id = orders.order_id,
product_id = product.product_id,
price = product.price
};
return Ok(order);
}
[HttpGet("{id}")]
public ActionResult<OrderDTO> GetOrder_byId(int id)
{
var order = from orders in _context.orders
join product in _context.products on orders.products_id equals product.product_id
join customer in _context.customer on orders.customer_id equals customer.customer_id
select new OrderDTO
{
customer_id = customer.customer_id,
order_id = orders.order_id,
product_id = product.product_id,
price = product.price
};
var order_by_id = order.ToList().Find(x => x.order_id == id);
if (order_by_id == null)
{
return NotFound();
}
return order_by_id;
}
[HttpPost]
public async Task<ActionResult<Orders>> PostOrders(Orders order)
{
_context.orders.Add(order);
await _context.SaveChangesAsync();
return CreatedAtAction("GetOrder", new { id = order.order_id }, order);
}
[HttpPut("{id}")]
public async Task<IActionResult> Put_Values(int id, Orders orders)
{
if (id != orders.order_id)
{
return BadRequest();
}
_context.Entry(orders).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ValuesExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
private bool ValuesExists(int id)
{
return _context.orders.Any(e => e.order_id == id);
}
[HttpDelete("{id}")]
public async Task<ActionResult<Orders>> Delete_orders(int id)
{
var values = await _context.orders.FindAsync(id);
if (values == null)
{
return NotFound();
}
_context.orders.Remove(values);
await _context.SaveChangesAsync();
return values;
}
}
}

View File

@ -0,0 +1,97 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shop.Data;
using Shop.DTO;
using Shop.Model;
namespace Shop.Controllers
{
[ApiController]
[Route("[controller]")]
public class ProductsController : Controller
{
private readonly Context _context;
public ProductsController(Context context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Products>>> GetProduct()
{
return await _context.products.ToListAsync();
}
[HttpPost]
public async Task<ActionResult<AddProducts.AddProduct>> Add_Product(AddProducts.AddProduct productDTO)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var product = new Products()
{
product_id = productDTO.product_id,
price = productDTO.price,
product_name = productDTO.product_name
};
await _context.products.AddAsync(product);
await _context.SaveChangesAsync();
return CreatedAtAction("GetProduct", new {id = product.product_id}, productDTO);
}
[HttpPut("{id}")]
public async Task<IActionResult> Put_Values(int id, Products products)
{
if (id != products.product_id)
{
return BadRequest();
}
_context.Entry(products).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ValuesExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
private bool ValuesExists(int id)
{
return _context.products.Any(e => e.product_id == id);
}
[HttpDelete("{id}")]
public async Task<ActionResult<Products>> Delete_values(int id)
{
var values = await _context.products.FindAsync(id);
if (values == null)
{
return NotFound();
}
_context.products.Remove(values);
await _context.SaveChangesAsync();
return values;
}
}
}

View File

@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using Shop.DTO;
using Shop.Helpers;
using Shop.Model;
using Shop.Services;
namespace Controllers
{
[Authorize]
[ApiController]
[Route("[controller]")]
public class UsersController : ControllerBase
{
private UserServices.IUserService _userService;
private IMapper _mapper;
public IConfiguration Configuration;
public UsersController(
UserServices.IUserService userService,
IMapper mapper,
IConfiguration configuration)
{
_userService = userService;
_mapper = mapper;
Configuration = configuration;
}
[AllowAnonymous]
[HttpPost("authenticate")]
public IActionResult Authenticate([FromBody]AuthenticateModel model)
{
var user = _userService.Authenticate(model.Username, model.Password);
if (user == null)
return BadRequest(new { message = "Username or password is incorrect" });
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(Configuration["Secret"]);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, user.Id.ToString())
}),
Expires = DateTime.UtcNow.AddDays(7),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);
// return basic user info and authentication token
return Ok(new
{
Id = user.Id,
Username = user.Username,
FirstName = user.FirstName,
LastName = user.LastName,
Token = tokenString
});
}
[AllowAnonymous]
[HttpPost("register")]
public IActionResult Register([FromBody]RegisterModel model)
{
// map model to entity
var user = _mapper.Map<User>(model);
try
{
// create user
_userService.Create(user, model.Password);
return Ok();
}
catch (AppException ex)
{
// return error message if there was an exception
return BadRequest(new { message = ex.Message });
}
}
[HttpGet]
public IActionResult GetAll()
{
var users = _userService.GetAll();
var model = _mapper.Map<IList<UserModel>>(users);
return Ok(model);
}
[HttpGet("{id}")]
public IActionResult GetById(int id)
{
var user = _userService.GetById(id);
var model = _mapper.Map<UserModel>(user);
return Ok(model);
}
[HttpPut("{id}")]
public IActionResult Update(int id, [FromBody]UpdateModel model)
{
//Finding who is logged in
int logged_in_user = int.Parse(User.Identity.Name);
// map model to entity and set id
var user = _mapper.Map<User>(model);
user.Id = id;
//Rejecting access if the logged in user is not same as the user updating information
if(logged_in_user != id)
{
return BadRequest(new { message = "Access Denied" });
}
try
{
// update user
_userService.Update(user, model.CurrentPassword, model.NewPassword, model.ConfirmNewPassword);
return Ok();
}
catch (AppException ex)
{
// return error message if there was an exception
return BadRequest(new { message = ex.Message });
}
}
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
_userService.Delete(id);
return Ok();
}
}
}

17
Shop/DTO/AddProducts.cs Normal file
View File

@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace Shop.DTO
{
public class AddProducts
{
public class AddProduct
{
[Required]
public int product_id { get; set; }
[Required]
public string product_name { get; set; }
[Required]
public decimal price { get; set; }
}
}
}

View File

@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Shop.DTO
{
public class AuthenticateModel
{
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
}
}

9
Shop/DTO/CustomerDTO.cs Normal file
View File

@ -0,0 +1,9 @@
namespace Shop.DTO
{
public class CustomerDTO
{
public int Customer_id { get; set; }
public string Name { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace Shop.DTO
{
public class CustomerOrderListDTO : CustomerDTO
{
public List<OrderDTO> Orders { get; set; }
}
}

13
Shop/DTO/OrderDTO.cs Normal file
View File

@ -0,0 +1,13 @@
namespace Shop.DTO
{
public class OrderDTO
{
public int order_id { get; set; }
public int customer_id { get; set; }
public int product_id { get; set; }
public decimal price { get; set; }
}
}

19
Shop/DTO/RegisterModel.cs Normal file
View File

@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
namespace Shop.DTO
{
public class RegisterModel
{
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
}
}

12
Shop/DTO/UpdateModel.cs Normal file
View File

@ -0,0 +1,12 @@
namespace Shop.DTO
{
public class UpdateModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
public string CurrentPassword { get; set; }
public string NewPassword { get; set; }
public string ConfirmNewPassword { get; set; }
}
}

10
Shop/DTO/UserModel.cs Normal file
View File

@ -0,0 +1,10 @@
namespace Shop.DTO
{
public class UserModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
}
}

19
Shop/Data/Context.cs Normal file
View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using Shop.Model;
using Shop.Models;
namespace Shop.Data
{
public class Context : DbContext
{
public Context(DbContextOptions<Context> options) : base(options) {}
public DbSet<Customer> customer { get; set; }
public DbSet<Orders> orders { get; set; }
public DbSet<Products> products { get; set; }
public DbSet<User> User {get; set;}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
namespace Shop.Helpers
{
// Custom exception class for throwing application specific exceptions (e.g. for validation)
// that can be caught and handled within the application
public class AppException : Exception
{
public AppException() : base() {}
public AppException(string message) : base(message) { }
public AppException(string message, params object[] args)
: base(String.Format(CultureInfo.CurrentCulture, message, args))
{
}
}
}

View File

@ -0,0 +1,17 @@
using AutoMapper;
using Shop.DTO;
using Shop.Model;
namespace Shop.Helpers
{
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<User, UserModel>();
CreateMap<RegisterModel, User>();
CreateMap<UpdateModel, User>();
}
}
}

12
Shop/Model/Customer.cs Normal file
View File

@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Shop.Model
{
public class Customer
{
[Key]
public int customer_id { get; set; }
public string customer_name { get; set; }
}
}

14
Shop/Model/Orders.cs Normal file
View File

@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace Shop.Models
{
public class Orders
{
[Key]
public int order_id { get; set; }
public int customer_id { get; set; }
public int products_id { get; set; }
}
}

12
Shop/Model/Products.cs Normal file
View File

@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Shop.Model
{
public class Products
{
[Key]
public int product_id { get; set; }
public string product_name { get; set; }
public decimal price { get; set; }
}
}

11
Shop/Model/User.cs Normal file
View File

@ -0,0 +1,11 @@
namespace Shop.Model
{
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Username { get; set; }
public string PasswordHash { get; set; }
}
}

23
Shop/Program.cs Normal file
View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Shop
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}

View File

@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:7781",
"sslPort": 44394
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Shop": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,165 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Shop.Data;
using Shop.Helpers;
using Shop.Model;
namespace Shop.Services
{
public class UserServices
{
public interface IUserService
{
User Authenticate(string username, string password);
IEnumerable<User> GetAll();
User GetById(int id);
User Create(User user, string password);
void Update(User user, string currentPassword, string password, string confirmPassword);
void Delete(int id);
}
public class UserService : IUserService
{
private Context _context;
public UserService(Context context)
{
_context = context;
}
public User Authenticate(string username, string password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
return null;
}
var user = _context.User.FirstOrDefault(x => x.Username == username) ?? null;
// check if username exists
if (user == null)
{
return null;
}
// Granting access if the hashed password in the database matches with the password(hashed in computeHash method) entered by user.
if(computeHash(password) != user.PasswordHash)
{
return null;
}
return user;
}
public IEnumerable<User> GetAll()
{
return _context.User;
}
public User GetById(int id)
{
return _context.User.Find(id);
}
public User Create(User user, string password)
{
// validation
if (string.IsNullOrWhiteSpace(password))
{
throw new AppException("Password is required");
}
if (_context.User.Any(x => x.Username == user.Username))
{
throw new AppException("Username \"" + user.Username + "\" is already taken");
}
//Saving hashed password into Database table
user.PasswordHash = computeHash(password);
_context.User.Add(user);
_context.SaveChanges();
return user;
}
public void Update(User userParam, string currentPassword = null, string password = null, string confirmPassword = null)
{
//Find the user by Id
var user = _context.User.Find(userParam.Id);
if (user == null)
{
throw new AppException("User not found");
}
// update user properties if provided
if (!string.IsNullOrWhiteSpace(userParam.Username) && userParam.Username != user.Username)
{
// throw error if the new username is already taken
if (_context.User.Any(x => x.Username == userParam.Username))
{
throw new AppException("Username " + userParam.Username + " is already taken");
}
else
{
user.Username = userParam.Username;
}
}
if (!string.IsNullOrWhiteSpace(userParam.FirstName))
{
user.FirstName = userParam.FirstName;
}
if (!string.IsNullOrWhiteSpace(userParam.LastName))
{
user.LastName = userParam.LastName;
}
if (!string.IsNullOrWhiteSpace(currentPassword))
{
if(computeHash(currentPassword) != user.PasswordHash)
{
throw new AppException("Invalid Current password!");
}
if(currentPassword == password)
{
throw new AppException("Please choose another password!");
}
if(password != confirmPassword)
{
throw new AppException("Password doesn't match!");
}
//Updating hashed password into Database table
user.PasswordHash = computeHash(password);
}
_context.User.Update(user);
_context.SaveChanges();
}
public void Delete(int id)
{
var user = _context.User.Find(id);
if (user != null)
{
_context.User.Remove(user);
_context.SaveChanges();
}
}
private static string computeHash(string Password)
{
MD5 md5 = new MD5CryptoServiceProvider();
var input = md5.ComputeHash(Encoding.UTF8.GetBytes(Password));
var hashstring = "";
foreach(var hashbyte in input)
{
hashstring += hashbyte.ToString("x2");
}
return hashstring;
}
}
}
}

18
Shop/Shop.csproj Normal file
View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.12" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.9.0" />
</ItemGroup>
</Project>

143
Shop/Startup.cs Normal file
View File

@ -0,0 +1,143 @@
using System;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Shop.Data;
using Shop.Services;
namespace Shop
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<Context>(opt =>
{
opt.UseMySql(Configuration.GetConnectionString("DefaultConnection"));
});
services.AddCors();
services.AddControllers();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
// configure jwt authentication
var key = Encoding.ASCII.GetBytes(Configuration["Secret"]);
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.Events = new JwtBearerEvents
{
OnTokenValidated = context =>
{
var userService = context.HttpContext.RequestServices.GetRequiredService<UserServices.IUserService>();
var userId = int.Parse(context.Principal.Identity.Name);
var user = userService.GetById(userId);
if (user == null)
{
// return unauthorized if user no longer exists
context.Fail("Unauthorized");
}
return Task.CompletedTask;
}
};
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
});
// configure DI for application services
services.AddScoped<UserServices.IUserService, UserServices.UserService>();
services.AddSwaggerGen(swagger =>
{
//This is to generate the Default UI of Swagger Documentation
swagger.SwaggerDoc("v1", new OpenApiInfo
{
Version= "v1",
Title = "Dorset College API",
Description="Web API"
});
// To Enable authorization using Swagger (JWT)
swagger.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
{
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
});
swagger.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
new string[] {}
}
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API Aurelien " +
"Rebourg"));
}
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Shop")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Shop")]
[assembly: System.Reflection.AssemblyTitleAttribute("Shop")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
a09a70cd7c468cb3fe40bda428f1e1aee9f97668

Binary file not shown.

View File

@ -0,0 +1,101 @@
{
"format": 1,
"restore": {
"/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj": {}
},
"projects": {
"/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj",
"projectName": "Shop",
"projectPath": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj",
"packagesPath": "/home/aurelien/.nuget/packages/",
"outputPath": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/aurelien/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"dependencies": {
"AutoMapper": {
"target": "Package",
"version": "[10.1.1, )"
},
"AutoMapper.Extensions.Microsoft.DependencyInjection": {
"target": "Package",
"version": "[8.1.1, )"
},
"Microsoft.AspNetCore.Authentication.JwtBearer": {
"target": "Package",
"version": "[3.1.12, )"
},
"Microsoft.EntityFrameworkCore": {
"target": "Package",
"version": "[3.1.12, )"
},
"Pomelo.EntityFrameworkCore.MySql": {
"target": "Package",
"version": "[3.1.1, )"
},
"Swashbuckle.AspNetCore": {
"target": "Package",
"version": "[5.6.3, )"
},
"System.IdentityModel.Tokens.Jwt": {
"target": "Package",
"version": "[6.9.0, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[3.1.10, 3.1.10]"
},
{
"name": "Microsoft.NETCore.App.Host.linux-x64",
"version": "[3.1.13, 3.1.13]"
}
],
"frameworkReferences": {
"Microsoft.AspNetCore.App": {
"privateAssets": "none"
},
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/5.0.201/RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/aurelien/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/aurelien/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.5.0</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.extensions.apidescription.server/3.0.0/build/Microsoft.Extensions.ApiDescription.Server.props" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.apidescription.server/3.0.0/build/Microsoft.Extensions.ApiDescription.Server.props')" />
<Import Project="$(NuGetPackageRoot)swashbuckle.aspnetcore/5.6.3/build/Swashbuckle.AspNetCore.props" Condition="Exists('$(NuGetPackageRoot)swashbuckle.aspnetcore/5.6.3/build/Swashbuckle.AspNetCore.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_Extensions_ApiDescription_Server Condition=" '$(PkgMicrosoft_Extensions_ApiDescription_Server)' == '' ">/home/aurelien/.nuget/packages/microsoft.extensions.apidescription.server/3.0.0</PkgMicrosoft_Extensions_ApiDescription_Server>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.extensions.apidescription.server/3.0.0/build/Microsoft.Extensions.ApiDescription.Server.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.apidescription.server/3.0.0/build/Microsoft.Extensions.ApiDescription.Server.targets')" />
</ImportGroup>
</Project>

1576
Shop/obj/project.assets.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,53 @@
{
"version": 2,
"dgSpecHash": "8sTig6C637tbCKDMDIiqIUh3svyl7c6/tGb3DJkjb93izwOgjDqkfUMmnu7pG3K3Xoa5dhBXfHT8m7pCNtSpSg==",
"success": true,
"projectFilePath": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj",
"expectedPackageFiles": [
"/home/aurelien/.nuget/packages/automapper/10.1.1/automapper.10.1.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/automapper.extensions.microsoft.dependencyinjection/8.1.1/automapper.extensions.microsoft.dependencyinjection.8.1.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.aspnetcore.authentication.jwtbearer/3.1.12/microsoft.aspnetcore.authentication.jwtbearer.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/microsoft.bcl.asyncinterfaces.1.1.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.bcl.hashcode/1.1.1/microsoft.bcl.hashcode.1.1.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.csharp/4.7.0/microsoft.csharp.4.7.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.entityframeworkcore/3.1.12/microsoft.entityframeworkcore.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.entityframeworkcore.abstractions/3.1.12/microsoft.entityframeworkcore.abstractions.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.entityframeworkcore.analyzers/3.1.12/microsoft.entityframeworkcore.analyzers.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.entityframeworkcore.relational/3.1.0/microsoft.entityframeworkcore.relational.3.1.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.apidescription.server/3.0.0/microsoft.extensions.apidescription.server.3.0.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.caching.abstractions/3.1.12/microsoft.extensions.caching.abstractions.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.caching.memory/3.1.12/microsoft.extensions.caching.memory.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.configuration/3.1.12/microsoft.extensions.configuration.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.configuration.abstractions/3.1.12/microsoft.extensions.configuration.abstractions.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.configuration.binder/3.1.12/microsoft.extensions.configuration.binder.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.dependencyinjection/3.1.12/microsoft.extensions.dependencyinjection.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.dependencyinjection.abstractions/3.1.12/microsoft.extensions.dependencyinjection.abstractions.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.logging/3.1.12/microsoft.extensions.logging.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.logging.abstractions/3.1.12/microsoft.extensions.logging.abstractions.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.options/3.1.12/microsoft.extensions.options.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.extensions.primitives/3.1.12/microsoft.extensions.primitives.3.1.12.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.identitymodel.jsonwebtokens/6.9.0/microsoft.identitymodel.jsonwebtokens.6.9.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.identitymodel.logging/6.9.0/microsoft.identitymodel.logging.6.9.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.identitymodel.protocols/5.5.0/microsoft.identitymodel.protocols.5.5.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.identitymodel.protocols.openidconnect/5.5.0/microsoft.identitymodel.protocols.openidconnect.5.5.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.identitymodel.tokens/6.9.0/microsoft.identitymodel.tokens.6.9.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.openapi/1.2.3/microsoft.openapi.1.2.3.nupkg.sha512",
"/home/aurelien/.nuget/packages/mysqlconnector/0.61.0/mysqlconnector.0.61.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/newtonsoft.json/11.0.2/newtonsoft.json.11.0.2.nupkg.sha512",
"/home/aurelien/.nuget/packages/pomelo.entityframeworkcore.mysql/3.1.1/pomelo.entityframeworkcore.mysql.3.1.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/pomelo.jsonobject/2.2.1/pomelo.jsonobject.2.2.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/swashbuckle.aspnetcore/5.6.3/swashbuckle.aspnetcore.5.6.3.nupkg.sha512",
"/home/aurelien/.nuget/packages/swashbuckle.aspnetcore.swagger/5.6.3/swashbuckle.aspnetcore.swagger.5.6.3.nupkg.sha512",
"/home/aurelien/.nuget/packages/swashbuckle.aspnetcore.swaggergen/5.6.3/swashbuckle.aspnetcore.swaggergen.5.6.3.nupkg.sha512",
"/home/aurelien/.nuget/packages/swashbuckle.aspnetcore.swaggerui/5.6.3/swashbuckle.aspnetcore.swaggerui.5.6.3.nupkg.sha512",
"/home/aurelien/.nuget/packages/system.collections.immutable/1.7.1/system.collections.immutable.1.7.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/system.componentmodel.annotations/4.7.0/system.componentmodel.annotations.4.7.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/system.diagnostics.diagnosticsource/4.7.1/system.diagnostics.diagnosticsource.4.7.1.nupkg.sha512",
"/home/aurelien/.nuget/packages/system.identitymodel.tokens.jwt/6.9.0/system.identitymodel.tokens.jwt.6.9.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/system.reflection.emit/4.7.0/system.reflection.emit.4.7.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/system.security.cryptography.cng/4.5.0/system.security.cryptography.cng.4.5.0.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.aspnetcore.app.ref/3.1.10/microsoft.aspnetcore.app.ref.3.1.10.nupkg.sha512",
"/home/aurelien/.nuget/packages/microsoft.netcore.app.host.linux-x64/3.1.13/microsoft.netcore.app.host.linux-x64.3.1.13.nupkg.sha512"
],
"logs": []
}

View File

@ -0,0 +1,89 @@
{
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj",
"projectName": "Shop",
"projectPath": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/Shop.csproj",
"outputPath": "/home/aurelien/Bureau/dorset/Dorset-back-master/Homework2/Shop/obj/",
"projectStyle": "PackageReference",
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"dependencies": {
"AutoMapper": {
"target": "Package",
"version": "[10.1.1, )"
},
"AutoMapper.Extensions.Microsoft.DependencyInjection": {
"target": "Package",
"version": "[8.1.1, )"
},
"Microsoft.AspNetCore.Authentication.JwtBearer": {
"target": "Package",
"version": "[3.1.12, )"
},
"Microsoft.EntityFrameworkCore": {
"target": "Package",
"version": "[3.1.12, )"
},
"Pomelo.EntityFrameworkCore.MySql": {
"target": "Package",
"version": "[3.1.1, )"
},
"Swashbuckle.AspNetCore": {
"target": "Package",
"version": "[5.6.3, )"
},
"System.IdentityModel.Tokens.Jwt": {
"target": "Package",
"version": "[6.9.0, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[3.1.10, 3.1.10]"
},
{
"name": "Microsoft.NETCore.App.Host.linux-x64",
"version": "[3.1.13, 3.1.13]"
}
],
"frameworkReferences": {
"Microsoft.AspNetCore.App": {
"privateAssets": "none"
},
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/5.0.201/RuntimeIdentifierGraph.json"
}
}
}