public ViewResult ChangeAnswer(UserFull userModification) { UserAnswer userAnswer = new UserAnswer(userModification); var errors = userAnswer.Validate(); if (errors == null) { MembershipUser mu = Membership.GetUser(); if (!mu.ChangePasswordQuestionAndAnswer(userAnswer.Password, securityQuestionRepository.Get(userModification.SecurityQuestion).Description, userAnswer.SecurityAnswer)) { errors = new ErrorSummary(); errors.RegisterErrorMessage("SecurityQuestion", "There was an error while we was updating your security answer, please check your password and try again."); } else { userModification.Alert = "User security question and answer changed successfully"; } } if (errors != null) { Session["Errors"] = errors.ErrorMessages; } userModification.Tab = 3; userModification = GetAccountData(userModification); return(View("Index", userModification)); }
public ViewResult ChangeAnswer(UserFull userModification) { UserAnswer userAnswer = new UserAnswer(userModification); if (ModelState.IsValid) { MembershipUser mu = Membership.GetUser(); if (mu.ChangePasswordQuestionAndAnswer(userAnswer.Password, securityQuestionRepository.Get(userModification.SecurityQuestion).Description, userAnswer.SecurityAnswer)) { userModification.Alert = "User security question and answer changed successfully"; } else { ModelState.AddModelError("Password", "The password dont match"); } } userModification.Tab = 3; userModification = GetAccountData(userModification); return(View("Index", userModification)); }
public ViewResult Register(UserRegistration userRegistration) { var errors = userRegistration.Validate(); if (errors == null) { IList <UserFlavor> userFlavors = Session["UserFlavorSelected"] as List <UserFlavor>; IList <EventType> eventTypes = Session["EventTypeSelected"] as List <EventType>; IList <Garment> mygarments = Session["MyGarments"] as List <Garment>; IList <Garment> mywishlist = Session["MyWishList"] as List <Garment>; PublicUser user = new PublicUser(); user.EmailAddress = userRegistration.Email; user.ChangeZipCode(userRegistration.ZipCode); user.SetFlavors(userFlavors); user.Size = new UserSize(Convert.ToInt32(userRegistration.UserSize)); //TODO: Get the UserId from ASP.NET Membership MembershipCreateStatus status; MembershipUser mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion)).Description, userRegistration.SecurityAnswer, true, out status); if (status != MembershipCreateStatus.Success) { errors = new ErrorSummary(); errors.RegisterErrorMessage("MembershipUser", status.ToString()); return(RegistrationError(userRegistration, errors.ErrorMessages)); } user.MembershipUserId = Convert.ToInt32(mu.ProviderUserKey); user.FirstName = string.Empty; user.LastName = string.Empty; user.PhoneNumber = string.Empty; if (eventTypes != null) { foreach (EventType eventType in eventTypes) { user.AddEventType(eventType); } } registeredUserRepository.SaveOrUpdate(user); Closet closet = new Closet(); closet.User = user; closet.PrivacyLevel = PrivacyLevel.Private; closetRepository.SaveOrUpdate(closet); if (mygarments != null) { foreach (Garment garment in mygarments) { closet.AddGarment(garment); } closetRepository.SaveOrUpdate(closet); } user.Closet = closet; registeredUserRepository.SaveOrUpdate(user); if (mywishlist != null && mywishlist.Count > 0) { WishList wl = new WishList(); wl.User = user; foreach (Garment wishlist in mywishlist) { wl.AddGarment(wishlist); } wishListRepository.SaveOrUpdate(wl); } closetRepository.GenerateCloset(user); Session.Abandon(); Session["UserRegistration"] = mu; return(View("RegistrationFinish", userRegistration)); } return(RegistrationError(userRegistration, errors.ErrorMessages)); }
public ActionResult Register(UserRegistration userRegistration) { if (ModelState.IsValid) { IList <UserFlavor> userFlavors = ClosetState.UserFlavors as List <UserFlavor>; IList <EventType> eventTypes = ClosetState.EventTypes as List <EventType>; IList <Garment> mygarments = garmentRepository.GetByIds(ClosetState.AddGarments) as List <Garment>; IList <Garment> mywishlist = garmentRepository.GetByIds(ClosetState.WishGarments) as List <Garment>; string channel = ClosetState.Channel; string invitationCode = ClosetState.InvitationCode; SecurityQuestion sq = securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion)); // Create Membership User MembershipCreateStatus status; MembershipUser mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, sq.Description, userRegistration.SecurityAnswer, false, out status); if (status != MembershipCreateStatus.Success) { ViewData["Errors"] = new string[] { status.ToString() } } ; try { bool mustConfirmMail = registerMemberService.RegisterMember(userRegistration.Email, userRegistration.UserName, userRegistration.FirstName, userRegistration.LastName, userRegistration.Password, new UserSize(Convert.ToInt32(userRegistration.UserSize)), Convert.ToInt32(mu.ProviderUserKey), userRegistration.ZipCode, userFlavors, eventTypes, mygarments, mywishlist, Url.Action("Validate", "EmailConfirmation"), channel, invitationCode); // Assign User Role Roles.AddUserToRole(mu.UserName, "User"); if (mustConfirmMail) { ClosetState.Clear(); return(RedirectToAction("Index", "EmailConfirmation", new { userid = mu.ProviderUserKey })); } //The user already confirmed his email, so we need to approve him and go to the login // Approve on Membership mu.IsApproved = true; Membership.UpdateUser(mu); RegisteredUser ru = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey)); // Approve on System ru.Confirm(); ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset; registeredUserRepository.SaveOrUpdate(ru); ClosetState.Clear(); return(RedirectToAction("Index", "Login", new { validatedUser = true })); } catch (Exception ex) { // Try to delete the incomplete created user because something went wrong. try { Membership.DeleteUser(userRegistration.UserName); } catch { } if (ex is InvalidInvitationCodeException) { ModelState.AddModelError("InvitationCode", "The code is not valid or already used."); } else { throw; } } } else { if (new List <ModelState>(ModelState.Values).Find(e => e.Value == null).Errors[0].ErrorMessage.StartsWith("Email")) { ModelState.AddModelError("Email", "Email does not match."); } else { ModelState.AddModelError("Password", "Password does not match."); } } GetRegistrationInfo(userRegistration); return(View("Index", userRegistration)); }