Пример #1
0
        public ActionResult Local(LocalSignup model, string id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Attempt to register the user
                    Guid userId = Guid.NewGuid();
                    var newUser = WebSecurity.CreateUserAndAccount(model.User.UserName, model.User.Password, new { Email = model.UserContact.EmailAddress, UserId = userId });

                    if (newUser != null)
                    {
                        if (!Roles.RoleExists("user"))
                        {
                            Roles.CreateRole("user");
                        }
                        Roles.AddUsersToRoles(new string[] { model.User.UserName }, new string[] { "User" });

                        // Now that the user is created, attempt to create the corresponding subscription
                        var customerInfo = new CustomerAttributes()
                        {
                            FirstName = model.UserContact.FirstName,
                            LastName = model.UserContact.LastName,
                            Email = model.UserContact.EmailAddress,
                            SystemID = userId.ToString()
                        };

                        var paymentAttributes = new CreditCardAttributes()
                        {
                            FullNumber = model.UserPayment.CardNumber.Trim(),
                            CVV = model.UserPayment.CVV,
                            ExpirationMonth = model.UserPayment.ExpirationMonth,
                            ExpirationYear = model.UserPayment.ExpirationYear,
                            BillingAddress = model.UserAddress.Address,
                            BillingCity = model.UserAddress.City,
                            BillingZip = model.UserAddress.Zip,
                            BillingState = model.UserAddress.State,
                            BillingCountry = model.UserAddress.Country
                        };

                        try
                        {
                            var newSubscription = Chargify.CreateSubscription(id, customerInfo, paymentAttributes);

                            WebSecurity.Login(model.User.UserName, model.User.Password, false);
                            return RedirectToAction("Index", "Site");
                        }
                        catch (ChargifyException ex)
                        {
                            if (ex.ErrorMessages.Count > 0)
                            {
                                ModelState.AddModelError("", ex.ErrorMessages.FirstOrDefault().Message);
                            }
                            else
                            {
                                ModelState.AddModelError("", ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        //ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    }
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #2
0
        public ActionResult Local(LocalSignup model, string id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Attempt to register the user
                    Guid userId  = Guid.NewGuid();
                    var  newUser = WebSecurity.CreateUserAndAccount(model.User.UserName, model.User.Password, new { Email = model.UserContact.EmailAddress, UserId = userId });

                    if (newUser != null)
                    {
                        if (!Roles.RoleExists("user"))
                        {
                            Roles.CreateRole("user");
                        }
                        Roles.AddUsersToRoles(new string[] { model.User.UserName }, new string[] { "User" });

                        // Now that the user is created, attempt to create the corresponding subscription
                        var customerInfo = new CustomerAttributes()
                        {
                            FirstName = model.UserContact.FirstName,
                            LastName  = model.UserContact.LastName,
                            Email     = model.UserContact.EmailAddress,
                            SystemID  = userId.ToString()
                        };

                        var paymentAttributes = new CreditCardAttributes()
                        {
                            FullNumber      = model.UserPayment.CardNumber.Trim(),
                            CVV             = model.UserPayment.CVV,
                            ExpirationMonth = model.UserPayment.ExpirationMonth,
                            ExpirationYear  = model.UserPayment.ExpirationYear,
                            BillingAddress  = model.UserAddress.Address,
                            BillingCity     = model.UserAddress.City,
                            BillingZip      = model.UserAddress.Zip,
                            BillingState    = model.UserAddress.State,
                            BillingCountry  = model.UserAddress.Country
                        };


                        try
                        {
                            var newSubscription = Chargify.CreateSubscription(id, customerInfo, paymentAttributes);

                            WebSecurity.Login(model.User.UserName, model.User.Password, false);
                            return(RedirectToAction("Index", "Site"));
                        }
                        catch (ChargifyException ex)
                        {
                            if (ex.ErrorMessages.Count > 0)
                            {
                                ModelState.AddModelError("", ex.ErrorMessages.FirstOrDefault().Message);
                            }
                            else
                            {
                                ModelState.AddModelError("", ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        //ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }