Account controller using Kidentity
- Uncomment account controller and switch to KIdentity
This commit is contained in:
parent
2f8c4b213a
commit
169ffaa062
|
|
@ -1,425 +1,423 @@
|
||||||
//using System;
|
using System;
|
||||||
//using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
//using System.Linq;
|
using System.Linq;
|
||||||
//using System.Security.Claims;
|
using System.Net;
|
||||||
//using System.Threading.Tasks;
|
#if NET45
|
||||||
//using System.Web;
|
using System.Security.Claims;
|
||||||
//using System.Web.Mvc;
|
#else
|
||||||
//using Microsoft.AspNet.Identity;
|
using System.Security.ClaimsK;
|
||||||
//using Microsoft.AspNet.Identity.EntityFramework;
|
#endif
|
||||||
//using Microsoft.AspNet.Mvc;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Abstractions;
|
||||||
|
using Microsoft.AspNet.Identity;
|
||||||
|
using Microsoft.AspNet.Identity.InMemory;
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
//using Microsoft.Owin.Security;
|
//using Microsoft.Owin.Security;
|
||||||
//using MvcMusicStore.Models;
|
using MvcMusicStore.Models;
|
||||||
|
|
||||||
//namespace MvcMusicStore.Controllers
|
namespace MvcMusicStore.Controllers
|
||||||
//{
|
{
|
||||||
// [Authorize]
|
//[Authorize]
|
||||||
// public class AccountController : Controller
|
public class AccountController : Controller
|
||||||
// {
|
{
|
||||||
// public AccountController()
|
public AccountController()
|
||||||
// : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
|
: this(new UserManager<ApplicationUser, string>(new InMemoryUserStore<ApplicationUser>()))
|
||||||
// {
|
{
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public AccountController(UserManager<ApplicationUser> userManager)
|
public AccountController(UserManager<ApplicationUser, string> userManager)
|
||||||
// {
|
{
|
||||||
// UserManager = userManager;
|
UserManager = userManager;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public UserManager<ApplicationUser> UserManager { get; private set; }
|
public UserManager<ApplicationUser, string> UserManager { get; private set; }
|
||||||
|
|
||||||
// private void MigrateShoppingCart(string UserName)
|
private void MigrateShoppingCart(string userName)
|
||||||
// {
|
{
|
||||||
// var storeDb = new MusicStoreEntities();
|
//var storeDb = new MusicStoreEntities();
|
||||||
|
|
||||||
// // Associate shopping cart items with logged-in user
|
// Associate shopping cart items with logged-in user
|
||||||
// var cart = ShoppingCart.GetCart(storeDb, this.HttpContext);
|
//var cart = ShoppingCart.GetCart(storeDb, this.HttpContext);
|
||||||
// cart.MigrateCart(UserName);
|
//cart.MigrateCart(userName);
|
||||||
// storeDb.SaveChanges();
|
//storeDb.SaveChanges();
|
||||||
|
|
||||||
// Session[ShoppingCart.CartSessionKey] = UserName;
|
//Session[ShoppingCart.CartSessionKey] = userName;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // GET: /Account/Login
|
// GET: /Account/Login
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// public IActionResult Login(string returnUrl)
|
public IActionResult Login(string returnUrl)
|
||||||
// {
|
{
|
||||||
// ViewBag.ReturnUrl = returnUrl;
|
ViewBag.ReturnUrl = returnUrl;
|
||||||
// return View();
|
return View();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/Login
|
// POST: /Account/Login
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
|
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
|
||||||
// {
|
{
|
||||||
// if (ModelState.IsValid)
|
//if (ModelState.IsValid)
|
||||||
// {
|
//{
|
||||||
// var user = await UserManager.FindAsync(model.UserName, model.Password);
|
var user = await UserManager.Find(model.UserName, model.Password);
|
||||||
// if (user != null)
|
if (user != null)
|
||||||
// {
|
{
|
||||||
// await SignInAsync(user, model.RememberMe);
|
await SignIn(user, model.RememberMe);
|
||||||
// return RedirectToLocal(returnUrl);
|
return RedirectToLocal(returnUrl);
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// ModelState.AddModelError("", "Invalid username or password.");
|
// ModelState.AddModelError("", "Invalid username or password.");
|
||||||
// }
|
}
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// // If we got this far, something failed, redisplay form
|
// If we got this far, something failed, redisplay form
|
||||||
// return View(model);
|
return View(model);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // GET: /Account/Register
|
// GET: /Account/Register
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// public IActionResult Register()
|
public IActionResult Register()
|
||||||
// {
|
{
|
||||||
// return View();
|
return View();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/Register
|
// POST: /Account/Register
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public async Task<IActionResult> Register(RegisterViewModel model)
|
public async Task<IActionResult> Register(RegisterViewModel model)
|
||||||
// {
|
{
|
||||||
// if (ModelState.IsValid)
|
//if (ModelState.IsValid)
|
||||||
// {
|
//{
|
||||||
// var user = new ApplicationUser() { UserName = model.UserName };
|
var user = new ApplicationUser() { UserName = model.UserName };
|
||||||
// var result = await UserManager.CreateAsync(user, model.Password);
|
var result = await UserManager.Create(user, model.Password);
|
||||||
// if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
// {
|
{
|
||||||
// await SignInAsync(user, isPersistent: false);
|
await SignIn(user, isPersistent: false);
|
||||||
// return RedirectToAction("Index", "Home");
|
return null;//RedirectToAction("Index", "Home");
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// AddErrors(result);
|
AddErrors(result);
|
||||||
// }
|
}
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// // If we got this far, something failed, redisplay form
|
// If we got this far, something failed, redisplay form
|
||||||
// return View(model);
|
return View(model);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/Disassociate
|
// POST: /Account/Disassociate
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public async Task<IActionResult> Disassociate(string loginProvider, string providerKey)
|
public async Task<IActionResult> Disassociate(string loginProvider, string providerKey)
|
||||||
// {
|
{
|
||||||
// ManageMessageId? message = null;
|
ManageMessageId? message = null;
|
||||||
// IdentityResult result = await UserManager.RemoveLoginAsync(User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey));
|
IdentityResult result = await UserManager.RemoveLogin(null /*User.Identity.GetUserId()*/, new UserLoginInfo(loginProvider, providerKey));
|
||||||
// if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
// {
|
{
|
||||||
// message = ManageMessageId.RemoveLoginSuccess;
|
message = ManageMessageId.RemoveLoginSuccess;
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// message = ManageMessageId.Error;
|
message = ManageMessageId.Error;
|
||||||
// }
|
}
|
||||||
// return RedirectToAction("Manage", new { Message = message });
|
return null;//RedirectToAction("Manage", new { Message = message });
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // GET: /Account/Manage
|
// GET: /Account/Manage
|
||||||
// public IActionResult Manage(ManageMessageId? message)
|
public IActionResult Manage(ManageMessageId? message)
|
||||||
// {
|
{
|
||||||
// ViewBag.StatusMessage =
|
ViewBag.StatusMessage =
|
||||||
// message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
|
message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
|
||||||
// : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
|
: message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
|
||||||
// : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
|
: message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
|
||||||
// : message == ManageMessageId.Error ? "An error has occurred."
|
: message == ManageMessageId.Error ? "An error has occurred."
|
||||||
// : "";
|
: "";
|
||||||
// ViewBag.HasLocalPassword = HasPassword();
|
ViewBag.HasLocalPassword = HasPassword();
|
||||||
// ViewBag.ReturnUrl = Url.Action("Manage");
|
//ViewBag.ReturnUrl = Url.Action("Manage");
|
||||||
// return View();
|
return View();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/Manage
|
// POST: /Account/Manage
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public async Task<IActionResult> Manage(ManageUserViewModel model)
|
public async Task<IActionResult> Manage(ManageUserViewModel model)
|
||||||
// {
|
{
|
||||||
// bool hasPassword = HasPassword();
|
bool hasPassword = HasPassword();
|
||||||
// ViewBag.HasLocalPassword = hasPassword;
|
ViewBag.HasLocalPassword = hasPassword;
|
||||||
// ViewBag.ReturnUrl = Url.Action("Manage");
|
//ViewBag.ReturnUrl = Url.Action("Manage");
|
||||||
// if (hasPassword)
|
if (hasPassword)
|
||||||
// {
|
{
|
||||||
// if (ModelState.IsValid)
|
//if (ModelState.IsValid)
|
||||||
// {
|
//{
|
||||||
// IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
|
IdentityResult result = await UserManager.ChangePassword("userId" /*User.Identity.GetUserId()*/, model.OldPassword, model.NewPassword);
|
||||||
// if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
// {
|
{
|
||||||
// return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
|
return null;//RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// AddErrors(result);
|
AddErrors(result);
|
||||||
// }
|
}
|
||||||
// }
|
//}
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// // User does not have a password so remove any validation errors caused by a missing OldPassword field
|
// User does not have a password so remove any validation errors caused by a missing OldPassword field
|
||||||
// ModelState state = ModelState["OldPassword"];
|
//ModelState state = ModelState["OldPassword"];
|
||||||
// if (state != null)
|
//if (state != null)
|
||||||
// {
|
//{
|
||||||
// state.Errors.Clear();
|
// state.Errors.Clear();
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// if (ModelState.IsValid)
|
//if (ModelState.IsValid)
|
||||||
// {
|
//{
|
||||||
// IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);
|
IdentityResult result = await UserManager.AddPassword("userId" /*User.Identity.GetUserId()*/, model.NewPassword);
|
||||||
// if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
// {
|
{
|
||||||
// return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess });
|
return null;//RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess });
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// AddErrors(result);
|
AddErrors(result);
|
||||||
// }
|
}
|
||||||
// }
|
//}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // If we got this far, something failed, redisplay form
|
// If we got this far, something failed, redisplay form
|
||||||
// return View(model);
|
return View(model);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/ExternalLogin
|
// POST: /Account/ExternalLogin
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public IActionResult ExternalLogin(string provider, string returnUrl)
|
public IActionResult ExternalLogin(string provider, string returnUrl)
|
||||||
// {
|
{
|
||||||
// // Request a redirect to the external login provider
|
// Request a redirect to the external login provider
|
||||||
// return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
|
//return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
|
||||||
// }
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // GET: /Account/ExternalLoginCallback
|
// GET: /Account/ExternalLoginCallback
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// public async Task<IActionResult> ExternalLoginCallback(string returnUrl)
|
public async Task<IActionResult> ExternalLoginCallback(string returnUrl)
|
||||||
// {
|
{
|
||||||
// var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
|
//var loginInfo = await AuthenticationManager.GetExternalLoginInfo();
|
||||||
// if (loginInfo == null)
|
//if (loginInfo == null)
|
||||||
// {
|
//{
|
||||||
// return RedirectToAction("Login");
|
// return RedirectToAction("Login");
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// // Sign in the user with this external login provider if the user already has a login
|
// Sign in the user with this external login provider if the user already has a login
|
||||||
// var user = await UserManager.FindAsync(loginInfo.Login);
|
var user = await UserManager.Find(null/*loginInfo.Login*/);
|
||||||
// if (user != null)
|
if (user != null)
|
||||||
// {
|
{
|
||||||
// await SignInAsync(user, isPersistent: false);
|
await SignIn(user, isPersistent: false);
|
||||||
// return RedirectToLocal(returnUrl);
|
return RedirectToLocal(returnUrl);
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// // If the user does not have an account, then prompt the user to create an account
|
// If the user does not have an account, then prompt the user to create an account
|
||||||
// ViewBag.ReturnUrl = returnUrl;
|
ViewBag.ReturnUrl = returnUrl;
|
||||||
// ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
|
ViewBag.LoginProvider = null;//loginInfo.Login.LoginProvider;
|
||||||
// return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { UserName = loginInfo.DefaultUserName });
|
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { /*UserName = loginInfo.DefaultUserName*/ });
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/LinkLogin
|
// POST: /Account/LinkLogin
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public IActionResult LinkLogin(string provider)
|
public IActionResult LinkLogin(string provider)
|
||||||
// {
|
{
|
||||||
// // Request a redirect to the external login provider to link a login for the current user
|
// Request a redirect to the external login provider to link a login for the current user
|
||||||
// return new ChallengeResult(provider, Url.Action("LinkLoginCallback", "Account"), User.Identity.GetUserId());
|
//return new ChallengeResult(provider, Url.Action("LinkLoginCallback", "Account"), User.Identity.GetUserId());
|
||||||
// }
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // GET: /Account/LinkLoginCallback
|
// GET: /Account/LinkLoginCallback
|
||||||
// public async Task<IActionResult> LinkLoginCallback()
|
public async Task<IActionResult> LinkLoginCallback()
|
||||||
// {
|
{
|
||||||
// var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, User.Identity.GetUserId());
|
//var loginInfo = await AuthenticationManager.GetExternalLoginInfo(XsrfKey, User.Identity.GetUserId());
|
||||||
// if (loginInfo == null)
|
//if (loginInfo == null)
|
||||||
// {
|
//{
|
||||||
// return RedirectToAction("Manage", new { Message = ManageMessageId.Error });
|
// return RedirectToAction("Manage", new { Message = ManageMessageId.Error });
|
||||||
// }
|
//}
|
||||||
// var result = await UserManager.AddLoginAsync(User.Identity.GetUserId(), loginInfo.Login);
|
//var result = await UserManager.AddLogin(User.Identity.GetUserId(), loginInfo.Login);
|
||||||
// if (result.Succeeded)
|
//if (result.Succeeded)
|
||||||
// {
|
//{
|
||||||
// return RedirectToAction("Manage");
|
// return RedirectToAction("Manage");
|
||||||
// }
|
//}
|
||||||
// return RedirectToAction("Manage", new { Message = ManageMessageId.Error });
|
return null;//RedirectToAction("Manage", new { Message = ManageMessageId.Error });
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/ExternalLoginConfirmation
|
// POST: /Account/ExternalLoginConfirmation
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
|
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
|
||||||
// {
|
{
|
||||||
// if (User.Identity.IsAuthenticated)
|
//if (User.Identity.IsAuthenticated)
|
||||||
// {
|
//{
|
||||||
// return RedirectToAction("Manage");
|
// return RedirectToAction("Manage");
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// if (ModelState.IsValid)
|
//if (ModelState.IsValid)
|
||||||
// {
|
//{
|
||||||
// // Get the information about the user from the external login provider
|
// Get the information about the user from the external login provider
|
||||||
// var info = await AuthenticationManager.GetExternalLoginInfoAsync();
|
//var info = await AuthenticationManager.GetExternalLoginInfoAsync();
|
||||||
// if (info == null)
|
//if (info == null)
|
||||||
// {
|
//{
|
||||||
// return View("ExternalLoginFailure");
|
// return View("ExternalLoginFailure");
|
||||||
// }
|
//}
|
||||||
// var user = new ApplicationUser() { UserName = model.UserName };
|
var user = new ApplicationUser() { UserName = model.UserName };
|
||||||
// var result = await UserManager.CreateAsync(user);
|
var result = await UserManager.Create(user);
|
||||||
// if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
// {
|
{
|
||||||
// result = await UserManager.AddLoginAsync(user.Id, info.Login);
|
result = await UserManager.AddLogin(user.Id, null/*info.Login*/);
|
||||||
// if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
// {
|
{
|
||||||
// await SignInAsync(user, isPersistent: false);
|
await SignIn(user, isPersistent: false);
|
||||||
// return RedirectToLocal(returnUrl);
|
return null;//RedirectToLocal(returnUrl);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// AddErrors(result);
|
AddErrors(result);
|
||||||
// }
|
//}
|
||||||
|
|
||||||
// ViewBag.ReturnUrl = returnUrl;
|
ViewBag.ReturnUrl = returnUrl;
|
||||||
// return View(model);
|
return View(model);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // POST: /Account/LogOff
|
// POST: /Account/LogOff
|
||||||
// [HttpPost]
|
//[HttpPost]
|
||||||
// [ValidateAntiForgeryToken]
|
//[ValidateAntiForgeryToken]
|
||||||
// public IActionResult LogOff()
|
public IActionResult LogOff()
|
||||||
// {
|
{
|
||||||
// AuthenticationManager.SignOut();
|
//AuthenticationManager.SignOut();
|
||||||
// return RedirectToAction("Index", "Home");
|
return null;//RedirectToAction("Index", "Home");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //
|
//
|
||||||
// // GET: /Account/ExternalLoginFailure
|
// GET: /Account/ExternalLoginFailure
|
||||||
// [AllowAnonymous]
|
//[AllowAnonymous]
|
||||||
// public IActionResult ExternalLoginFailure()
|
public IActionResult ExternalLoginFailure()
|
||||||
// {
|
{
|
||||||
// return View();
|
return View();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// [ChildActionOnly]
|
//[ChildActionOnly]
|
||||||
// public IActionResult RemoveAccountList()
|
public IActionResult RemoveAccountList()
|
||||||
// {
|
{
|
||||||
// var linkedAccounts = UserManager.GetLogins(User.Identity.GetUserId());
|
//var linkedAccounts = UserManager.GetLogins(null /*User.Identity.GetUserId()*/);
|
||||||
// ViewBag.ShowRemoveButton = HasPassword() || linkedAccounts.Count > 1;
|
//ViewBag.ShowRemoveButton = HasPassword() || linkedAccounts.Count > 1;
|
||||||
// return (IActionResult)PartialView("_RemoveAccountPartial", linkedAccounts);
|
return null;//(IActionResult)PartialView("_RemoveAccountPartial", linkedAccounts);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// protected override void Dispose(bool disposing)
|
#region Helpers
|
||||||
// {
|
// Used for XSRF protection when adding external logins
|
||||||
// if (disposing && UserManager != null)
|
private const string XsrfKey = "XsrfId";
|
||||||
// {
|
|
||||||
// UserManager.Dispose();
|
|
||||||
// UserManager = null;
|
|
||||||
// }
|
|
||||||
// base.Dispose(disposing);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #region Helpers
|
//private IAuthenticationManager AuthenticationManager
|
||||||
// // Used for XSRF protection when adding external logins
|
//{
|
||||||
// private const string XsrfKey = "XsrfId";
|
// get
|
||||||
|
// {
|
||||||
|
// return HttpContext.GetOwinContext().Authentication;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
// private IAuthenticationManager AuthenticationManager
|
private async Task SignIn(ApplicationUser user, bool isPersistent)
|
||||||
// {
|
{
|
||||||
// get
|
//AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
|
||||||
// {
|
var identity = await UserManager.CreateIdentity(user, "Application" /*DefaultAuthenticationTypes.ApplicationCookie */);
|
||||||
// return HttpContext.GetOwinContext().Authentication;
|
//AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private async Task SignInAsync(ApplicationUser user, bool isPersistent)
|
// Migrate the user's shopping cart
|
||||||
// {
|
MigrateShoppingCart(user.UserName);
|
||||||
// AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
|
}
|
||||||
// var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
|
|
||||||
// AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
|
|
||||||
|
|
||||||
// // Migrate the user's shopping cart
|
private void AddErrors(IdentityResult result)
|
||||||
// MigrateShoppingCart(user.UserName);
|
{
|
||||||
// }
|
foreach (var error in result.Errors)
|
||||||
|
{
|
||||||
|
//ModelState.AddModelError("", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// private void AddErrors(IdentityResult result)
|
private bool HasPassword()
|
||||||
// {
|
{
|
||||||
// foreach (var error in result.Errors)
|
// No sync helpers yet
|
||||||
// {
|
//var user = UserManager.FindById(null /*User.Identity.GetUserId()*/);
|
||||||
// ModelState.AddModelError("", error);
|
//if (user != null)
|
||||||
// }
|
//{
|
||||||
// }
|
// return user.PasswordHash != null;
|
||||||
|
//}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// private bool HasPassword()
|
public enum ManageMessageId
|
||||||
// {
|
{
|
||||||
// var user = UserManager.FindById(User.Identity.GetUserId());
|
ChangePasswordSuccess,
|
||||||
// if (user != null)
|
SetPasswordSuccess,
|
||||||
// {
|
RemoveLoginSuccess,
|
||||||
// return user.PasswordHash != null;
|
Error
|
||||||
// }
|
}
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public enum ManageMessageId
|
private IActionResult RedirectToLocal(string returnUrl)
|
||||||
// {
|
{
|
||||||
// ChangePasswordSuccess,
|
//if (Url.IsLocalUrl(returnUrl))
|
||||||
// SetPasswordSuccess,
|
//{
|
||||||
// RemoveLoginSuccess,
|
// return Redirect(returnUrl);
|
||||||
// Error
|
//}
|
||||||
// }
|
//else
|
||||||
|
//{
|
||||||
|
// return RedirectToAction("Index", "Home");
|
||||||
|
//}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// private IActionResult RedirectToLocal(string returnUrl)
|
//private class ChallengeResult : HttpUnauthorizedResult
|
||||||
// {
|
//{
|
||||||
// if (Url.IsLocalUrl(returnUrl))
|
// public ChallengeResult(string provider, string redirectUri)
|
||||||
// {
|
// : this(provider, redirectUri, null)
|
||||||
// return Redirect(returnUrl);
|
// {
|
||||||
// }
|
// }
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// return RedirectToAction("Index", "Home");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private class ChallengeResult : HttpUnauthorizedResult
|
// public ChallengeResult(string provider, string redirectUri, string userId)
|
||||||
// {
|
// {
|
||||||
// public ChallengeResult(string provider, string redirectUri)
|
// LoginProvider = provider;
|
||||||
// : this(provider, redirectUri, null)
|
// RedirectUri = redirectUri;
|
||||||
// {
|
// UserId = userId;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// public ChallengeResult(string provider, string redirectUri, string userId)
|
// public string LoginProvider { get; set; }
|
||||||
// {
|
// public string RedirectUri { get; set; }
|
||||||
// LoginProvider = provider;
|
// public string UserId { get; set; }
|
||||||
// RedirectUri = redirectUri;
|
|
||||||
// UserId = userId;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public string LoginProvider { get; set; }
|
// public override void ExecuteResult(ControllerContext context)
|
||||||
// public string RedirectUri { get; set; }
|
// {
|
||||||
// public string UserId { get; set; }
|
// var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
|
||||||
|
// if (UserId != null)
|
||||||
// public override void ExecuteResult(ControllerContext context)
|
// {
|
||||||
// {
|
// properties.Dictionary[XsrfKey] = UserId;
|
||||||
// var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
|
// }
|
||||||
// if (UserId != null)
|
// context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
|
||||||
// {
|
// }
|
||||||
// properties.Dictionary[XsrfKey] = UserId;
|
//}
|
||||||
// }
|
#endregion
|
||||||
// context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// #endregion
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
//using Microsoft.AspNet.Identity.EntityFramework;
|
using Microsoft.AspNet.Identity.InMemory;
|
||||||
|
|
||||||
//namespace MvcMusicStore.Models
|
namespace MvcMusicStore.Models
|
||||||
//{
|
{
|
||||||
// // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
|
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
|
||||||
// public class ApplicationUser : IdentityUser
|
public class ApplicationUser : InMemoryUser
|
||||||
// {
|
{
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
//public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||||
// {
|
//{
|
||||||
// public ApplicationDbContext()
|
// public ApplicationDbContext()
|
||||||
// : base("DefaultConnection")
|
// : base("DefaultConnection")
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
// }
|
//}
|
||||||
//}
|
}
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
|
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Mvc.Core" : "0.1-alpha-*",
|
"Microsoft.AspNet.Mvc.Core" : "0.1-alpha-*",
|
||||||
"Microsoft.Data.Entity" : "0.1-alpha-*"
|
"Microsoft.Data.Entity" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.Identity" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.Identity.InMemory" : "0.1-alpha-*"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"net45": {
|
"net45": {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
|
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
|
||||||
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
|
<package id="bootstrap" version="2.3.1" targetFramework="net45" />
|
||||||
<package id="EntityFramework" version="6.0.2" targetFramework="net45" />
|
<package id="EntityFramework" version="6.0.2" targetFramework="net45" />
|
||||||
<package id="jQuery" version="1.9.1" targetFramework="net45" />
|
<package id="jQuery" version="1.9.1" targetFramework="net45" />
|
||||||
<package id="jQuery.Validation" version="1.8.1" targetFramework="net45" />
|
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
|
||||||
|
|
@ -14,17 +14,17 @@
|
||||||
<package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
|
<package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
|
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net45" />
|
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Host.SystemWeb" version="2.0.0" targetFramework="net45" />
|
<package id="Microsoft.Owin.Host.SystemWeb" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security" version="2.0.2" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security.Cookies" version="2.0.2" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security.Cookies" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security.Facebook" version="2.0.0" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security.Facebook" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security.Google" version="2.0.0" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security.Google" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.0.0" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security.OAuth" version="2.0.2" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security.OAuth" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Owin.Security.Twitter" version="2.0.0" targetFramework="net45" />
|
<package id="Microsoft.Owin.Security.Twitter" version="2.0.2" targetFramework="net45" />
|
||||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||||
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
|
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
|
||||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
|
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
|
||||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||||
<package id="Respond" version="1.2.0" targetFramework="net45" />
|
<package id="Respond" version="1.2.0" targetFramework="net45" />
|
||||||
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
|
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue