/* * // * // 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<OAuthAccount> accounts = OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name); * List<ExternalLogin> externalLogins = new List<ExternalLogin>(); * 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); * } */ // GET: /Account/Overview // Overview of transactions for the current user public ActionResult Overview() { CabinOverviewModel model = new CabinOverviewModel(); using (var db = new CabinWebsiteEntities()) { int userId = WebSecurity.CurrentUserId; model.messages = db.messages.Select(t => new MessageModel {/* * messageID = t.messageID, * userID = t.userID, * date = t.date, * title = t.title, * body = t.body,*/ }).OrderByDescending(t => t.date).ToList(); } return(View(model)); //return View(); }
public SimpleMembershipInitializer() { Database.SetInitializer <CabinWebsiteEntities>(null); try { using (var context = new CabinWebsiteEntities()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("CabinWebsiteConnection", "user", "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); } }
/**/ /* * public ActionResult Tasks() * { * ViewBag.Message = "Your app description page."; * * return View(); * } * * public ActionResult AddTask() * { * ViewBag.Message = "Your app description page."; * * return View(); * } * * * /* * public ActionResult AddTask(int model) * { * ViewBag.Message = "Your app description page."; * * return View(); * } */ // // public ActionResult Calendar() { CalendarModel model = new CalendarModel(); using (var db = new CabinWebsiteEntities()) {/* * int userId = WebSecurity.CurrentUserId; * string myFirstName = db.users.Where(i => i.userID == userId).Select(u => u.firstname).FirstOrDefault(); * string myLastName = db.users.Where(i => i.userID == userId).Select(u => u.lastname).FirstOrDefault(); * model.myReservedDates = db.calendars.Where( * a => * a.userID == userId * ).Select(t => new ReservedModel * { * calendarID = t.calendarID, * userID = t.userID, * userFirstName = myFirstName, * userLastName = myLastName, * dateAdded = t.dateAdded, * reservedDate = t.reservedDate, * }).OrderByDescending(t => t.reservedDate).ToList(); * * model.otherReservedDates = db.calendars.Where( * a => * a.userID != userId * ).Select(t => new ReservedModel * { * calendarID = t.calendarID, * userID = t.userID, * userFirstName = db.users.Where(i => i.userID == t.userID).Select(u => u.firstname).FirstOrDefault(), * userLastName = db.users.Where(i => i.userID == t.userID).Select(u => u.lastname).FirstOrDefault(), * dateAdded = t.dateAdded, * reservedDate = t.reservedDate, * }).OrderByDescending(t => t.reservedDate).ToList();*/ } return(View(model)); }