public async Task <ActionResult> RegisterUserAsync(RegisterUserModel model)
        {
            model.AcceptUserAgreement = true;

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    FirstName      = model.Name,
                    IsActive       = true,
                    Registered     = DateTime.Now,
                    EmailConfirmed = true
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Add a default subscription called "Free" to all users.
                    await SubscriptionExtensions.RegisterUserSubscriptionCode("Free", user.Id);

                    return(PartialView("_RegisterUserPartial", model));
                }

                AddUserErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(PartialView("_RegisterUserPartial", model));
        }
        public async Task <ActionResult> Register(string code)
        {
            if (Request.IsAuthenticated)
            {
                var userId     = HttpContext.GetUserId();
                var registered = await SubscriptionExtensions.RegisterUserSubscriptionCode(userId, code);

                if (!registered)
                {
                    throw new ApplicationException();
                }

                return(PartialView("_RegisterCodePartial"));
            }
            return(View());
        }
예제 #3
0
        public async Task <ActionResult> Register(string code)
        {
            if (Request.IsAuthenticated)
            {
                // Extension method for fetching the user id
                var userId = HttpContext.GetUserId();
                // Extension method for registering a code with a user
                var registered = await SubscriptionExtensions.RegisterUserSubscriptionCode(code, userId);

                if (!registered)
                {
                    throw new ApplicationException();
                }
                return(PartialView("_RegisterCodePartial"));
            }
            return(View());
        }