Exemplo n.º 1
0
        public IActionResult Recovery(string email)
        {
            try
            {
                string token = GetSha256(Guid.NewGuid().ToString());
                using (var db = new sercompraContext())
                {
                    var oUser = db.Usuarios.Where(d => d.Email == email).FirstOrDefault();
                    if (oUser != null)
                    {
                        oUser.RecoveryToken   = token;
                        db.Entry(oUser).State = EntityState.Modified;
                        db.SaveChanges();

                        //enviar mail
                        SendEmail(oUser.Email, token);
                    }
                    else
                    {
                        ViewBag.Error = "El usuario no existe";
                        return(View("Login"));
                    }
                }
            }
            catch (Exception e)
            {
                return(Content("Ocurrió un error " + e.Message));
            }
            //return View("Login");
            return(RedirectToAction("Privacy", "Home"));
        }
Exemplo n.º 2
0
 public IActionResult Login(string email, string password)
 {
     try
     {
         using (var db = new sercompraContext())
         {
             /*var usr = from d in db.Usuarios
              *  where d.Email == email && d.Contraseña == password
              *  select d;*/
             var rl = from d in db.Usuarios
                      where (d.Email == email && d.Contraseña == password)
                      select d.Rol;
             if (rl.Count() > 0)
             {
                 //Session["User"] = rl.First();
                 if (rl.Contains("Administrador"))
                 {
                     return(RedirectToAction("index", "Home"));
                 }
                 if (rl.Contains("Funcionario"))
                 {
                     return(RedirectToAction("index", "Home"));
                 }
                 if (rl.Contains("Proveedor"))
                 {
                     return(RedirectToAction("index", "Home"));
                 }
             }
             else
             {
                 ViewBag.Error = "Usuario o contraseña incorrectos";
                 return(View());
             }
         }
     }
     catch (Exception e)
     {
         return(Content("Ocurrió un error " + e.Message));
     }
     //return View("Login");
     return(RedirectToAction("Index", "Home"));
 }