public ActionResult DeleteConfirmed() { ReaderDb _db = new ReaderDb(); UserProfile up = _db.UserProfiles.Find(WebSecurity.CurrentUserId); _db.UserProfiles.Remove(up); _db.SaveChanges(); WebSecurity.Logout(); return Redirect(Url.Content("~/")); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new { Email = model.Email}); WebSecurity.Login(model.UserName, model.Password); //Init the profile to default value ReaderDb _db = new ReaderDb(); UserProfile up = _db.UserProfiles.Where(u => u.UserName == model.UserName).Single(); up.eventClicked = 0; up.eventDownloaded = 0; up.eventRead = 0; up.feedMaxEvent = 30; up.articleDisplayType = 0; up.SynchronisationType = 0; up.EventPerPage = 15; up.SynchroCode = ProfileController.RandomString(20); //genere un code de synchro unique //Add the default category _db.Categories.Add(new Category() { UserId = up.UserId, Name = "Default" }); _db.SaveChanges(); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
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 (ReaderDb db = new ReaderDb()) { 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); }