Esempio n. 1
0
 public void CreateNewSignUp(SignUp model, string ipAddress)
 {
     // Set the username to the email as well, to speed up searches, if username not used
     if (!Cohort.Site.Auth.Username)
     {
         model.Username = model.Email;
     }
     var user = new User
     {
         Username = model.Username,
         Email = model.Email,
         Password = _security.Hash(model.Password),
         IsActivated = false,
         LandingPageUrl = model.LandingPage,
         ReferrerUrl = model.RefererUrl,
         Culture = Thread.CurrentThread.CurrentUICulture.Name,
         JoinedOn = DateTime.Now,
         IPAddress = ipAddress
     };
     _user.Save(user);
 }
Esempio n. 2
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"});
        }