diff --git a/.gitignore b/.gitignore index bd74113..64f0764 100644 --- a/.gitignore +++ b/.gitignore @@ -186,11 +186,14 @@ UpgradeLog*.htm # Microsoft Fakes Log.txt + +# 51Degrees *.lic *Enterprise*.dat *Premium*.dat *Enterprise*.trie *Premium*.trie -App_Data/Cache/ +**/App_Data/Cache million.csv -*.snk \ No newline at end of file +*.snk + diff --git a/51degrees 4.sln b/51degrees 4.sln index 6765de7..aee3c04 100644 --- a/51degrees 4.sln +++ b/51degrees 4.sln @@ -61,68 +61,76 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find Profiles", "Examples\F EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "All Profiles", "Examples\All Profiles\All Profiles.csproj", "{EA6A83FE-D698-4E4D-821E-1B5BCC22D501}" EndProject +Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "FiftyOne.Foundation SQL", "FoundationV3\FiftyOne.Foundation SQL.sqlproj", "{334A1D9F-82F5-41C0-8583-76823D8BF2B1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Debug|x64.ActiveCfg = Debug|x64 - {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Debug|x64.Build.0 = Debug|x64 - {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Release|x64.ActiveCfg = Release|x64 - {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Release|x64.Build.0 = Release|x64 - {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Debug|x64.ActiveCfg = Debug|x64 - {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Debug|x64.Build.0 = Debug|x64 - {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Release|x64.ActiveCfg = Release|x64 - {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Release|x64.Build.0 = Release|x64 - {1211A461-73CA-4D7E-86A7-983540F12539}.Debug|x64.ActiveCfg = Debug|x64 - {1211A461-73CA-4D7E-86A7-983540F12539}.Debug|x64.Build.0 = Debug|x64 - {1211A461-73CA-4D7E-86A7-983540F12539}.Release|x64.ActiveCfg = Release|x64 - {1211A461-73CA-4D7E-86A7-983540F12539}.Release|x64.Build.0 = Release|x64 - {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Debug|x64.ActiveCfg = Debug|x64 - {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Debug|x64.Build.0 = Debug|x64 - {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Release|x64.ActiveCfg = Release|x64 - {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Release|x64.Build.0 = Release|x64 - {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Debug|x64.ActiveCfg = Debug|x64 - {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Debug|x64.Build.0 = Debug|x64 - {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Release|x64.ActiveCfg = Release|x64 - {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Release|x64.Build.0 = Release|x64 - {069D6175-9007-40DD-A313-F63C9377A680}.Debug|x64.ActiveCfg = Debug|x64 - {069D6175-9007-40DD-A313-F63C9377A680}.Debug|x64.Build.0 = Debug|x64 - {069D6175-9007-40DD-A313-F63C9377A680}.Release|x64.ActiveCfg = Release|x64 - {069D6175-9007-40DD-A313-F63C9377A680}.Release|x64.Build.0 = Release|x64 - {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Debug|x64.ActiveCfg = Debug|x64 - {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Debug|x64.Build.0 = Debug|x64 - {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Release|x64.ActiveCfg = Release|x64 - {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Release|x64.Build.0 = Release|x64 - {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Debug|x64.ActiveCfg = Debug|x64 - {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Debug|x64.Build.0 = Debug|x64 - {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Release|x64.ActiveCfg = Release|x64 - {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Release|x64.Build.0 = Release|x64 - {091CBBA9-94C4-486B-B630-6533E787A489}.Debug|x64.ActiveCfg = Debug|x64 - {091CBBA9-94C4-486B-B630-6533E787A489}.Debug|x64.Build.0 = Debug|x64 - {091CBBA9-94C4-486B-B630-6533E787A489}.Release|x64.ActiveCfg = Release|x64 - {091CBBA9-94C4-486B-B630-6533E787A489}.Release|x64.Build.0 = Release|x64 - {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Debug|x64.ActiveCfg = Debug|x64 - {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Debug|x64.Build.0 = Debug|x64 - {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Release|x64.ActiveCfg = Release|x64 - {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Release|x64.Build.0 = Release|x64 - {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Debug|x64.ActiveCfg = Debug|x64 - {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Debug|x64.Build.0 = Debug|x64 - {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Release|x64.ActiveCfg = Release|x64 - {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Release|x64.Build.0 = Release|x64 - {608157FD-165C-40F4-AF79-BC812C9BC70E}.Debug|x64.ActiveCfg = Debug|x64 - {608157FD-165C-40F4-AF79-BC812C9BC70E}.Debug|x64.Build.0 = Debug|x64 - {608157FD-165C-40F4-AF79-BC812C9BC70E}.Release|x64.ActiveCfg = Release|x64 - {608157FD-165C-40F4-AF79-BC812C9BC70E}.Release|x64.Build.0 = Release|x64 - {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Debug|x64.ActiveCfg = Debug|x64 - {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Debug|x64.Build.0 = Debug|x64 - {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Release|x64.ActiveCfg = Release|x64 - {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Release|x64.Build.0 = Release|x64 - {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Debug|x64.ActiveCfg = Debug|x64 - {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Debug|x64.Build.0 = Debug|x64 - {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Release|x64.ActiveCfg = Release|x64 - {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Release|x64.Build.0 = Release|x64 + {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0A7C5CE-1B06-4BB3-AB9D-DB055C6EDF69}.Release|Any CPU.Build.0 = Release|Any CPU + {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D658044-FB65-4939-8449-A3A1DEBBB31A}.Release|Any CPU.Build.0 = Release|Any CPU + {1211A461-73CA-4D7E-86A7-983540F12539}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1211A461-73CA-4D7E-86A7-983540F12539}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1211A461-73CA-4D7E-86A7-983540F12539}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1211A461-73CA-4D7E-86A7-983540F12539}.Release|Any CPU.Build.0 = Release|Any CPU + {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6535DE09-9EFF-4876-9D65-6483EFD453AD}.Release|Any CPU.Build.0 = Release|Any CPU + {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {324F06B4-50D5-4F6E-9DEE-2DA05B2B3B18}.Release|Any CPU.Build.0 = Release|Any CPU + {069D6175-9007-40DD-A313-F63C9377A680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {069D6175-9007-40DD-A313-F63C9377A680}.Debug|Any CPU.Build.0 = Debug|Any CPU + {069D6175-9007-40DD-A313-F63C9377A680}.Release|Any CPU.ActiveCfg = Release|Any CPU + {069D6175-9007-40DD-A313-F63C9377A680}.Release|Any CPU.Build.0 = Release|Any CPU + {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB500454-EC93-4FEA-BDD8-FBA018EF2C3C}.Release|Any CPU.Build.0 = Release|Any CPU + {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBA7559B-EF3C-496D-BDC7-9EF76A5D3EB9}.Release|Any CPU.Build.0 = Release|Any CPU + {091CBBA9-94C4-486B-B630-6533E787A489}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {091CBBA9-94C4-486B-B630-6533E787A489}.Debug|Any CPU.Build.0 = Debug|Any CPU + {091CBBA9-94C4-486B-B630-6533E787A489}.Release|Any CPU.ActiveCfg = Release|Any CPU + {091CBBA9-94C4-486B-B630-6533E787A489}.Release|Any CPU.Build.0 = Release|Any CPU + {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BD47A7B-6D73-46BD-82D5-E7E9BE347646}.Release|Any CPU.Build.0 = Release|Any CPU + {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F4B351DA-1474-4F6B-83D1-75B62CB19CD7}.Release|Any CPU.Build.0 = Release|Any CPU + {608157FD-165C-40F4-AF79-BC812C9BC70E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {608157FD-165C-40F4-AF79-BC812C9BC70E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {608157FD-165C-40F4-AF79-BC812C9BC70E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {608157FD-165C-40F4-AF79-BC812C9BC70E}.Release|Any CPU.Build.0 = Release|Any CPU + {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B91129C0-224A-4AA7-BE18-C13EB2E2BDFD}.Release|Any CPU.Build.0 = Release|Any CPU + {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA6A83FE-D698-4E4D-821E-1B5BCC22D501}.Release|Any CPU.Build.0 = Release|Any CPU + {334A1D9F-82F5-41C0-8583-76823D8BF2B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {334A1D9F-82F5-41C0-8583-76823D8BF2B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {334A1D9F-82F5-41C0-8583-76823D8BF2B1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {334A1D9F-82F5-41C0-8583-76823D8BF2B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {334A1D9F-82F5-41C0-8583-76823D8BF2B1}.Release|Any CPU.Build.0 = Release|Any CPU + {334A1D9F-82F5-41C0-8583-76823D8BF2B1}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Examples/MVC/Controllers/AccountController.cs b/Examples/MVC/Controllers/AccountController.cs deleted file mode 100644 index 3d1fb2f..0000000 --- a/Examples/MVC/Controllers/AccountController.cs +++ /dev/null @@ -1,407 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Transactions; -using System.Web; -using System.Web.Mvc; -using System.Web.Security; -using DotNetOpenAuth.AspNet; -using Microsoft.Web.WebPages.OAuth; -using WebMatrix.WebData; -using MVC.Filters; -using MVC.Models; - -namespace MVC.Controllers -{ - [Authorize] - [InitializeSimpleMembership] - public class AccountController : Controller - { - // - // GET: /Account/Login - - [AllowAnonymous] - public ActionResult Login(string returnUrl) - { - ViewBag.ReturnUrl = returnUrl; - return View(); - } - - // - // POST: /Account/Login - - [HttpPost] - [AllowAnonymous] - [ValidateAntiForgeryToken] - public ActionResult Login(LoginModel model, string returnUrl) - { - if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) - { - return RedirectToLocal(returnUrl); - } - - // If we got this far, something failed, redisplay form - ModelState.AddModelError("", "The user name or password provided is incorrect."); - return View(model); - } - - // - // POST: /Account/LogOff - - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult LogOff() - { - WebSecurity.Logout(); - - return RedirectToAction("Index", "Home"); - } - - // - // GET: /Account/Register - - [AllowAnonymous] - public ActionResult Register() - { - return View(); - } - - // - // POST: /Account/Register - - [HttpPost] - [AllowAnonymous] - [ValidateAntiForgeryToken] - public ActionResult Register(RegisterModel model) - { - if (ModelState.IsValid) - { - // Attempt to register the user - try - { - WebSecurity.CreateUserAndAccount(model.UserName, model.Password); - WebSecurity.Login(model.UserName, model.Password); - return RedirectToAction("Index", "Home"); - } - catch (MembershipCreateUserException e) - { - ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); - } - } - - // If we got this far, something failed, redisplay form - return View(model); - } - - // - // POST: /Account/Disassociate - - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Disassociate(string provider, string providerUserId) - { - string ownerAccount = OAuthWebSecurity.GetUserName(provider, providerUserId); - ManageMessageId? message = null; - - // Only disassociate the account if the currently logged in user is the owner - if (ownerAccount == User.Identity.Name) - { - // Use a transaction to prevent the user from deleting their last login credential - using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable })) - { - bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); - if (hasLocalAccount || OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name).Count > 1) - { - OAuthWebSecurity.DeleteAccount(provider, providerUserId); - scope.Complete(); - message = ManageMessageId.RemoveLoginSuccess; - } - } - } - - return RedirectToAction("Manage", new { Message = message }); - } - - // - // GET: /Account/Manage - - public ActionResult Manage(ManageMessageId? message) - { - ViewBag.StatusMessage = - message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." - : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." - : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed." - : ""; - ViewBag.HasLocalPassword = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); - ViewBag.ReturnUrl = Url.Action("Manage"); - return View(); - } - - // - // POST: /Account/Manage - - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Manage(LocalPasswordModel model) - { - bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); - ViewBag.HasLocalPassword = hasLocalAccount; - ViewBag.ReturnUrl = Url.Action("Manage"); - if (hasLocalAccount) - { - if (ModelState.IsValid) - { - // ChangePassword will throw an exception rather than return false in certain failure scenarios. - bool changePasswordSucceeded; - try - { - changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword); - } - catch (Exception) - { - changePasswordSucceeded = false; - } - - if (changePasswordSucceeded) - { - return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }); - } - else - { - ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); - } - } - } - else - { - // User does not have a local password so remove any validation errors caused by a missing - // OldPassword field - ModelState state = ModelState["OldPassword"]; - if (state != null) - { - state.Errors.Clear(); - } - - if (ModelState.IsValid) - { - try - { - WebSecurity.CreateAccount(User.Identity.Name, model.NewPassword); - return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }); - } - catch (Exception) - { - ModelState.AddModelError("", String.Format("Unable to create local account. An account with the name \"{0}\" may already exist.", User.Identity.Name)); - } - } - } - - // If we got this far, something failed, redisplay form - return View(model); - } - - // - // POST: /Account/ExternalLogin - - [HttpPost] - [AllowAnonymous] - [ValidateAntiForgeryToken] - public ActionResult ExternalLogin(string provider, string returnUrl) - { - return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); - } - - // - // GET: /Account/ExternalLoginCallback - - [AllowAnonymous] - public ActionResult ExternalLoginCallback(string returnUrl) - { - AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); - if (!result.IsSuccessful) - { - return RedirectToAction("ExternalLoginFailure"); - } - - if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false)) - { - return RedirectToLocal(returnUrl); - } - - if (User.Identity.IsAuthenticated) - { - // If the current user is logged in add the new account - OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name); - return RedirectToLocal(returnUrl); - } - else - { - // User is new, ask for their desired membership name - string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId); - ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName; - ViewBag.ReturnUrl = returnUrl; - return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData }); - } - } - - // - // POST: /Account/ExternalLoginConfirmation - - [HttpPost] - [AllowAnonymous] - [ValidateAntiForgeryToken] - public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) - { - string provider = null; - string providerUserId = null; - - if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) - { - return RedirectToAction("Manage"); - } - - if (ModelState.IsValid) - { - // Insert a new user into the database - using (UsersContext db = new UsersContext()) - { - UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); - // Check if user already exists - if (user == null) - { - // Insert name into the profile table - db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); - db.SaveChanges(); - - OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); - OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); - - return RedirectToLocal(returnUrl); - } - else - { - ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); - } - } - } - - ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; - ViewBag.ReturnUrl = returnUrl; - return View(model); - } - - // - // GET: /Account/ExternalLoginFailure - - [AllowAnonymous] - public ActionResult ExternalLoginFailure() - { - return View(); - } - - [AllowAnonymous] - [ChildActionOnly] - public ActionResult ExternalLoginsList(string returnUrl) - { - ViewBag.ReturnUrl = returnUrl; - return PartialView("_ExternalLoginsListPartial", OAuthWebSecurity.RegisteredClientData); - } - - [ChildActionOnly] - public ActionResult RemoveExternalLogins() - { - ICollection accounts = OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name); - List externalLogins = new List(); - foreach (OAuthAccount account in accounts) - { - AuthenticationClientData clientData = OAuthWebSecurity.GetOAuthClientData(account.Provider); - - externalLogins.Add(new ExternalLogin - { - Provider = account.Provider, - ProviderDisplayName = clientData.DisplayName, - ProviderUserId = account.ProviderUserId, - }); - } - - ViewBag.ShowRemoveButton = externalLogins.Count > 1 || OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); - return PartialView("_RemoveExternalLoginsPartial", externalLogins); - } - - #region Helpers - private ActionResult RedirectToLocal(string returnUrl) - { - if (Url.IsLocalUrl(returnUrl)) - { - return Redirect(returnUrl); - } - else - { - return RedirectToAction("Index", "Home"); - } - } - - public enum ManageMessageId - { - ChangePasswordSuccess, - SetPasswordSuccess, - RemoveLoginSuccess, - } - - internal class ExternalLoginResult : ActionResult - { - public ExternalLoginResult(string provider, string returnUrl) - { - Provider = provider; - ReturnUrl = returnUrl; - } - - public string Provider { get; private set; } - public string ReturnUrl { get; private set; } - - public override void ExecuteResult(ControllerContext context) - { - OAuthWebSecurity.RequestAuthentication(Provider, ReturnUrl); - } - } - - private static string ErrorCodeToString(MembershipCreateStatus createStatus) - { - // See http://go.microsoft.com/fwlink/?LinkID=177550 for - // a full list of status codes. - switch (createStatus) - { - case MembershipCreateStatus.DuplicateUserName: - return "User name already exists. Please enter a different user name."; - - case MembershipCreateStatus.DuplicateEmail: - return "A user name for that e-mail address already exists. Please enter a different e-mail address."; - - case MembershipCreateStatus.InvalidPassword: - return "The password provided is invalid. Please enter a valid password value."; - - case MembershipCreateStatus.InvalidEmail: - return "The e-mail address provided is invalid. Please check the value and try again."; - - case MembershipCreateStatus.InvalidAnswer: - return "The password retrieval answer provided is invalid. Please check the value and try again."; - - case MembershipCreateStatus.InvalidQuestion: - return "The password retrieval question provided is invalid. Please check the value and try again."; - - case MembershipCreateStatus.InvalidUserName: - return "The user name provided is invalid. Please check the value and try again."; - - case MembershipCreateStatus.ProviderError: - return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."; - - case MembershipCreateStatus.UserRejected: - return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."; - - default: - return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."; - } - } - #endregion - } -} diff --git a/Examples/MVC/Controllers/BaseController.cs b/Examples/MVC/Controllers/BaseController.cs index 3687a71..ad6c179 100644 --- a/Examples/MVC/Controllers/BaseController.cs +++ b/Examples/MVC/Controllers/BaseController.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; +using System.Web.Mvc; using FiftyOne.Foundation.Mobile.Detection; using MVC.Models; using System.Web.Routing; diff --git a/Examples/MVC/Controllers/HomeController.cs b/Examples/MVC/Controllers/HomeController.cs index 446ff81..e72fc3e 100644 --- a/Examples/MVC/Controllers/HomeController.cs +++ b/Examples/MVC/Controllers/HomeController.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; -using FiftyOne.Foundation.Mobile.Detection; -using MVC.Models; +using System.Web.Mvc; namespace MVC.Controllers { diff --git a/Examples/MVC/Filters/InitializeSimpleMembershipAttribute.cs b/Examples/MVC/Filters/InitializeSimpleMembershipAttribute.cs deleted file mode 100644 index ed0de0f..0000000 --- a/Examples/MVC/Filters/InitializeSimpleMembershipAttribute.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Data.Entity; -using System.Data.Entity.Infrastructure; -using System.Threading; -using System.Web.Mvc; -using WebMatrix.WebData; -using MVC.Models; - -namespace MVC.Filters -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] - public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute - { - private static SimpleMembershipInitializer _initializer; - private static object _initializerLock = new object(); - private static bool _isInitialized; - - public override void OnActionExecuting(ActionExecutingContext filterContext) - { - // Ensure ASP.NET Simple Membership is initialized only once per app start - LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock); - } - - private class SimpleMembershipInitializer - { - public SimpleMembershipInitializer() - { - Database.SetInitializer(null); - - try - { - using (var context = new UsersContext()) - { - if (!context.Database.Exists()) - { - // Create the SimpleMembership database without Entity Framework migration schema - ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); - } - } - - WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); - } - catch (Exception ex) - { - throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); - } - } - } - } -} diff --git a/Examples/MVC/MVC.csproj b/Examples/MVC/MVC.csproj index 889482e..080d36d 100644 --- a/Examples/MVC/MVC.csproj +++ b/Examples/MVC/MVC.csproj @@ -50,12 +50,9 @@ - - - @@ -85,8 +82,6 @@ ..\..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll - - True ..\..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll @@ -120,14 +115,14 @@ True ..\..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll - - True - ..\..\packages\Microsoft.AspNet.WebPages.Data.2.0.30506.0\lib\net40\WebMatrix.Data.dll - True ..\..\packages\Microsoft.AspNet.WebPages.OAuth.2.0.30506.0\lib\net40\Microsoft.Web.WebPages.OAuth.dll + + ..\..\packages\Microsoft.AspNet.WebPages.Data.2.0.20710.0\lib\net40\WebMatrix.Data.dll + True + True ..\..\packages\Microsoft.AspNet.WebPages.WebData.2.0.30506.0\lib\net40\WebMatrix.WebData.dll @@ -187,14 +182,11 @@ - - Global.asax - @@ -294,19 +286,9 @@ - - - - - - - - - - diff --git a/Examples/MVC/Models/AccountModels.cs b/Examples/MVC/Models/AccountModels.cs deleted file mode 100644 index 62bd106..0000000 --- a/Examples/MVC/Models/AccountModels.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Data.Entity; -using System.Globalization; -using System.Web.Security; - -namespace MVC.Models -{ - public class UsersContext : DbContext - { - public UsersContext() - : base("DefaultConnection") - { - } - - public DbSet UserProfiles { get; set; } - } - - [Table("UserProfile")] - public class UserProfile - { - [Key] - [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] - public int UserId { get; set; } - public string UserName { get; set; } - } - - public class RegisterExternalLoginModel - { - [Required] - [Display(Name = "User name")] - public string UserName { get; set; } - - public string ExternalLoginData { get; set; } - } - - public class LocalPasswordModel - { - [Required] - [DataType(DataType.Password)] - [Display(Name = "Current password")] - public string OldPassword { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "New password")] - public string NewPassword { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm new password")] - [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - - public class LoginModel - { - [Required] - [Display(Name = "User name")] - public string UserName { get; set; } - - [Required] - [DataType(DataType.Password)] - [Display(Name = "Password")] - public string Password { get; set; } - - [Display(Name = "Remember me?")] - public bool RememberMe { get; set; } - } - - public class RegisterModel - { - [Required] - [Display(Name = "User name")] - public string UserName { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "Password")] - public string Password { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm password")] - [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - - public class ExternalLogin - { - public string Provider { get; set; } - public string ProviderDisplayName { get; set; } - public string ProviderUserId { get; set; } - } -} diff --git a/Examples/MVC/Models/Device.cs b/Examples/MVC/Models/Device.cs index f96e292..0e5ec22 100644 --- a/Examples/MVC/Models/Device.cs +++ b/Examples/MVC/Models/Device.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using FiftyOne.Foundation.Mobile.Detection; +using FiftyOne.Foundation.Mobile.Detection; using System.Linq; -using System.Web; /* The first stage of using 51Degrees device detection in MVC is creating diff --git a/Examples/MVC/Views/Account/ExternalLoginConfirmation.cshtml b/Examples/MVC/Views/Account/ExternalLoginConfirmation.cshtml deleted file mode 100644 index a5f3a58..0000000 --- a/Examples/MVC/Views/Account/ExternalLoginConfirmation.cshtml +++ /dev/null @@ -1,36 +0,0 @@ -@model MVC.Models.RegisterExternalLoginModel -@{ - ViewBag.Title = "Register"; -} - -
-

@ViewBag.Title.

-

Associate your @ViewBag.ProviderDisplayName account.

-
- -@using (Html.BeginForm("ExternalLoginConfirmation", "Account", new { ReturnUrl = ViewBag.ReturnUrl })) { - @Html.AntiForgeryToken() - @Html.ValidationSummary(true) - -
- Association Form -

- You've successfully authenticated with @ViewBag.ProviderDisplayName. - Please enter a user name for this site below and click the Confirm button to finish - logging in. -

-
    -
  1. - @Html.LabelFor(m => m.UserName) - @Html.TextBoxFor(m => m.UserName) - @Html.ValidationMessageFor(m => m.UserName) -
  2. -
- @Html.HiddenFor(m => m.ExternalLoginData) - -
-} - -@section Scripts { - @Scripts.Render("~/bundles/jqueryval") -} diff --git a/Examples/MVC/Views/Account/ExternalLoginFailure.cshtml b/Examples/MVC/Views/Account/ExternalLoginFailure.cshtml deleted file mode 100644 index ec69c13..0000000 --- a/Examples/MVC/Views/Account/ExternalLoginFailure.cshtml +++ /dev/null @@ -1,8 +0,0 @@ -@{ - ViewBag.Title = "Login Failure"; -} - -
-

@ViewBag.Title.

