From 2b5951fd4a7ad1770b8674c047a72b7aacecf1eb Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 30 May 2016 13:53:56 +0200 Subject: [PATCH] nettoyages de code --- ...60529205859_ModeratorGroupName.Designer.cs | 1 - .../20160529205859_ModeratorGroupName.cs | 2 -- .../ApplicationDbContextModelSnapshot.cs | 2 -- .../Controllers/AdministrationController.cs | 24 +++++++++++++++++++ Yavsc/src/Controllers/ManageController.cs | 1 + Yavsc/src/Settings/SiteSettings.cs | 6 +---- Yavsc/src/Startup.cs | 8 ++++--- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Yavsc/Migrations/20160529205859_ModeratorGroupName.Designer.cs b/Yavsc/Migrations/20160529205859_ModeratorGroupName.Designer.cs index 2a68b9b0..7fb19c93 100644 --- a/Yavsc/Migrations/20160529205859_ModeratorGroupName.Designer.cs +++ b/Yavsc/Migrations/20160529205859_ModeratorGroupName.Designer.cs @@ -1,7 +1,6 @@ using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Infrastructure; -using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Migrations; using Yavsc.Models; diff --git a/Yavsc/Migrations/20160529205859_ModeratorGroupName.cs b/Yavsc/Migrations/20160529205859_ModeratorGroupName.cs index b2640adf..e172ea24 100644 --- a/Yavsc/Migrations/20160529205859_ModeratorGroupName.cs +++ b/Yavsc/Migrations/20160529205859_ModeratorGroupName.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using Microsoft.Data.Entity.Migrations; namespace Yavsc.Migrations diff --git a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs index f596c3f9..666c4d69 100644 --- a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,8 +1,6 @@ using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Infrastructure; -using Microsoft.Data.Entity.Metadata; -using Microsoft.Data.Entity.Migrations; using Yavsc.Models; namespace Yavsc.Migrations diff --git a/Yavsc/src/Controllers/AdministrationController.cs b/Yavsc/src/Controllers/AdministrationController.cs index 9f1d402c..82d0f08f 100644 --- a/Yavsc/src/Controllers/AdministrationController.cs +++ b/Yavsc/src/Controllers/AdministrationController.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; +using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Authorization; @@ -57,6 +59,28 @@ namespace Yavsc.Controllers } return Ok(new {message="you owned it."}); } + public class RoleInfo { + public string Name { get; set; } + public IEnumerable Users { get; set; } + } + [Authorize(Roles=Constants.AdminGroupName)] + [Produces("application/json")] + public async Task Index() { + var adminCount = await _userManager.GetUsersInRoleAsync( + Constants.AdminGroupName); + var youAreAdmin = await _userManager.IsInRoleAsync( + await _userManager.FindByIdAsync(User.GetUserId()), + Constants.AdminGroupName); + var roles = _roleManager.Roles.Select(x=> + new RoleInfo { + Name = x.Name, + Users = x.Users.Select( u=>u.UserId ) + } ); + return Ok (new { Roles = roles, AdminCount = adminCount.Count, + YouAreAdmin = youAreAdmin + }); + } + private void AddErrors(IdentityResult result) { diff --git a/Yavsc/src/Controllers/ManageController.cs b/Yavsc/src/Controllers/ManageController.cs index 2a6b3b57..b9dd291a 100644 --- a/Yavsc/src/Controllers/ManageController.cs +++ b/Yavsc/src/Controllers/ManageController.cs @@ -86,6 +86,7 @@ namespace Yavsc.Controllers var user = await GetCurrentUserAsync(); long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id); + var model = new IndexViewModel { HasPassword = await _userManager.HasPasswordAsync(user), diff --git a/Yavsc/src/Settings/SiteSettings.cs b/Yavsc/src/Settings/SiteSettings.cs index 4d90978f..a9d8218a 100644 --- a/Yavsc/src/Settings/SiteSettings.cs +++ b/Yavsc/src/Settings/SiteSettings.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace Yavsc +namespace Yavsc { public class SiteSettings { diff --git a/Yavsc/src/Startup.cs b/Yavsc/src/Startup.cs index 7d4ef1a8..cfa6a1f1 100755 --- a/Yavsc/src/Startup.cs +++ b/Yavsc/src/Startup.cs @@ -407,7 +407,6 @@ namespace Yavsc options.LogoutPath = new PathString("/signout"); }); - branch.UseMiddleware(googleOptions); // Facebook @@ -420,10 +419,12 @@ namespace Yavsc }); }); + var authProvider = new AuthorizationProvider(loggerFactory); + app.UseOpenIdConnectServer(options => { - options.Provider = new AuthorizationProvider(loggerFactory); - + options.Provider = authProvider; + // Register the certificate used to sign the JWT tokens. /* options.SigningCredentials.AddCertificate( assembly: typeof(Startup).GetTypeInfo().Assembly, @@ -442,6 +443,7 @@ namespace Yavsc options.AllowInsecureHttp = true; options.AuthenticationScheme = "oidc"; // was = OpenIdConnectDefaults.AuthenticationScheme; options.LogoutEndpointPath = new PathString("/connect/logout"); + /* options.ValidationEndpointPath = new PathString("/connect/introspect"); */ });