public ActionResult SyncDatabase(string returnUrl) { //TESTING AND OR DEBUGGING PURPOSES ONLY if (ModelState.IsValid) { int output = 0; System.Web.Security.MembershipUserCollection theCollection = Membership.Provider.GetAllUsers(0, 123, out output); AnswerAppDataContext db = new AnswerAppDataContext(); foreach (MembershipUser theUser in theCollection) { ViewData["UserList"] += "[" + theUser.UserName + "," + theUser.Email + "]"; IQueryable<AnswerApp.Models.User> retrieved = from theUsers in db.Users where theUsers.UserName.Equals(theUser.UserName) select theUsers; User[] Users_in_Answer_Database_by_theUser_Name = retrieved.ToArray<User>(); if (Users_in_Answer_Database_by_theUser_Name.Length < 1) { Membership.Provider.DeleteUser(theUser.UserName, true); ViewData["DeletedUsers"] += "[" + theUser.UserName + "," + theUser.Email + "]"; } } List<User> UserList = new List<User>(); UserList = db.Users.ToList<User>(); foreach (User theUser in UserList) { RegisterModel model = new RegisterModel(); model.UserName = theUser.UserName; model.Email = theUser.Email; model.Password = theUser.Password; MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); ViewData["AddedUsers"] += "[" + theUser.Unique_Id + "," + theUser.UserName + "," + theUser.Email + "," + theUser.Password + "," + "," + theUser.Answers + theUser.MetaData + "]"; } else { ViewData["ErrorList"] = ErrorCodeToString(createStatus); } } } //TESTING AND OR DEBUGGING PURPOSES ONLY*/ return View(); }
// // GET: /Account/Register public ActionResult Register() { RegisterModel model = new RegisterModel(); //model.SecurityQuestionList = new SelectList("What is the name of your first pet?", "What is your favorite food?", "What is your favorite subject in school?", "Who is your favorite musician or musical group?"); //ViewBag.TextBookList = "Math 10<br>Science 10<br>"; return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { if(model.UserName.Contains("_")) { ModelState.AddModelError("", "Your user name cannot contain underscores"); return View(model); } if ((!model.Email.Contains("@")) || (!model.Email.Split(new char[1] { '@' })[1].Contains(".")) || (model.Email.Split(new char[1] { '@' })[1].Contains("@")) || (model.Email.Split(new char[1] { '@' })[1].Length < 1) || (model.Email.Split(new char[1] { '@' })[0].Length < 1)) { ModelState.AddModelError("", "You have entered an invalid e-mail address");//"Your e-mail address must contain only one '@' symbol and at least one '.' symbol afterwards."); return View(model); } //Add the new user to the Answer Database AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); IQueryable<AnswerApp.Models.User> retrieved = from theUsers in db.Users where theUsers.UserName.Equals(model.UserName) select theUsers; User[] Users_in_Answer_Database_by_theUser_Name = retrieved.ToArray<User>(); //If the user does not already exist AnswerApp.Models.User theNewUser = new AnswerApp.Models.User(); if (Users_in_Answer_Database_by_theUser_Name.Length < 1) { theNewUser.UserName = model.UserName; theNewUser.Password = model.Password; theNewUser.Email = model.Email; theNewUser.PasswordQuestion = model.PasswordQuestion; theNewUser.PasswordAnswer = model.PasswordAnswer; theNewUser.MetaData = theNewUser.UserName.GetHashCode().ToString();//theNewUser.UserName;//.GetHashCode().ToString(); db.Users.InsertOnSubmit(theNewUser); db.SubmitChanges();//*/--D.A.P. MailAddress fromAddress = new MailAddress("*****@*****.**"); MailAddress toAddress = new MailAddress(theNewUser.Email); SendEmail(fromAddress, toAddress, "Solvation - E-mail Registration Confirmation", "Hello " + theNewUser.UserName + ". Before you can complete registration with Solvation.ca we must first confirm that this is a valid e-mail addres. To confirm that this is a valid e-mail address you will need to proceed to the following address using your web browser. http://Solvation.ca/Account/ConfirmRegistration/?SecretCode=" /*+ theNewUser.UserName + "_"*/ + theNewUser.UserName.GetHashCode().ToString()); return RedirectToAction("LogIn", "Account"); } // Attempt to register the user /*MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false );// createPersistentCookie MailAddress fromAddress = new MailAddress("*****@*****.**"); MailAddress toAddress = new MailAddress(theNewUser.Email); SendEmail(fromAddress, toAddress, "Salutations!", "Hello " + theNewUser.UserName + " and welcome to Solvation.ca"); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); }//*/ } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { //Add the new user to the Answer Database AnswerApp.Models.AnswerAppDataContext db = new AnswerApp.Models.AnswerAppDataContext(); AnswerApp.Models.User theNewUser = new AnswerApp.Models.User(); theNewUser.UserName = model.UserName; theNewUser.Password = model.Password; theNewUser.Email = model.Email; db.Users.InsertOnSubmit(theNewUser); db.SubmitChanges();//*/--D.A.P. // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }