-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
9199aa5
commit 91c2420
Showing
9 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
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 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 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,8 @@ | ||
namespace Wordle.Api.Identity; | ||
|
||
public static class Claims | ||
{ | ||
public const string Random = "Random"; | ||
public const string BirthDate = "BirthDate"; | ||
} | ||
|
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 |
---|---|---|
|
@@ -23,6 +23,11 @@ private static async Task SeedRolesAsync(RoleManager<IdentityRole> roleManager) | |
{ | ||
await roleManager.CreateAsync(new IdentityRole(Roles.Admin)); | ||
} | ||
// Seed Roles | ||
if (!await roleManager.RoleExistsAsync(Roles.Awesome)) | ||
{ | ||
await roleManager.CreateAsync(new IdentityRole(Roles.Awesome)); | ||
} | ||
} | ||
|
||
private static async Task SeedAdminUserAsync(UserManager<AppUser> userManager) | ||
|
@@ -43,5 +48,21 @@ private static async Task SeedAdminUserAsync(UserManager<AppUser> userManager) | |
await userManager.AddToRoleAsync(user, Roles.Admin); | ||
} | ||
} | ||
|
||
if (await userManager.FindByEmailAsync("[email protected]") == null) | ||
{ | ||
AppUser user = new AppUser | ||
{ | ||
UserName = "[email protected]", | ||
Email = "[email protected]" | ||
}; | ||
|
||
IdentityResult result = userManager.CreateAsync(user, "P@ssw0rd123").Result; | ||
|
||
if (result.Succeeded) | ||
{ | ||
await userManager.AddToRoleAsync(user, Roles.Awesome); | ||
} | ||
} | ||
} | ||
} |
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,24 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using System.Security.Claims; | ||
using System.ComponentModel; | ||
|
||
namespace Wordle.Api.Identity; | ||
public static class Policies | ||
{ | ||
public const string RandomAdmin = "RandomAdmin"; | ||
|
||
public static void RandomAdminPolicy(AuthorizationPolicyBuilder policy) | ||
{ | ||
policy.RequireRole(Roles.Admin); | ||
policy.RequireAssertion(context => | ||
{ | ||
var random = context.User.Claims.FirstOrDefault(c => c.Type == Claims.Random); | ||
if (Double.TryParse(random?.Value, out double result)) | ||
{ | ||
return result > 0.5; | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
public static class Roles | ||
{ | ||
public const string Admin = "Admin"; | ||
public const string Awesome = "Awesome"; | ||
} |
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 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 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