Exemplo n.º 1
0
        public async Task <ActionResult> Create([Bind(Include = "idProfesor,nombreProfesor,apellidoProfesor,rol,contrasena,nombreUsuario,emailProfesor,estado")] Profesor profesor)
        {
            int profesorActivo = (from d in db.Profesor where d.emailProfesor == profesor.emailProfesor select d.idProfesor).FirstOrDefault();

            if (profesorActivo != 0)
            {
                ViewBag.Error = "Este correo ya se encuentra registrado";
                return(View(profesor));
            }
            ViewBag.Error = profesorActivo;

            String pass        = RandomString(5);
            String passEncrypt = Encripta.GetSHA256(pass);

            profesor.contrasena = passEncrypt;
            if (ModelState.IsValid)
            {
                sendEmail(profesor.emailProfesor, pass);
                //encriptar aqui
                db.Profesor.Add(profesor);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }


            return(View(profesor));
        }
Exemplo n.º 2
0
        public ActionResult CambiarContraseña(string contrasena)
        {
            var session = (Models.Profesor)Session["User"];

            try
            {
                using (prueba1Entities db = new prueba1Entities())
                {
                    var user = (from d in db.Profesor
                                where d.idProfesor == session.idProfesor select d).FirstOrDefault();

                    if (user == null)
                    {
                        return(View("CambiarContraseña"));
                    }

                    user.contrasena = Encripta.GetSHA256(contrasena);


                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("ServerError", "Error"));
            }
        }
Exemplo n.º 3
0
        public ActionResult Login(string email, string password)
        {
            if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
            {
                String pass = Encripta.GetSHA256(password);
                var    user = db.Profesor.FirstOrDefault(e => e.emailProfesor == email && e.contrasena == pass);



                if (user != null)
                {
                    Session["User"]     = user;
                    Session["Nombre"]   = user.nombreProfesor + " " + user.apellidoProfesor;
                    Session["RolVista"] = user.rol;



                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Error = "No se encuentra un usuario";
                    return(View("Login"));
                }
            }
            else
            {
                ViewBag.Error = "Debes llenar los campos para iniciar sesión";
                return(View("Login"));
            }
        }
Exemplo n.º 4
0
        public ActionResult RecuperarContraseña(string correo)
        {
            try
            {
                using (prueba1Entities db = new prueba1Entities())
                {
                    var user = (from d in db.Profesor
                                where d.emailProfesor == correo && d.estado == "Activo"
                                select d).FirstOrDefault();

                    if (user == null)
                    {
                        ViewBag.Error = "No se encuentra ningún usuario registrado o activo con la dirección email: " + correo;
                        return(View("RecuperarContraseña"));
                    }

                    string contrasena = RandomString(6);

                    MailMessage mensaje = new MailMessage("*****@*****.**", correo, "Cambio de Contraseña",
                                                          "Se solicito un cambio de contraseña, su nueva contraseña es " + contrasena +
                                                          ". Favor iniciar sesión en el sistema y cambiar la contraseña");

                    SmtpClient server = new SmtpClient("smtp.gmail.com");
                    server.EnableSsl = true;

                    server.UseDefaultCredentials = false;
                    server.Port        = 587;
                    server.Credentials = new System.Net.NetworkCredential("*****@*****.**", "portalanalisis123");
                    server.Send(mensaje);


                    user.contrasena = Encripta.GetSHA256(contrasena);


                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Login"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("ServerError", "Error"));
            }
        }