A few changes with this checkin

1. Adding cookies middleware to the music store app
2. Enabling login, register & related management pages to render some UI for testing
3. Updated the LKG.json
This commit is contained in:
Praburaj 2014-04-14 12:35:56 -07:00
parent b37c811266
commit 9127f5b930
11 changed files with 113 additions and 63 deletions

View File

@ -65,6 +65,7 @@ namespace MusicStore.Controllers
// //
// GET: /Account/Register // GET: /Account/Register
[AllowAnonymous] [AllowAnonymous]
[HttpGet] //TODO: Do we need this. Without this I seem to be landing here irrespective of the HTTP verb?
public IActionResult Register() public IActionResult Register()
{ {
return View(); return View();
@ -362,7 +363,7 @@ namespace MusicStore.Controllers
private async Task SignIn(ApplicationUser user, bool isPersistent) private async Task SignIn(ApplicationUser user, bool isPersistent)
{ {
this.Context.Response.SignOut(DefaultAuthenticationTypes.ExternalCookie); //this.Context.Response.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
this.Context.Response.SignIn(identity, new AuthenticationProperties() { IsPersistent = isPersistent }); this.Context.Response.SignIn(identity, new AuthenticationProperties() { IsPersistent = isPersistent });
} }
@ -447,7 +448,7 @@ namespace MusicStore.Controllers
{ {
public static string GetUserId(this IIdentity user) public static string GetUserId(this IIdentity user)
{ {
return string.Empty; return user.Name;
} }
public static Task<ExternalLoginInfo> GetExternalLoginInfo(this HttpResponse response) public static Task<ExternalLoginInfo> GetExternalLoginInfo(this HttpResponse response)

View File

@ -1,33 +1,36 @@
{ {
"version": "0.1-alpha-*", "version": "0.1-alpha-*",
"dependencies": { "dependencies": {
"Helios": "0.1-alpha-243", "Helios": "0.1-alpha-254",
"Microsoft.AspNet.Abstractions": "0.1-alpha-239", "Microsoft.AspNet.Abstractions": "0.1-alpha-249",
"Microsoft.AspNet.Mvc": "0.1-alpha-573", "Microsoft.AspNet.Mvc": "0.1-alpha-599",
"Microsoft.AspNet.Razor": "0.1-alpha-181", "Microsoft.AspNet.Razor": "0.1-alpha-181",
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-174", "Microsoft.AspNet.ConfigurationModel": "0.1-alpha-174",
"Microsoft.AspNet.DependencyInjection": "0.1-alpha-243", "Microsoft.AspNet.DependencyInjection": "0.1-alpha-247",
"Microsoft.AspNet.RequestContainer": "0.1-alpha-243", "Microsoft.AspNet.RequestContainer": "0.1-alpha-250",
"Microsoft.AspNet.Routing": "0.1-alpha-220", "Microsoft.AspNet.Routing": "0.1-alpha-228",
"Microsoft.AspNet.Mvc.ModelBinding": "0.1-alpha-573", "Microsoft.AspNet.Mvc.ModelBinding": "0.1-alpha-599",
"Microsoft.AspNet.Mvc.Core": "0.1-alpha-573", "Microsoft.AspNet.Mvc.Core": "0.1-alpha-599",
"Microsoft.AspNet.Mvc.Razor": "0.1-alpha-573", "Microsoft.AspNet.Mvc.Razor": "0.1-alpha-599",
"Microsoft.AspNet.StaticFiles": "0.1-alpha-180", "Microsoft.AspNet.StaticFiles": "0.1-alpha-188",
"System.Security.Claims": "0.1-alpha-120", "System.Security.Claims": "0.1-alpha-124",
"System.Security.Principal": "4.0.0.0", "System.Security.Principal": "4.0.0.0",
"Microsoft.AspNet.Security.DataProtection": "0.1-alpha-142", "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-142",
"Microsoft.AspNet.Identity": "0.1-alpha-327", "Microsoft.AspNet.Identity": "0.1-alpha-347",
"Microsoft.AspNet.Identity.Entity": "0.1-alpha-327", "Microsoft.AspNet.Identity.Entity": "0.1-alpha-347",
"Microsoft.AspNet.Identity.InMemory": "0.1-alpha-327", "Microsoft.AspNet.Identity.InMemory": "0.1-alpha-347",
"Microsoft.Data.Entity": "0.1-alpha-419", "Microsoft.Data.Entity": "0.1-alpha-432",
"Microsoft.Data.Relational": "0.1-alpha-419", "Microsoft.Data.Relational": "0.1-alpha-432",
"Microsoft.Data.SqlServer": "0.1-pre-419", "Microsoft.Data.SqlServer": "0.1-pre-419",
"Microsoft.Data.InMemory": "0.1-alpha-419", "Microsoft.Data.InMemory": "0.1-alpha-432",
"Microsoft.Data.Migrations": "0.1-alpha-419", "Microsoft.Data.Migrations": "0.1-alpha-432",
"Microsoft.AspNet.Diagnostics": "0.1-alpha-124", "Microsoft.AspNet.Diagnostics": "0.1-alpha-133",
"Microsoft.AspNet.Hosting": "0.1-alpha-243", "Microsoft.AspNet.Hosting": "0.1-alpha-250",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-180", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-193",
"Microsoft.AspNet.Configuration.Json": "0.1-alpha-174" "Microsoft.AspNet.Configuration.Json": "0.1-alpha-174",
"Microsoft.AspNet.Security": "0.1-alpha-102",
"Microsoft.AspNet.Security.Cookies": "0.1-alpha-102",
"Microsoft.AspNet.Logging": "0.1-alpha-159"
}, },
"configurations": { "configurations": {
"net45": { "net45": {

View File

@ -0,0 +1,12 @@
using Microsoft.AspNet.Logging;
using System;
namespace MusicStore.Logging
{
public class NullLogger : ILogger
{
public bool WriteCore(TraceType eventType, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{
return false;
}
}
}

View File

@ -0,0 +1,11 @@
using Microsoft.AspNet.Logging;
namespace MusicStore.Logging
{
public class NullLoggerFactory : ILoggerFactory
{
public ILogger Create(string name)
{
return new NullLogger();
}
}
}

View File

@ -1,23 +1,23 @@
using Microsoft.AspNet; using Microsoft.AspNet;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.Configuration.Json; using Microsoft.AspNet.Configuration.Json;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.DependencyInjection.NestedProviders;
using Microsoft.AspNet.RequestContainer;
using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.InMemory; using Microsoft.AspNet.Identity.InMemory;
using Microsoft.AspNet.Logging;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.RequestContainer;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security.Cookies;
using Microsoft.Net.Runtime;
using MusicStore.Logging;
using MusicStore.Models; using MusicStore.Models;
using MusicStore.Web.Models; using MusicStore.Web.Models;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection;
using Microsoft.Net.Runtime;
public class Startup public class Startup
{ {
@ -28,14 +28,22 @@ public class Startup
//ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. //ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseErrorPage(ErrorPageOptions.ShowAll);
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<ILoggerFactory>(new NullLoggerFactory());
serviceCollection.Add(MvcServices.GetDefaultServices());
app.UseContainer(serviceCollection.BuildServiceProvider(app.ServiceProvider));
app.UseFileServer(); app.UseFileServer();
var serviceProvider = MvcServices.GetDefaultServices().BuildServiceProvider(app.ServiceProvider); app.UseCookieAuthentication(new CookieAuthenticationOptions()
app.UseContainer(serviceProvider); {
AuthenticationType = "Application",
LoginPath = new PathString("/Account/Login")
});
var routes = new RouteCollection() var routes = new RouteCollection()
{ {
DefaultHandler = new MvcApplication(serviceProvider), DefaultHandler = new MvcApplication(app.ServiceProvider),
}; };
routes.MapRoute( routes.MapRoute(

View File

@ -12,29 +12,32 @@
<section id="loginForm"> <section id="loginForm">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{ {
@Html.AntiForgeryToken() @*@Html.AntiForgeryToken()*@
<h4>Use a local account to log in.</h4> <h4>Use a local account to log in.</h4>
<hr /> <hr />
@Html.ValidationSummary(true) @Html.ValidationSummary(true)
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">UserName:</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" }) @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName) @*@Html.ValidationMessageFor(m => m.UserName)*@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">Password:</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" }) @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Password) @*@Html.ValidationMessageFor(m => m.Password)*@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-offset-2 col-md-10"> <div class="col-md-offset-2 col-md-10">
<div class="checkbox"> <div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe) @Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe) @*@Html.LabelFor(m => m.RememberMe)*@
<label>Remember Me</label>
</div> </div>
</div> </div>
</div> </div>
@ -49,11 +52,12 @@
} }
</section> </section>
</div> </div>
<div class="col-md-4">
<section id="socialLoginForm"> @*<div class="col-md-4">
@Html.Partial("_ExternalLoginsListPartial", new { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl }) <section id="socialLoginForm">
</section> @Html.Partial("_ExternalLoginsListPartial", new { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })
</div> </section>
</div>*@
</div> </div>
@section Scripts { @section Scripts {
@*Bug : Script helpers are out of scope for alpha*@ @*Bug : Script helpers are out of scope for alpha*@

View File

@ -7,23 +7,23 @@
} }
<h2>@ViewBag.Title.</h2> <h2>@ViewBag.Title.</h2>
<p class="text-success">@ViewBag.StatusMessage</p> <p class="text-success">@ViewBag.StatusMessage</p>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@if (ViewBag.HasLocalPassword) @if (ViewBag.HasLocalPassword)
{ {
@Html.Partial("_ChangePasswordPartial") await Html.PartialAsync("_ChangePasswordPartial");
} }
else else
{ {
@Html.Partial("_SetPasswordPartial") await Html.PartialAsync("_SetPasswordPartial");
} }
<section id="externalLogins"> @*<section id="externalLogins">
@Html.Action("RemoveAccountList") @Html.Action("RemoveAccountList")
@Html.Partial("_ExternalLoginsListPartial", new { Action = "LinkLogin", ReturnUrl = ViewBag.ReturnUrl }) @Html.Partial("_ExternalLoginsListPartial", new { Action = "LinkLogin", ReturnUrl = ViewBag.ReturnUrl })
</section> </section>*@
</div> </div>
</div> </div>

View File

@ -9,26 +9,29 @@
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{ {
@Html.AntiForgeryToken() @*@Html.AntiForgeryToken()*@
<h4>Create a new account.</h4> <h4>Create a new account.</h4>
<hr /> <hr />
@Html.ValidationSummary() @Html.ValidationSummary()
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">UserName</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" }) @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" }) @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">Confirm Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" }) @*@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })*@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@ -1,28 +1,31 @@
@using Microsoft.AspNet.Identity @using Microsoft.AspNet.Identity
@model MusicStore.Models.ManageUserViewModel @model MusicStore.Models.ManageUserViewModel
<p>You're logged in as <strong>@User.Identity.GetUserName()</strong>.</p> <p>You're logged in as <strong>@Context.HttpContext.User.Identity.Name</strong>.</p>
@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) @using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{ {
@Html.AntiForgeryToken() @*@Html.AntiForgeryToken()*@
<h4>Change Password Form</h4> <h4>Change Password Form</h4>
<hr /> <hr />
@Html.ValidationSummary() @Html.ValidationSummary()
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.OldPassword, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.OldPassword, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">Old Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.OldPassword, new { @class = "form-control" }) @Html.PasswordFor(m => m.OldPassword, new { @class = "form-control" })
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">New Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" }) @Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" })
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">Confirm Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" }) @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
</div> </div>

View File

@ -7,19 +7,21 @@
@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) @using (Html.BeginForm("Manage", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{ {
@Html.AntiForgeryToken() @*@Html.AntiForgeryToken()*@
<h4>Create Local Login</h4> <h4>Create Local Login</h4>
<hr /> <hr />
@Html.ValidationSummary() @Html.ValidationSummary()
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">New Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" }) @Html.PasswordFor(m => m.NewPassword, new { @class = "form-control" })
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" }) @*@Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })*@
<label class="col-md-2 control-label">Confirm Password</label>
<div class="col-md-10"> <div class="col-md-10">
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" }) @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
</div> </div>

View File

@ -27,7 +27,10 @@
"Microsoft.AspNet.Diagnostics": "0.1-alpha-*", "Microsoft.AspNet.Diagnostics": "0.1-alpha-*",
"Microsoft.AspNet.Hosting": "0.1-alpha-*", "Microsoft.AspNet.Hosting": "0.1-alpha-*",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*", "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*",
"Microsoft.AspNet.Configuration.Json": "0.1-alpha-*" "Microsoft.AspNet.Configuration.Json": "0.1-alpha-*",
"Microsoft.AspNet.Security": "0.1-alpha-*",
"Microsoft.AspNet.Security.Cookies": "0.1-alpha-*",
"Microsoft.AspNet.Logging": "0.1-alpha-*"
}, },
"commands": { "commands": {
"web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"