-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
778 changed files
with
41,371 additions
and
37,177 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.