-

Unsuccessful login with service.

-
diff --git a/Examples/MVC/Views/Account/Login.cshtml b/Examples/MVC/Views/Account/Login.cshtml deleted file mode 100644 index 51b854f..0000000 --- a/Examples/MVC/Views/Account/Login.cshtml +++ /dev/null @@ -1,50 +0,0 @@ -@model MVC.Models.LoginModel - -@{ - ViewBag.Title = "Log in"; -} - -
-

@ViewBag.Title.

-
- -
-

Use a local account to log in.

-@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) { - @Html.AntiForgeryToken() - @Html.ValidationSummary(true) - -
- Log in Form -
    -
  1. - @Html.LabelFor(m => m.UserName) - @Html.TextBoxFor(m => m.UserName) - @Html.ValidationMessageFor(m => m.UserName) -
  2. -
  3. - @Html.LabelFor(m => m.Password) - @Html.PasswordFor(m => m.Password) - @Html.ValidationMessageFor(m => m.Password) -
  4. -
  5. - @Html.CheckBoxFor(m => m.RememberMe) - @Html.LabelFor(m => m.RememberMe, new { @class = "checkbox" }) -
  6. -
- -
-

- @Html.ActionLink("Register", "Register") if you don't have an account. -

-} -
- - - -@section Scripts { - @Scripts.Render("~/bundles/jqueryval") -} diff --git a/Examples/MVC/Views/Account/Manage.cshtml b/Examples/MVC/Views/Account/Manage.cshtml deleted file mode 100644 index 9a17f6c..0000000 --- a/Examples/MVC/Views/Account/Manage.cshtml +++ /dev/null @@ -1,32 +0,0 @@ -@model MVC.Models.LocalPasswordModel -@{ - ViewBag.Title = "Manage Account"; -} - -
-

