Ejemplo n.º 1
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(tiendaOnlineUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new tiendaOnlineUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

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

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new tiendaOnlineUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("El usuario creó una nueva cuenta.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "./ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirma tu correo electrónico",

                                                      $"<font face=',Times New Roman, verdana' size=6 color='FF3300'> <b>Enhorabuena, " +
                                                      $"¡ya estás en iBuy! </b><br/></font> <font face=',Times New Roman, verdana' " +
                                                      $"size=4>¡Ya eres parte de la familia iBuy! Por seguridad, confirma tu dirección email.<br/>" +
                                                      $"Confirmando tu dirección de email tu cuenta estará más segura. Podrás seguir tus pedidos " +
                                                      $"más fácilmente, <br/>recibir emails con promociones y recuperar los detalles de tu cuenta. " +
                                                      $"</br> Simplemente tienes que confirmar tu cuenta haciendo clic</font> " +
                                                      $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'><font size=6>aquí!</font></a>.");

                    if (user.Email == "*****@*****.**")
                    {
                        await _userManager.AddToRoleAsync(user, "Admin");

                        await _userManager.AddToRoleAsync(user, "Seller");

                        var vendedor = new DetalleVendedor();
                        vendedor.correoComercial    = user.Email;
                        vendedor.nombreComercial    = "ibuy";
                        vendedor.tipoVendedor       = TipoVendedor.Privado;
                        vendedor.tiendaOnlineUserID = user.Id;
                        _context.Add(vendedor);
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, "User");
                    }
                    await _context.SaveChangesAsync();

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    //return LocalRedirect(returnUrl);
                    //este return redirige luego del registro, hacia la pagina de CheckEmail para informarle de que
                    //debe revisar su bandeja de entrada y validar su cuenta
                    return(RedirectToPage("./CheckEmail"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }