public static bool ValidateUser(string username, string password, bool status)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }
            else
            {
                AppUser login = new AppUser();

                login.Password = password;
                login.Name     = username;

                IAppUser appUserBO   = new AppUserBO();
                string   loginStatus = appUserBO.Authenticated(login);
                //string loginStatus = LoginStatus.OK;
                if (loginStatus.Equals(LoginStatus.OK))
                {
                    var userRoles = new string[] { };

                    var cacheKey = string.Format("UserRoles_{0}", login.Name);

                    int _cacheTimeoutInMinutes = 30;

                    HttpRuntime.Cache.Insert(cacheKey, userRoles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), System.Web.Caching.Cache.NoSlidingExpiration);
                    return(true);
                }
                return(false);
            }
        }
        public static MembershipUser GetUser(string userName, bool userIsOnline, bool status)
        {
            var cacheKey = string.Format("UserData_{0}", userName);

            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return((CustomMembershipUser)HttpRuntime.Cache[cacheKey]);
            }

            AppUser  user      = new AppUser();
            IAppUser appUserBO = new AppUserBO();

            user = appUserBO.FindByName(userName);


            if (user != null)
            {
                //user.Profile.PMG.ToList().ForEach(x => x.Module.PMG = null);
                //user.Profile.PMG.ToList().ForEach(x => x.Module.Grant = x.Grant);
                //foreach (var item in user.Profile.PMG)
                //{
                //    item.Profile = null;
                //}

                var membershipUser = new CustomMembershipUser(user);

                HttpRuntime.Cache.Insert(cacheKey, membershipUser, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), System.Web.Caching.Cache.NoSlidingExpiration);

                return(membershipUser);
            }
            return(null);
        }
        public static string ValidateUserActiveDirectory(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(LoginStatus.LOGIN_ERROR);
            }
            else
            {
                AppUser login = new AppUser();

                login.Password = password;
                login.Name     = username;

                IAppUser appUserBO   = new AppUserBO();
                string   loginStatus = appUserBO.Authenticated(login);
                //string loginStatus = LoginStatus.OK;
                string statusReturn = loginStatus;

                switch (loginStatus)
                {
                case LoginStatus.OK:
                    var userRoles = new string[] { };
                    var cacheKey  = string.Format("UserRoles_{0}", login.Name);
                    int _cacheTimeoutInMinutes = 30;
                    userRoles = new[] { "Administrator" };
                    HttpRuntime.Cache.Insert(cacheKey, userRoles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), System.Web.Caching.Cache.NoSlidingExpiration);
                    break;
                }

                return(statusReturn);
            }
        }
예제 #4
0
        public string Update(AppUser appUser)
        {
            CustomIdentity customIdentity = (CustomIdentity)ControllerContext.HttpContext.User.Identity;

            try
            {
                IAppUser appUserBO = new AppUserBO(customIdentity.Name);
                string   message   = appUserBO.Update(appUser);
                return(message);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #5
0
        public JsonResult SearchUser(LdapUser user)
        {
            CustomIdentity customIdentity = (CustomIdentity)ControllerContext.HttpContext.User.Identity;

            try
            {
                List <LdapUser> listUser       = new List <LdapUser>();
                List <LdapUser> listUserFilter = new List <LdapUser>();
                if (ConfigurationManager.AppSettings["LdapMockup"].ToLower().Equals("true"))
                {
                    //Ldap ldap = new Ldap();

                    //listUser = ldap.GetList();

                    //if (user.UserName != "" && user.UserName != null)
                    //{
                    //    listUserFilter = listUser.FindAll(x => x.UserName.Trim().ToLower().Contains(user.UserName.Trim().ToLower()));
                    //}

                    //if (user.Name != "" && user.Name != null)
                    //{
                    //    listUserFilter = listUser.FindAll(x => x.Name.Trim().ToLower().Contains(user.Name.Trim().ToLower()));
                    //}

                    //if (user.Email != "" && user.Email != null)
                    //{
                    //    listUserFilter = listUser.FindAll(x => x.Email.Trim().ToLower().Contains(user.Email.Trim().ToLower()));
                    //}
                    //listUser = ldap.GetList().FindAll(x => x.UserName.Trim().ToLower().Contains(user.UserName.Trim().ToLower()) ||
                    //    x.Name.Trim().ToLower().Contains(user.Name.Trim().ToLower()) ||
                    //    x.Email.Trim().ToLower().Contains(user.Email.Trim().ToLower()));

                    return(Json(listUserFilter));
                }
                else
                {
                    IAppUser userBO = new AppUserBO(customIdentity.Name);
                    listUser = userBO.FindUserDirectory(user);
                    return(Json(listUser));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #6
0
        // GET: Users
        public ActionResult Index()
        {
            try
            {
                CustomIdentity customIdentity = (CustomIdentity)ControllerContext.HttpContext.User.Identity;
                IAppUser       appUserBO      = new AppUserBO();
                List <AppUser> listAppUser    = appUserBO.GetAllAppUser(x => x.Name != "lylAdmin");



                return(View(listAppUser));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #7
0
        public string Add(AppUser appUser)
        {
            CustomIdentity customIdentity = (CustomIdentity)ControllerContext.HttpContext.User.Identity;

            try
            {
                IAppUser appUserBO = new AppUserBO(customIdentity.Name);
                int      id        = appUserBO.Add(appUser);
                if (id > 0)
                {
                    return("Usuario agregado exitosamente");
                }
                return("Error Agregando usuario, intente nuevamente.");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }