From 604ee33e1d6ebab48e779ab6b555151ac72aacdb Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 4 Aug 2016 13:40:39 +0200 Subject: [PATCH] =?UTF-8?q?cr=C3=A9er=20les=20r=C3=B4les=20au=20d=C3=A9mar?= =?UTF-8?q?rage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yavsc/Startup/Startup.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index b9583d07..2853b773 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -2,12 +2,15 @@ using System; using System.Globalization; using System.Reflection; +using System.Threading.Tasks; using System.Web.Optimization; using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Localization; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Filters; @@ -225,6 +228,7 @@ namespace Yavsc IOptions siteSettings, IOptions localizationOptions, IOptions oauth2SettingsContainer, + RoleManager _roleManager, ILoggerFactory loggerFactory) { Startup.UserFilesDirName = siteSettings.Value.UserFiles.DirName; @@ -275,7 +279,23 @@ namespace Yavsc else throw ex; } } - + Task.Run(async ()=>{ + foreach (string roleName in new string[] {Constants.AdminGroupName, + Constants.StarGroupName, Constants.PerformerGroupName, + Constants.StarHunterGroupName + }) + if (!await _roleManager.RoleExistsAsync(roleName)) + { + var role = new IdentityRole { Name = roleName }; + var resultCreate = await _roleManager.CreateAsync(role); + if (!resultCreate.Succeeded) + { + throw new Exception("The role '{roleName}' does not exist and could not be created."); + } + } + }); + + app.UseIISPlatformHandler(options => { options.AuthenticationDescriptions.Clear();