Пример #1
0
 public ActionResult Register(RegistrationViewModel registrationViewModel)
 {
     return this.RegisterInternal(registrationViewModel, "Sorry, that email address has already been registered.",
         createUser: (pwd) => new Parent(registrationViewModel.Name, registrationViewModel.Email, pwd).Initialise(),
         confirmAction: () => this.RedirectToAction("Confirm"),
         invalidModelStateAction: () => this.View("Register", registrationViewModel)
         );
 }
Пример #2
0
        ActionResult RegisterInternal(
            RegistrationViewModel registrationViewModel,
            string usernameTakenMessage,
            Func<string, User> createUser,
            Func<ActionResult> confirmAction, 
            Func<ActionResult> invalidModelStateAction,
            Action<User> afterUserCreated = null)
        {
            if (registrationViewModel == null)
            {
                throw new ArgumentNullException("registrationViewModel");
            }
            if (createUser == null)
            {
                throw new ArgumentNullException("createUser");
            }
            if (confirmAction == null)
            {
                throw new ArgumentNullException("confirmAction");
            }
            if (invalidModelStateAction == null)
            {
                throw new ArgumentNullException("invalidModelStateAction");
            }

            if (this.ModelState.IsValid)
            {
                var conflictedUser = this.userService.GetUserByUserName(registrationViewModel.Email);
                if (conflictedUser != null)
                {
                    this.ModelState.AddModelError("Email", usernameTakenMessage);
                    return invalidModelStateAction();
                }

                var hashedPassword = this.formsAuthenticationService.HashAndSalt(
                    registrationViewModel.Email,
                    registrationViewModel.Password);

                var user = createUser(hashedPassword);

                if (string.IsNullOrWhiteSpace(this.configuration.EmailSmtpServer))
                {
                    // if no smtp server configured, just activate user as no email is sent out.
                    user.Activate();
                }

                this.userService.SaveUser(user);

                if (afterUserCreated != null)
                {
                    afterUserCreated(user);
                }
                return confirmAction();
            }

            return invalidModelStateAction();
        }
        public ActionResult AddChild(RegistrationViewModel registrationViewModel)
        {
            var parent = userService.CurrentUser as Parent;
            if (parent == null)
            {
                //throw new TardisBankException("You must be a parent in order to register a Child");
                return StatusCode.NotFound;
            }

            return RegisterInternal(registrationViewModel, "Sorry, that user name has already been taken",
                pwd => parent.CreateChild(registrationViewModel.Name, registrationViewModel.Email, pwd),
                () => RedirectToAction("Index", "Child"), () => View("AddChild", registrationViewModel)
                );
        }
 public ActionResult Register(RegistrationViewModel registrationViewModel)
 {
     return RegisterInternal(registrationViewModel, "Sorry, that email address has already been registered.",
         pwd =>
             new Parent(registrationViewModel.Name, registrationViewModel.Email, pwd).Initialise(mediator),
         () => RedirectToAction("Confirm"), () => View("Register", registrationViewModel)
         );
 }