@ViewBag.Title.

-
- -

@ViewBag.StatusMessage

- -

You're logged in as @User.Identity.Name.

- -@if (ViewBag.HasLocalPassword) -{ - @Html.Partial("_ChangePasswordPartial") -} -else -{ - @Html.Partial("_SetPasswordPartial") -} - -
- @Html.Action("RemoveExternalLogins") - -

Add an external login

- @Html.Action("ExternalLoginsList", new { ReturnUrl = ViewBag.ReturnUrl }) -
- -@section Scripts { - @Scripts.Render("~/bundles/jqueryval") -} diff --git a/Examples/MVC/Views/Account/Register.cshtml b/Examples/MVC/Views/Account/Register.cshtml deleted file mode 100644 index 4c85626..0000000 --- a/Examples/MVC/Views/Account/Register.cshtml +++ /dev/null @@ -1,37 +0,0 @@ -@model MVC.Models.RegisterModel -@{ - ViewBag.Title = "Register"; -} - -
-

@ViewBag.Title.

-

Create a new account.

-
- -@using (Html.BeginForm()) { - @Html.AntiForgeryToken() - @Html.ValidationSummary() - -
- Registration Form -
    -
  1. - @Html.LabelFor(m => m.UserName) - @Html.TextBoxFor(m => m.UserName) -
  2. -
  3. - @Html.LabelFor(m => m.Password) - @Html.PasswordFor(m => m.Password) -
  4. -
  5. - @Html.LabelFor(m => m.ConfirmPassword) - @Html.PasswordFor(m => m.ConfirmPassword) -
  6. -
- -
-} - -@section Scripts { - @Scripts.Render("~/bundles/jqueryval") -} diff --git a/Examples/MVC/Views/Account/_ChangePasswordPartial.cshtml b/Examples/MVC/Views/Account/_ChangePasswordPartial.cshtml deleted file mode 100644 index 17b9c7c..0000000 --- a/Examples/MVC/Views/Account/_ChangePasswordPartial.cshtml +++ /dev/null @@ -1,27 +0,0 @@ -@model MVC.Models.LocalPasswordModel - -

