Exemple #1
0
        public ActionResult SignUp(SignUp model, string stripeToken)
        {
            if (ModelState.IsValid)
            {
                if (model.Password != model.PasswordAgain)
                {
                    ModelState.AddModelError("password", "Both passwords entered must match.");
                }
                if (_accounts.GetUser(model.Email) != null)
                {
                    ModelState.AddModelError("email", "This username is already taken. Did you mean to sign in?");
                }

                if (Cohort.Site.Stripe.Enabled && !string.IsNullOrEmpty(stripeToken))
                {
                    // Successful credit capture is necessary in-process
                    if (!_stripe.SaveCustomerByToken(model.Email, stripeToken))
                    {
                        ModelState.AddModelError("", "We could not capture your credit card details. Please try again.");
                    }
                }

                if (ModelState.IsValid)
                {
                    _accounts.CreateNewSignUp(model, _accounts.GetIPAddress(Request));
                    var hash = _activation.StoreAuthenticationTicketForActivation(model.Email);

                    Func <bool> thing = () =>
                    {
                        _email.Send("Activation", new
                        {
                            To             = model.Email,
                            From           = Cohort.Site.Email.FromAddress,
                            Subject        = Cohort.Site.Email.ActivationSubject,
                            ActivationLink = GetActivationLink(hash),
                            Cohort.Site.Membership.ActivationDays
                        });
                        return(true);
                    };
                    thing.PerformAsync();
                }
            }

            return(!ModelState.IsValid
                       ? (ActionResult)View(model)
                       : RedirectToAction("Index", "Home", new { area = "User" }));
        }