public ActionResult Create(AspNetUserRoles crear)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    IchamiloClient client = new IchamiloClient();
                    client.Open();
                    ChamiloUser chuser = client.getUserChamilo(crear.AspNetUsers.Name);
                    if (crear.AspNetRoles.Name == "Maestro" && chuser.Status == 5)
                    {
                        chuser.Status = 1;
                        client.updateUser(chuser, chuser.Username);
                    }
                    if (crear.AspNetRoles.Name == "Estudiante" && chuser.Status == 1)
                    {
                        chuser.Status = 5;
                        client.updateUser(chuser, chuser.Username);
                    }
                    db.AspNetUserRoles.Add(crear);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "El usuario ya pertenece al rol.";
                return(RedirectToAction("Index"));
            }

            return(View(crear));
        }
Пример #2
0
        public ActionResult ChamiloLessons(String coursecode, String name)
        {
            ViewBag.CourseCode = coursecode;
            ViewBag.Name       = name;
            IchamiloClient ch = new IchamiloClient();

            ch.Open();
            List <ChamiloLesson> chamilolessons = ch.getLessonByCource(coursecode).ToList();

            return(View(chamilolessons));
            //return PartialView("_chamiloLessons", chamilolessons);
        }
Пример #3
0
        public ActionResult ChamiloCourses()
        {
            String         nameuser = User.Identity.Name;
            IchamiloClient ch       = new IchamiloClient();

            ch.Open();
            var chamilouser = ch.getUserChamilo(nameuser);
            List <chamiloCource> chamilocourses = ch.getCourcesByUser(chamilouser.Username).ToList();

            return(View(chamilocourses));
            //return PartialView("_chamiloCourses", chamilocourses);
        }
        public async Task <ActionResult> IniciarSesion(LoginViewModel model, string returnUrl)
        {
            investicEntities db = new investicEntities();

            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);

                if (user != null)
                {
                    await SignInAsync(user, model.RememberMe);

                    string       roluser      = AspNetUsersRoles.GetRoles(AspNetUsers.GetUserId(user.UserName)).FirstOrDefault();
                    tblLogAcceso tbllogAcceso = new tblLogAcceso()
                    {
                        Usuario           = model.UserName,
                        IP                = Request.UserHostAddress,
                        Rol               = roluser != ""? roluser:"******",
                        FechaInicioSesion = System.DateTime.Now,
                        FechaCierreSesion = System.DateTime.Now,
                        Latitud           = model.Latitud,
                        Longitud          = model.Longitud,
                        Altitud           = model.Altitud
                    };

                    db.tblLogAcceso.Add(tbllogAcceso);
                    db.SaveChanges();

                    ViewBag.mensaje = "no es";
                    IchamiloClient client = new IchamiloClient();
                    client.Open();
                    ChamiloUser chuser = client.getUserChamilo(model.UserName.Trim());
                    chuser.Password = model.Password;
                    if (AspNetUsersRoles.IsUserInRole("Editor", user.UserName))
                    {
                        return(RedirectToAction("Editor", "Admin", new { nombreu = user.UserName }));
                    }

                    else if (AspNetUsersRoles.IsUserInRole("Maestro", user.UserName))
                    {
                        return(RedirectToAction("Maestro", "Admin", new { nombreu = user.UserName }));
                    }
                    else if (AspNetUsersRoles.IsUserInRole("Estudiante", user.UserName))
                    {
                        return(RedirectToAction("Estudiante", "Admin", new { nombreu = user.UserName }));
                    }
                    else if (AspNetUsersRoles.IsUserInRole("Administrador", user.UserName))
                    {
                        return(RedirectToAction("Index", "Seguimiento"));
                    }
                    else if (AspNetUsersRoles.IsUserInRole("Coordinador", user.UserName))
                    {
                        return(RedirectToAction("Index", "Seguimiento"));
                    }
                    else if (AspNetUsersRoles.IsUserInRole("Contratista", user.UserName))
                    {
                        return(RedirectToAction("Index", "Seguimiento"));
                    }
                    else if (AspNetUsersRoles.IsUserInRole("Administrator", user.UserName))
                    {
                        return(RedirectToAction("Index", "Administrator"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Usuario no registrado.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Registrar(RegisterViewModel model, FormCollection form)
        {
            investicEntities db = new investicEntities();

            model.UserName = model.PersonalID;
            ChamiloUser chuser = new ChamiloUser();

            chuser.FirstName         = model.Name;
            chuser.LasttName         = model.SureName;
            chuser.Password          = model.Password;
            chuser.Email             = model.Mail;
            chuser.Phone             = model.Phone;
            chuser.Username          = model.PersonalID.Trim();
            chuser.Status            = getStatus(form["SelectedUserRoleId"].ToString());
            chuser.Registration_date = DateTime.Now;

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName    = model.UserName,
                    Name        = model.Name,
                    SureName    = model.SureName,
                    PersonalID  = model.PersonalID,
                    Genre       = model.Genre,
                    Email       = model.Mail,
                    PhoneNumber = model.Phone,
                    Address     = model.Address,
                    BirthDay    = model.BirthDay
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    IchamiloClient client = new IchamiloClient();
                    client.Open();
                    AspNetUsers aspNetUser = db.AspNetUsers.Where(m => m.PersonalID == user.PersonalID).FirstOrDefault();
                    if (aspNetUser != null)
                    {
                        aspNetUser.TipoDoc         = model.TipoDoc;
                        db.Entry(aspNetUser).State = System.Data.Entity.EntityState.Modified;
                    }
                    AspNetUserRoles asignRoleToUser = new AspNetUserRoles();
                    string          roleSelected    = form["SelectedUserRoleId"].ToString();
                    asignRoleToUser.RoleId = AspNetRoles.GetRoleId(roleSelected);
                    asignRoleToUser.UserId = AspNetUsers.GetUserId(model.UserName);
                    db.AspNetUserRoles.Add(asignRoleToUser);
                    db.SaveChanges();
                    client.insertUser(chuser);
                    try
                    {
                        var m = new MailMessage(
                            new MailAddress("*****@*****.**", "Registro Plataforma Investic"),
                            new MailAddress(user.Email));
                        m.Subject = "Plataforma Investic - Confirmación de correo electronico";
                        m.Body    =
                            string.Format(
                                "Estimado {0}<BR/>Gracias por su registro en la plataforma Investic,<BR/>Sus datos de acceso:<BR/>Usuario: " +
                                model.PersonalID + "<BR/>Contraseña: " + model.Password +
                                "<BR/>Por favor haga clic en el siguiente vinculo, para confirmar su registro: <a href=\"{1}\" title=\"Confirmación Usuario\">{1}</a>",
                                user.UserName,
                                Url.Action("ConfirmarCorreo", "Usuario", new { Token = user.Id, user.Email }, Request.Url.Scheme));
                        m.IsBodyHtml = true;
                        var smtp = new SmtpClient("smtp.gmail.com");
                        smtp.Credentials = new NetworkCredential("*****@*****.**", "Investic666");
                        smtp.EnableSsl   = true;
                        smtp.Send(m);
                        //await SignInAsync(user, isPersistent: false);

                        return(RedirectToAction("EmailEnviado", "Usuario"));
                    }
                    catch {
                        if (AspNetUsersRoles.IsUserInRole("Editor", user.UserName))
                        {
                            return(RedirectToAction("Editor", "Admin", new { nombreu = user.UserName }));
                        }

                        else if (AspNetUsersRoles.IsUserInRole("Maestro", user.UserName))
                        {
                            return(RedirectToAction("Maestro", "Admin", new { nombreu = user.UserName }));
                        }
                        else if (AspNetUsersRoles.IsUserInRole("Estudiante", user.UserName))
                        {
                            return(RedirectToAction("Estudiante", "Admin", new { nombreu = user.UserName }));
                        }
                        else if (AspNetUsersRoles.IsUserInRole("Administrador", user.UserName))
                        {
                            return(RedirectToAction("Index", "Seguimiento"));
                        }
                        else if (AspNetUsersRoles.IsUserInRole("Coordinador", user.UserName))
                        {
                            return(RedirectToAction("Index", "Seguimiento"));
                        }
                        else if (AspNetUsersRoles.IsUserInRole("Contratista", user.UserName))
                        {
                            return(RedirectToAction("Index", "Seguimiento"));
                        }
                    }
                }
                else
                {
                    AddErrors(result);
                    return(RedirectToAction("Registrar", new { code = 20 }));
                }
            }

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