nettoyages de code

main
Paul Schneider 10 years ago
parent bc0f7cbafd
commit 2b5951fd4a
7 changed files with 31 additions and 13 deletions

@ -1,7 +1,6 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;

@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
namespace Yavsc.Migrations namespace Yavsc.Migrations

@ -1,8 +1,6 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;
namespace Yavsc.Migrations namespace Yavsc.Migrations

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Authorization;
@ -57,6 +59,28 @@ namespace Yavsc.Controllers
} }
return Ok(new {message="you owned it."}); return Ok(new {message="you owned it."});
} }
public class RoleInfo {
public string Name { get; set; }
public IEnumerable<string> Users { get; set; }
}
[Authorize(Roles=Constants.AdminGroupName)]
[Produces("application/json")]
public async Task<IActionResult> 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) private void AddErrors(IdentityResult result)
{ {

@ -86,6 +86,7 @@ namespace Yavsc.Controllers
var user = await GetCurrentUserAsync(); var user = await GetCurrentUserAsync();
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id); long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
var model = new IndexViewModel var model = new IndexViewModel
{ {
HasPassword = await _userManager.HasPasswordAsync(user), HasPassword = await _userManager.HasPasswordAsync(user),

@ -1,8 +1,4 @@
using System; namespace Yavsc
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Yavsc
{ {
public class SiteSettings public class SiteSettings
{ {

@ -407,7 +407,6 @@ namespace Yavsc
options.LogoutPath = new PathString("/signout"); options.LogoutPath = new PathString("/signout");
}); });
branch.UseMiddleware<GoogleMiddleware>(googleOptions); branch.UseMiddleware<GoogleMiddleware>(googleOptions);
// Facebook // Facebook
@ -420,9 +419,11 @@ namespace Yavsc
}); });
}); });
var authProvider = new AuthorizationProvider(loggerFactory);
app.UseOpenIdConnectServer(options => app.UseOpenIdConnectServer(options =>
{ {
options.Provider = new AuthorizationProvider(loggerFactory); options.Provider = authProvider;
// Register the certificate used to sign the JWT tokens. // Register the certificate used to sign the JWT tokens.
/* options.SigningCredentials.AddCertificate( /* options.SigningCredentials.AddCertificate(
@ -442,6 +443,7 @@ namespace Yavsc
options.AllowInsecureHttp = true; options.AllowInsecureHttp = true;
options.AuthenticationScheme = "oidc"; // was = OpenIdConnectDefaults.AuthenticationScheme; options.AuthenticationScheme = "oidc"; // was = OpenIdConnectDefaults.AuthenticationScheme;
options.LogoutEndpointPath = new PathString("/connect/logout"); options.LogoutEndpointPath = new PathString("/connect/logout");
/* options.ValidationEndpointPath = new PathString("/connect/introspect"); */ /* options.ValidationEndpointPath = new PathString("/connect/introspect"); */
}); });

Loading…