MusicStore.Spa fixes:

- Flow app claims to client code properly
- Remove unnecessary JS link
- Fix JS links on login page
This commit is contained in:
DamianEdwards 2014-10-23 18:06:40 -07:00
parent a2e005c017
commit 05237d908e
10 changed files with 31 additions and 20 deletions

View File

@ -70,7 +70,7 @@ namespace MusicStore.Apis
}
[HttpPost]
[Authorize("ManageStore", "Allowed")]
[Authorize("app-ManageStore", "Allowed")]
public async Task<ActionResult> CreateAlbum()
{
var album = new Album();
@ -96,7 +96,7 @@ namespace MusicStore.Apis
}
[HttpPut("{albumId:int}/update")]
[Authorize("ManageStore", "Allowed")]
[Authorize("app-ManageStore", "Allowed")]
public async Task<ActionResult> UpdateAlbum(int albumId)
{
var album = _storeContext.Albums.SingleOrDefault(a => a.AlbumId == albumId);
@ -129,7 +129,7 @@ namespace MusicStore.Apis
}
[HttpDelete("{albumId:int}")]
[Authorize("ManageStore", "Allowed")]
[Authorize("app-ManageStore", "Allowed")]
public async Task<ActionResult> DeleteAlbum(int albumId)
{
//var album = await _storeContext.Albums.SingleOrDefaultAsync(a => a.AlbumId == albumId);

View File

@ -13,7 +13,7 @@ namespace MusicStore.Spa.Controllers
}
[HttpGet("admin")]
[Authorize("ManageStore", "Allowed")]
[Authorize("app-ManageStore", "Allowed")]
public IActionResult Admin()
{
return View("/Pages/Admin.cshtml");

View File

@ -56,7 +56,7 @@ namespace MusicStore.Models
user = new ApplicationUser { UserName = settings.DefaultAdminUsername };
await userManager.CreateAsync(user, settings.DefaultAdminPassword);
await userManager.AddToRoleAsync(user, adminRole);
await userManager.AddClaimAsync(user, new Claim("ManageStore", "Allowed"));
await userManager.AddClaimAsync(user, new Claim("app-ManageStore", "Allowed"));
}
}

View File

@ -17,7 +17,6 @@
<script src="~/lib/angular/angular.js"></script>
<script src="~/lib/angular-route/angular-route.js"></script>
<script src="~/lib/angular-bootstrap/ui-bootstrap.js"></script>
<script src="~/lib/angular-bootstrap/ui-bootstrap-tpls.js"></script>
@* TODO: This is currently all the compiled TypeScript, non-minified. Need to explore options
for alternate loading schemes, e.g. AMD loader of individual modules, min vs. non-min, etc. *@

View File

@ -96,8 +96,8 @@
@*@Scripts.Render("~/bundles/jqueryval")*@
@*<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>*@
<script src="~/js/angular.js"></script>
<script src="~/js/angular-route.js"></script>
<script src="~/lib/angular/angular.js"></script>
<script src="~/lib/angular-route/angular-route.js"></script>
@* TODO: This is currently all the compiled TypeScript, non-minified. Need to explore options
for alternate loading schemes, e.g. AMD loader of individual modules, min vs. non-min, etc. *@
<script src="~/js/MusicStore.Store.js"></script>

View File

@ -1,4 +1,5 @@
@using System.Security.Principal
@using System.Security.Claims
@using Microsoft.AspNet.Identity
@{
@ -18,15 +19,18 @@
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
@*@Html.Json(new {
@Html.Json(new {
isAuthenticated = true,
userName = User.Identity.GetUserName(),
userId = User.Identity.GetUserId(),
roles = ((System.Security.Claims.ClaimsPrincipal)User).Claims
.Where(c => c.Type == System.Security.Claims.ClaimTypes.Role)
.Select(role => role.Value)
roles = ((ClaimsPrincipal)User).Claims
.Where(c => c.Type == ClaimTypes.Role)
.Select(role => role.Value),
claims = ((ClaimsPrincipal)User).Claims
.Where(c => c.Type.StartsWith("app-", StringComparison.OrdinalIgnoreCase))
.Select(role => new { role.Type, role.Value })
},
new { id = "userDetails" })*@
new { id = "userDetails" })
}
}
else
@ -36,11 +40,11 @@ else
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink", app_login_link = "" })</li>
</ul>
@*@Html.Json(new {
@Html.Json(new {
isAuthenticated = false,
userName = (string)null,
userId = (string)null,
roles = Enumerable.Empty<string>()
},
new { id = "userDetails" })*@
new { id = "userDetails" })
}

View File

@ -4,7 +4,7 @@
<h2>Album <small>{{ viewModel.mode | titlecase }}</small></h2>
<hr />
<alert ng-show="viewModel.alert" type="{{ viewModel.alert.type.toString() }}" close="viewModel.clearAlert()">
<alert ng-show="viewModel.alert" type="{{ viewModel.alert.type.value }}" close="viewModel.clearAlert()">
{{ viewModel.alert.message }}
<ul ng-show="viewModel.alert.modelErrors">
<li ng-repeat="modelError in viewModel.alert.modelErrors">{{ modelError.ErrorMessage }}</li>

View File

@ -6,7 +6,7 @@
<a class="btn btn-default" href="#/albums/new">Create new</a>
</p>
<alert ng-show="viewModel.alert" type="{{ viewModel.alert.type.toString() }}" close="viewModel.clearAlert()">
<alert ng-show="viewModel.alert" type="{{ viewModel.alert.type.value }}" close="viewModel.clearAlert()">
{{ viewModel.alert.message }}
<ul ng-show="viewModel.alert.modelErrors">
<li ng-repeat="modelError in viewModel.alert.modelErrors">{{ modelError.ErrorMessage }}</li>

View File

@ -37,7 +37,7 @@ module MusicStore.Admin {
}
// Use this method to register work which should be performed when the injector is done loading all modules.
//function BUG:run() {
//}
function run($log: ng.ILogService, userDetails: UserDetails.IUserDetailsService) {
$log.log(userDetails.getUserDetails());
}
}

View File

@ -1028,6 +1028,10 @@ var MusicStore;
"$routeProvider",
"$logProvider",
configuration
]).run([
"$log",
"MusicStore.UserDetails.IUserDetailsService",
run
]);
var dependencies = [
@ -1053,6 +1057,10 @@ var MusicStore;
$routeProvider.when("/albums/:albumId/details", { templateUrl: "ng-apps/MusicStore.Admin/Catalog/AlbumDetails.cshtml" }).when("/albums/:albumId/:mode", { templateUrl: "ng-apps/MusicStore.Admin/Catalog/AlbumEdit.cshtml" }).when("/albums/:mode", { templateUrl: "ng-apps/MusicStore.Admin/Catalog/AlbumEdit.cshtml" }).when("/albums", { templateUrl: "ng-apps/MusicStore.Admin/Catalog/AlbumList.cshtml" }).otherwise({ redirectTo: "/albums" });
}
function run($log, userDetails) {
$log.log(userDetails.getUserDetails());
}
})(MusicStore.Admin || (MusicStore.Admin = {}));
var Admin = MusicStore.Admin;
})(MusicStore || (MusicStore = {}));