Change password

- -@using (Html.BeginForm("Manage", "Account")) { - @Html.AntiForgeryToken() - @Html.ValidationSummary() - -
- Change Password Form -
    -
  1. - @Html.LabelFor(m => m.OldPassword) - @Html.PasswordFor(m => m.OldPassword) -
  2. -
  3. - @Html.LabelFor(m => m.NewPassword) - @Html.PasswordFor(m => m.NewPassword) -
  4. -
  5. - @Html.LabelFor(m => m.ConfirmPassword) - @Html.PasswordFor(m => m.ConfirmPassword) -
  6. -
- -
-} diff --git a/Examples/MVC/Views/Account/_ExternalLoginsListPartial.cshtml b/Examples/MVC/Views/Account/_ExternalLoginsListPartial.cshtml deleted file mode 100644 index 5bdce84..0000000 --- a/Examples/MVC/Views/Account/_ExternalLoginsListPartial.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@model ICollection - -@if (Model.Count == 0) -{ -
-

There are no external authentication services configured. See this article - for details on setting up this ASP.NET application to support logging in via external services.

-
-} -else -{ - using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = ViewBag.ReturnUrl })) - { - @Html.AntiForgeryToken() -
- Log in using another service -

- @foreach (AuthenticationClientData p in Model) - { - - } -

-
- } -} diff --git a/Examples/MVC/Views/Account/_RemoveExternalLoginsPartial.cshtml b/Examples/MVC/Views/Account/_RemoveExternalLoginsPartial.cshtml deleted file mode 100644 index 002a510..0000000 --- a/Examples/MVC/Views/Account/_RemoveExternalLoginsPartial.cshtml +++ /dev/null @@ -1,34 +0,0 @@ -@model ICollection - -@if (Model.Count > 0) -{ -

Registered external logins

- - - @foreach (MVC.Models.ExternalLogin externalLogin in Model) - { - - - - - } - -
@externalLogin.ProviderDisplayName - @if (ViewBag.ShowRemoveButton) - { - using (Html.BeginForm("Disassociate", "Account")) - { - @Html.AntiForgeryToken() -
- @Html.Hidden("provider", externalLogin.Provider) - @Html.Hidden("providerUserId", externalLogin.ProviderUserId) - -
- } - } - else - { - @:   - } -
-} diff --git a/Examples/MVC/Views/Account/_SetPasswordPartial.cshtml b/Examples/MVC/Views/Account/_SetPasswordPartial.cshtml deleted file mode 100644 index 12822cc..0000000 --- a/Examples/MVC/Views/Account/_SetPasswordPartial.cshtml +++ /dev/null @@ -1,26 +0,0 @@ -@model MVC.Models.LocalPasswordModel - -

- You do not have a local password for this site. Add a local - password so you can log in without an external login. -

- -@using (Html.BeginForm("Manage", "Account")) { - @Html.AntiForgeryToken() - @Html.ValidationSummary() - -
- Set Password Form -
    -
  1. - @Html.LabelFor(m => m.NewPassword) - @Html.PasswordFor(m => m.NewPassword) -
  2. -
  3. - @Html.LabelFor(m => m.ConfirmPassword) - @Html.PasswordFor(m => m.ConfirmPassword) -
  4. -
- -
-} diff --git a/Examples/MVC/Views/Shared/_Layout.cshtml b/Examples/MVC/Views/Shared/_Layout.cshtml index 95099ba..440cd59 100644 --- a/Examples/MVC/Views/Shared/_Layout.cshtml +++ b/Examples/MVC/Views/Shared/_Layout.cshtml @@ -18,9 +18,6 @@

@Html.Raw("")

-
- @Html.Partial("_LoginPartial") -