Beispiel #1
0
        public async Task <ActionResult> Recovery(RecoveryViewModel model)
        {
            try
            {
                ViewBag.CustomErrors = "";

                if (ModelState.IsValid)
                {
                    //var user = await UserManager.FindAsync(model.UserName, model.Password);
                    //if (user != null)
                    //{
                    //    await SignInAsync(user, model.RememberMe);
                    //    return RedirectToLocal("~/");
                    //}
                    //else
                    //{
                    //    ViewBag.CustomErrors += "Usuario y/o contraseña inválidos";
                    //    return View(model);
                    //}
                    return(RedirectToAction("RecoveryPassword", "Mail", new { rfc = model.UserName }));
                }

                // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
                return(View(model));
            }
            catch (Exception ex)
            {
                ViewBag.CustomErrors += ex.Message;
                return(View(model));
            }
        }
        public async Task <IActionResult> Recovery(RecoveryViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = _context.Usuario.Where(d => d.RecContraseña == model.token).FirstOrDefault();
                    if (user != null)
                    {
                        user.Contraseña    = Crypto.Hash(model.Password);
                        user.RecContraseña = null;
                        _context.Update(user);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        //Mensaje = "Este token ha Expirado";
                        return(View(model));
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
        public async Task <ActionResult> AccountRecovery([FromBody] RecoveryViewModel recoveryViewModel)
        {
            if (IsValid(recoveryViewModel.Email))
            {
                var user = await userManager.FindByEmailAsync(recoveryViewModel.Email);

                if (user != null)
                {
                    var authClaims = new[]
                    {
                        new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
                        new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
                    };

                    var authSigninKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SecureKey"));

                    var token = new JwtSecurityToken(
                        claims: authClaims,
                        expires: DateTime.Now.AddMinutes(30)
                        );

                    SendGridEmailService.ExecuteSendRecoveryEmail(user.Email, new JwtSecurityTokenHandler().WriteToken(token)).Wait();

                    return(Ok(new
                    {
                        message = MessageConstants.AccountRecoveryOk
                    }));
                }
            }

            return(BadRequest(new
            {
                message = MessageConstants.AccountRecoveryBad
            }));
        }
        public ActionResult StarRecovery(RecoveryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            string token = GetSha256(Guid.NewGuid().ToString());

            using (SII_Entities db = new SII_Entities())
            {
                var oUser = db.Tbl_Usuario.Where(d => d.Tbl_Persona.correo_Electronico == model.Email).FirstOrDefault();
                if (oUser != null)
                {
                    oUser.token_recovery = token;
                    token = oUser.token_recovery;
                    db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    TempData["msg"] = "Recuperado";
                    ViewBag.Msg     = TempData["msg"];

                    //enviar email
                    SendEmail(oUser.Tbl_Persona.correo_Electronico, token);
                }
            }
            return(Redirect("http://localhost:51219/Acceso/Login"));
        }
        public ActionResult StartRecovery(RecoveryViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                string token = Guid.NewGuid().ToString();

                using (proyectofloresEntities db = new proyectofloresEntities())
                {
                    var oUser = db.usuario.Where(d => d.email == model.Email).FirstOrDefault();
                    if (oUser != null)
                    {
                        oUser.token           = token;
                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();

                        //enviar correo
                        SendEmail(oUser.email, token);
                    }
                }
                return(View());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public ActionResult Recovery(string token)
        {
            RecoveryViewModel model = new RecoveryViewModel();

            model.token = token;
            if (model.token == null || model.token.Trim().Equals(""))
            {
                //Mensaje = "Token Vencido";
                return(View("Index"));
            }
            var user = _context.Usuario.Where(d => d.RecContraseña == model.token).FirstOrDefault();

            if (user != null)
            {
                return(View(model));
            }
            else
            {
                // Mensaje = "Token Vencido";
                return(View("Index"));
            }
        }
        public async Task <ActionResult> Recovery(Guid notificationId, Guid movementId)
        {
            var movementDetails = await mediator.SendAsync(new GetMovementDetailsById(notificationId, movementId));

            var model = new RecoveryViewModel
            {
                SelectedmovementId = movementId,
                NotificationId     = notificationId,
                NotificationType   = await mediator.SendAsync(new GetNotificationType(notificationId)),
                ShipmentNumber     = movementDetails.Number
            };

            if (TempData[CertificateKey] != null)
            {
                model.Certificate = (CertificateType)TempData[CertificateKey];
            }
            else
            {
                return(RedirectToAction("CertificateTypes", "Certificate"));
            }
            return(View(model));
        }
Beispiel #8
0
        public IActionResult StartRecovery(RecoveryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var token = _userService.GenerateTokenRecovery(model.Email);

            if (!string.IsNullOrEmpty(token))
            {
                var email = new MailRequest()
                {
                    Email   = model.Email,
                    Subject = "Recuperar Contraseña",
                    Body    = "<p>Correo para recuperación de contraseña</p><br>" + "<a href='" + "https://nogupeweb.azurewebsites.net/Account/Recovery/?token=" + token + "'>Click para recuperar</a>"
                };

                _emailSenderService.SendEmailAsync(email);
            }

            return(View());
        }
Beispiel #9
0
        public ActionResult StartRecovery(RecoveryViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                string token = Generales.GetSha256(Guid.NewGuid().ToString());

                using (Models.LateOSEntities db = new Models.LateOSEntities())
                {
                    var oUser = db.V_Usuarios.Where(d => d.clte_Correo == model.Email).FirstOrDefault();
                    if (oUser != null)
                    {
                        tbUsuarios tbUser = db.tbUsuarios.Where(x => x.usu_Id == oUser.usu_Id).FirstOrDefault();
                        if (tbUser != null)
                        {
                            tbUser.usu_Token       = token;
                            db.Entry(tbUser).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }

                        //enviar mail
                        Generales.SendEmail(oUser.clte_Correo, token);
                    }
                }
                ViewBag.Message = "El correo se envió correctamente";
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Se produjo un error";
                return(View());
            }
        }
 public RecoveryPage()
 {
     InitializeComponent();
     BindingContext = new RecoveryViewModel();
 }
        public ActionResult StarRecovery(string token)
        {
            RecoveryViewModel model = new RecoveryViewModel();

            return(View());
        }
Beispiel #12
0
        public ActionResult Recovery(RecoveryViewModel model)
        {
            string EmailOrigen = "*****@*****.**";
            string Pass        = "******";

            using (FinanzasEntities db = new FinanzasEntities())
            {
                var lst = from d in db.user where d.email == model.Email select d;
                if (lst.Count() > 0)
                {
                    user oUser = lst.First();
                    UserF.id = oUser.id;

                    #region
                    //Auto Genera Contraseña - Modifica Contraseña
                    Guid   miGuid           = Guid.NewGuid();
                    string PassAutoGenerate = Convert.ToBase64String(miGuid.ToByteArray());
                    PassAutoGenerate      = PassAutoGenerate.Replace("=", "").Replace("+", "").Replace("/", "").Substring(0, 12);
                    oUser.password        = Encriptador.encriptar(PassAutoGenerate);
                    db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    #endregion

                    UserF.password = PassAutoGenerate;
                }
                else
                {
                    //Mensaje Alerta
                    ViewBag.smsnore = "No hay una cuenta asociada a este correo";
                    return(View());
                }
            }

            MailMessage oMailMessage = new MailMessage(EmailOrigen, model.Email, "Recuperacion de Contraseña",
                                                       "<p>Correo para recuperacion de contraseña</p><br>" +
                                                       "<p>Su contraseña es: " + UserF.password + "</p><br>" +
                                                       "<p>Le recomendamos cambiar su contraseña</p>");

            oMailMessage.IsBodyHtml = true;

            SmtpClient oSmtpClient = new SmtpClient("smtp.gmail.com");
            oSmtpClient.EnableSsl             = true;
            oSmtpClient.UseDefaultCredentials = false;
            oSmtpClient.Port        = 587;
            oSmtpClient.Credentials = new System.Net.NetworkCredential(EmailOrigen, Pass);

            try
            {
                oSmtpClient.Send(oMailMessage);
                oSmtpClient.Dispose();

                //Mensaje de Exito
                TempData["smsE"] = "El correo ha sido enviado, revise su bandeja de entrada";
                ViewBag.smsE     = TempData["smsE"];

                return(Redirect(Url.Content("~/Access/Index")));
            }
            catch (Exception)
            {
                //Mensaje de Peligro
                TempData["smsD"] = "Ha ocurrido un error crítico";
                ViewBag.smsD     = TempData["smsD"];
                return(Redirect(Url.Content("~/Access/Index")));
            }
        }
Beispiel #13
0
        //Recuperación de la cuenta por correo electrónico
        public ActionResult StartRecovery()
        {
            RecoveryViewModel model = new RecoveryViewModel();

            return(View(model));
        }
        public async Task <ActionResult> Recovery(Guid notificationId, Guid movementId, RecoveryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            TempData[CertificateKey]      = model.Certificate;
            TempData[NotificationTypeKey] = model.NotificationType;
            TempData[DateRecoveredKey]    = model.GetDateRecovered();

            MovementBasicDetails movementDetails = await mediator.SendAsync(new GetMovementDetailsById(notificationId, movementId));

            ValidateRecoveryShipment(model.GetDateRecovered(), movementDetails);
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            return(RedirectToAction("UploadCertificate", new { movementId = movementId }));
        }