Пример #1
0
        public ActionResult Register(RegisterUserViewModel registerUserViewModel)
        {
            if (registerUserViewModel.Password != registerUserViewModel.Password)
            {
                ViewData.ModelState.AddModelBinderValidationError("ConfirmPassword", ModelBinderValidationStateKeys.USER_PASSWORDS_DONT_MATCH);
            }

            if (registerUserViewModel.EmailAddress != registerUserViewModel.ConfirmEmailAddress)
            {
                ViewData.ModelState.AddModelBinderValidationError("ConfirmEmailAddress", ModelBinderValidationStateKeys.USER_EMAILS_DONT_MATCH);
            }

            if (registerUserViewModel.Policy == false)
            {
                ViewData.ModelState.AddModelBinderValidationError("Policy", ModelBinderValidationStateKeys.POLICY_NOT_APPROVED);
            }

            try
            {
                MembershipCreateStatus createStatus;
                MembershipUser newUser = Provider.CreateUser(registerUserViewModel.Username, registerUserViewModel.Password, registerUserViewModel.EmailAddress, null, null, false, null, out createStatus);

                //Load the users profile based upon the new username
                UserProfile userProfile = UserProfileManager.GetByUsername(registerUserViewModel.Username);
                userProfile.RecievesNewsletter = registerUserViewModel.RecievesNewsletter;

                //Temporary hack... set the users default town to Manchester...
                //All users need this until they have adjusted their profile...
                userProfile.Town = TownManager.GetByID(new Guid("0D5A3A81-53C1-48B0-B176-A419ACBB2EE8"));

                //Woops we dont actually have any usercredentials at this point...
                //clearly we need a system account...
                UserProfileManager.Save(userProfile, new UserCredentials());

                //Not sure what to do with the MembershipCreateStatus at this point. Really dont like microsofts design here...
            }
            catch (ValidationException e)
            {
                e.AddToModelState(ViewData.ModelState);
                return View(registerUserViewModel);
            }

            return RedirectToUserRegistered(registerUserViewModel.Username);
        }
Пример #2
0
 public ActionResult Register()
 {
     RegisterUserViewModel registerUserViewModel = new RegisterUserViewModel();
     //registerUserViewModel.RecievesNewsletter = true;
     return View(registerUserViewModel);
 }