Пример #1
0
        public bool RequestRestorePassword([FromBody] ResendEmailViewModel model)
        {
            if (!model.IsValid())
            {
                return(false);
            }
            model.Trim();
            model.Correo = model.Correo?.ToUpper();

            var user = _dbContext.Usuarios.FirstOrDefault(x => x.Correo.ToUpper() == model.Correo && x.Estado == Estado.Activo);

            if (user is null)
            {
                return(false);
            }

            var oldRegistries = _dbContext.Registros.Where(x => x.Usuario.UsuarioId == user.UsuarioId);

            if (oldRegistries.Count() > 0)
            {
                _dbContext.RemoveRange(oldRegistries);
                _dbContext.SaveChanges();
            }

            var register = new Registro(user);

            _dbContext.Registros.Add(register);
            _dbContext.SaveChanges();

            _mail.SendRequestRestorePassword(user.Correo, $"{user.Nombre} {user.Apellidos}", register.Token);

            return(true);
        }
Пример #2
0
        public bool ReSendConfirmationEmail([FromBody] ResendEmailViewModel model)
        {
            if (!model.IsValid())
            {
                return(false);
            }
            model.Trim();
            model.Correo = model.Correo.ToUpper();

            var oldregistries = _dbContext.Registros.Where(x => x.Usuario.Correo.ToUpper() == model.Correo);

            if (oldregistries != null)
            {
                _dbContext.RemoveRange(oldregistries);
                _dbContext.SaveChanges();
            }

            var user = _dbContext.Usuarios.FirstOrDefault(x => x.Correo.ToUpper() == model.Correo);

            if (user is null)
            {
                return(false);
            }

            var register = new Registro(user);

            _dbContext.Registros.Add(register);
            _dbContext.SaveChanges();

            _mail.SendConfirmationMail(user.Correo, $"{user.Nombre} {user.Apellidos}", register.Token);

            return(true);
        }
Пример #3
0
        public async Task <IActionResult> ResendEmail(ResendEmailViewModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user?.EmailConfirmed == false)
            {
                ViewData["Resent"] = true;
                SendEmailConfirmation(user);
            }
            ViewData["Resent"] = false;
            return(View("Login"));
        }
Пример #4
0
        public async Task <IActionResult> ResendEmailConfirmation(ResendEmailViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    return(RedirectToAction(nameof(AccountController.ResendEmailConfirmation), "Account"));
                }

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);

                await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                                                  $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
            }

            return(View(model));
        }
Пример #5
0
        public async Task <IActionResult> ResendEmail(ResendEmailViewModel model)
        {
            var user = _userManager.FindByEmailAsync(model.Email).Result;

            if (user == null)
            {
                return(ConfirmResendEmail("Email address does not exist."));
            }
            var isEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);

            if (isEmailConfirmed)
            {
                return(View("Login"));
            }
            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
            //This method will send an email from [email protected] to the email the user inputted.
            await _authEmail.SendEmailAsync(model.Email, "Confirm Email", "Please confirm your account by clicking this <a href=\"" + callbackUrl + "\">link</a>");

            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }
Пример #6
0
        public async Task <IActionResult> SendEmail([FromBody] ResendEmailViewModel model)
        {
            try
            {
                if (!ModelState.IsValid || model.UserId == null)
                {
                    return(BadRequest(ModelState));
                }
                var userIdentity = _userManager.Users.Where(c => c.Id == model.UserId.ToString()).FirstOrDefault();
                if (userIdentity != null)
                {
                    await _emailSender.SendEmailAsync(userIdentity.Email, "Account Verification",
                                                      $"Your email verification code is <b>{userIdentity.PhoneNumber}</b>.");

                    return(new OkObjectResult(userIdentity));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(null);
        }