Skip to content

Commit

Permalink
project commit v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dim145 committed Jun 10, 2022
1 parent bcf60f6 commit 937dca9
Show file tree
Hide file tree
Showing 778 changed files with 41,371 additions and 37,177 deletions.
Empty file added .editorconfig
Empty file.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ _[Ss]cripts
*.ncrunchsolution
*.dot[Cc]over
/AnimeSearch/wwwroot/.well-known
/AnimeSearch/wwwroot/sitemap.xml
*.v1
.dtbcache.v2

#########
# Rider #
#########
/.idea/
1 change: 0 additions & 1 deletion .idea/.idea.AnimeSearch/.idea/.name

This file was deleted.

16 changes: 16 additions & 0 deletions .vs/AnimeSearch/project-colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Version": 1,
"ProjectMap": {
"233fb6b9-81ab-4c9b-bf25-5b5b7051393b": {
"ProjectGuid": "233fb6b9-81ab-4c9b-bf25-5b5b7051393b",
"DisplayName": "AnimeSearch",
"ColorIndex": 0
},
"a2fe74e1-b743-11d0-ae1a-00a0c90fffc3": {
"ProjectGuid": "a2fe74e1-b743-11d0-ae1a-00a0c90fffc3",
"DisplayName": "Fichiers divers",
"ColorIndex": -1
}
},
"NextColorIndex": 1
}
13 changes: 10 additions & 3 deletions AnimeSearch.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimeSearch", "AnimeSearch\AnimeSearch.csproj", "{233FB6B9-81AB-4C9B-BF25-5B5B7051393B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnimeSearch", "AnimeSearch\AnimeSearch.csproj", "{233FB6B9-81AB-4C9B-BF25-5B5B7051393B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3AF840B5-45F6-4859-B6B7-D57606F607C5}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
276 changes: 264 additions & 12 deletions AnimeSearch/AnimeSearch.csproj

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions AnimeSearch/Attributes/LevelAuthorize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using AnimeSearch.Database;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AnimeSearch.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]

public class LevelAuthorize : Attribute, IAsyncAuthorizationFilter
{
private readonly int niveauActuel;

public LevelAuthorize(int niveauActuel = 0) => this.niveauActuel = niveauActuel;

public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
if(!context.HttpContext.User.Identity.IsAuthenticated)
{
var accept = context.HttpContext.Request.Headers.Accept.ToString();

if (accept.Contains("html") || accept.Equals("*/*"))
context.Result = new RedirectToActionResult("LoginGet", "Identity", new {returnUrl = context.HttpContext.Request.Path});
else
context.Result = new UnauthorizedResult();

return;
}

var _userManager = (UserManager<Users>) context.HttpContext.RequestServices.GetService(typeof(UserManager<Users>));
var _roleManager = (RoleManager<Roles>) context.HttpContext.RequestServices.GetService(typeof(RoleManager<Roles>));

Users currentUser = await _userManager.FindByNameAsync(context.HttpContext.User.Identity.Name);
List<Roles> roles = (await _userManager.GetRolesAsync(currentUser)).Select(r => _roleManager.FindByNameAsync(r).GetAwaiter().GetResult()).ToList();

if (roles.Contains(Utilities.SUPER_ADMIN_ROLE))
{
return;
}

if (roles.Max(r => r.NiveauAutorisation) < niveauActuel)
context.Result = new UnauthorizedResult();
}
}
}
Loading

0 comments on commit 937dca9

Please sign in to comment.