Пример #1
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)
            {
                DataTable dt = new DataTable();
                dt = Estados.Consec(Input.Estado);
                int    cons  = Convert.ToInt32(dt.Rows[0][0].ToString()) + 1;
                string corto = Estados.Abreviatura(Input.Estado);

                string consformat = string.Format("{0:0000}", cons);

                string membresia = corto + "-" + consformat;

                var user = new IdentityUser {
                    UserName = info.Principal.FindFirstValue(ClaimTypes.Email), Email = info.Principal.FindFirstValue(ClaimTypes.Email)
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    Usuarios.InsertaUsuario(membresia, Input.Nombre, user.Email, Input.Estado, user.Id, Input.Apaterno, Input.Amaterno);
                    Estados.ActualizarConsecutivo(cons, Input.Estado);
                    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());
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                DataTable dt = new DataTable();
                dt = Estados.Consec(Input.Estado);
                int    cons  = Convert.ToInt32(dt.Rows[0][0].ToString()) + 1;
                string corto = Estados.Abreviatura(Input.Estado);

                string consformat = string.Format("{0:0000}", cons);

                string membresia = corto + "-" + consformat;

                var user = new IdentityUser {
                    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 con contraseña.");

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

                    //await _emailSender.SendEmailAsync(Input.Email, "confirme su email",
                    //    $"Por favor confirme su cuenta por<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'> clic aquí</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

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

                    Usuarios.InsertaUsuario(membresia, Input.Nombre, user.Email, Input.Estado, user.Id, Input.Apaterno, Input.Amaterno);

                    Estados.ActualizarConsecutivo(cons, Input.Estado);

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

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