Example #1
0
        public ActionResult Login(Users user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (IsValid(user.NickName, user.Password))
                    {
                        FormsAuthentication.SetAuthCookie(Users.NickName, Users.Active = true);

                        if (ApplicationUsers.UserId == Users.UserId)
                        {
                            if (ApplicationUsers.RoleId == RolesUser.RoleId)
                            {
                                UserCont(ApplicationUsers, UserCountries1);

                                if (RolesUser.Description.Equals("Administrador"))
                                {
                                    Functions.ActivitySesions(ApplicationUsers);

                                    return(RedirectToAction("Index", "Ventas"));
                                }
                                else if (RolesUser.Description.Equals("Vendedor"))
                                {
                                    Functions.ActivitySesions(ApplicationUsers);

                                    return(RedirectToAction("Index", "Ventas"));
                                }
                                else if (RolesUser.Description.Equals("Agroquimico"))
                                {
                                    Functions.ActivitySesions(ApplicationUsers);

                                    return(RedirectToAction("Index", "Clasification"));
                                }
                                else if (RolesUser.Description.Equals("Diagramador"))
                                {
                                    Functions.ActivitySesions(ApplicationUsers);

                                    return(RedirectToAction("Index", "Production"));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Applications.ApplicationId != ApplicationUsers.ApplicationId)
                        {
                            ModelState.AddModelError("", "No tiene privilegios para entrar al sistema");
                        }
                        else
                        {
                            ModelState.AddModelError("", "Inicio de Sesión Incorrecto");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var trace = new System.Diagnostics.StackTrace(e);

                string msj = e.Message;
            }
            return(View("Login"));
        }
Example #2
0
        public ActionResult Login(Models.Users _user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _user.Password = cryptography.encrypt(_user.Password);
                    string _nickName    = _user.NickName;
                    string _password    = _user.Password;
                    var    _hashkey     = System.Configuration.ConfigurationManager.AppSettings["HashKey"];
                    var    _roWloginApp = db.Database.SqlQuery <plm_spLoginApplications_Result>("plm_spLoginApplications @User = '******', @Password ='******', @HashKey = '" + _hashkey + "'").ToList();

                    _roWusers.UserId    = _roWloginApp[0].UsrUserId;
                    _roWusers.Active    = _roWloginApp[0].UserActive;
                    _roWusers.CountryId = _roWloginApp[0].UserCountryId;
                    _roWusers.Email     = _roWloginApp[0].UserEmail;
                    _roWusers.LastName  = _roWloginApp[0].UserLastName;
                    _roWusers.Name      = _roWloginApp[0].UserName;
                    _roWusers.NickName  = _roWloginApp[0].UserNickName;
                    _roWusers.Password  = _roWloginApp[0].UserPassword;

                    _roWApplicationusers.ApplicationId = _roWloginApp[0].UserApplicationId;
                    _roWApplicationusers.RoleId        = _roWloginApp[0].UserRoleId;
                    _roWApplicationusers.UserId        = _roWloginApp[0].UserUserId;

                    _roWrolesUsers.Active      = _roWloginApp[0].RoleActive;
                    _roWrolesUsers.Description = _roWloginApp[0].RoleDescription;
                    _roWrolesUsers.RoleId      = _roWloginApp[0].RoleId;

                    _roWApplications.ApplicationId = _roWloginApp[0].ApplicationsApplicationId;
                    _roWApplications.Active        = _roWloginApp[0].ApplicationsActive;
                    _roWApplications.Description   = _roWloginApp[0].ApplicationsDescription;
                    _roWApplications.HashKey       = _roWloginApp[0].ApplicationsHashKey;

                    FormsAuthentication.SetAuthCookie(_roWusers.NickName, _roWusers.Active = true);
                    if (_roWApplicationusers.UserId == _roWusers.UserId)
                    {
                        if (_roWApplicationusers.RoleId == _roWrolesUsers.RoleId)
                        {
                            UserCont(_roWusers, _roWApplicationusers);
                            if (_roWrolesUsers.Description == "Administrador")
                            {
                                Functions.ActivitySesions(_roWusers, _roWApplicationusers);
                                return(RedirectToAction("Index", "Analytics"));
                                //return RedirectToAction("RedirectToAction", "Login");
                            }
                            if (_roWrolesUsers.Description == "Vendedor")
                            {
                                Functions.ActivitySesions(_roWusers, _roWApplicationusers);
                                return(RedirectToAction("Index", "Analytics"));
                            }
                            if (_roWrolesUsers.Description == "Diagramador")
                            {
                                Functions.ActivitySesions(_roWusers, _roWApplicationusers);
                                return(RedirectToAction("Index", "Analytics"));
                            }
                            if (_roWrolesUsers.Description == "Laboratorio de Información")
                            {
                                Functions.ActivitySesions(_roWusers, _roWApplicationusers);
                                return(RedirectToAction("Index", "Analytics"));
                            }
                        }
                    }
                }
            }
            catch (Exception _msgException)
            {
                if (_msgException.Message == "_errorAccess")
                {
                    ViewData["Error"] = "No tiene acceso al sistema.";
                }
                else if (_msgException.Message == "_errorapplication")
                {
                    ViewData["Error"] = "Hay un problema con la aplicación.";
                }
                else if (_msgException.Message == "_errorUser")
                {
                    ViewData["Error"] = "Ingrese sus credenciales correctamente.";
                }
                else
                {
                    ViewData["Error"] = "Ocurrio un problema al accesar a los servidores, disculpe los inconvenientes.";
                }
            }
            return(View(_user));
        }