Exemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel registerViewModel, string returnUrl)
        {
            var model = new LoginRegisterViewModel
            {
                Login    = new LoginViewModel(),
                Register = registerViewModel
            };

            ViewBag.ReturnUrl       = returnUrl;
            TempData["ActivePanel"] = "register";

            if (!ModelState.IsValid)
            {
                return(View("LoginRegister", model));
            }

            var user = new ApplicationUser {
                UserName = registerViewModel.RegisterEmail, Email = registerViewModel.RegisterEmail
            };
            var result = await UserManager.CreateAsync(user, registerViewModel.RegisterPassword);

            if (result.Succeeded)
            {
                await UserManager.AddToRoleAsync(user.Id, RoleNames.Customer);

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = Url.Action("confirmEmail", "account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                var body        = MailHelper.CreateConfirmEmailBody(ControllerContext, callbackUrl);
                await UserManager.SendEmailAsync(user.Id, "Confirm your account", body);

                return(View("SendMail", model: user.Id));
            }

            AddErrors(result);
            TempData["ErrorMessage"] = result.Errors.First().ToString();
            return(View("LoginRegister", model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ResendConfirmMail(string userId)
        {
            if (userId == null)
            {
                return(RedirectToAction("index"));
            }

            var user = UserManager.FindById(userId);

            if (user == null)
            {
                return(View("Error"));
            }

            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = Url.Action("confirmEmail", "account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            var body        = MailHelper.CreateConfirmEmailBody(ControllerContext, callbackUrl);
            await UserManager.SendEmailAsync(user.Id, "Confirm your account", body);

            return(View("SendMail", model: user.Id));
        }