示例#1
0
        //
        // GET: /Login/
        public ActionResult Index()
        {
            var model     = new LoginFormModel();
            var listLogin = new List <LdapDto>();

            EntityConnectionStringBuilder e = new EntityConnectionStringBuilder(ConfigurationManager.ConnectionStrings["FMSEntities"].ConnectionString);
            string        connectionString  = e.ProviderConnectionString;
            SqlConnection con = new SqlConnection(connectionString);

            con.Open();
            SqlCommand    query  = new SqlCommand("SELECT LOGIN, CONCAT(LOGIN,'-',SUBSTRING(AD_GROUP,23,10)) AS DISPLAY_LOGIN FROM LOGIN_FOR_VTI", con);
            SqlDataReader reader = query.ExecuteReader();

            while (reader.Read())
            {
                var item = new LdapDto();
                item.Login       = reader[0].ToString();
                item.DisplayName = reader[1].ToString();
                listLogin.Add(item);
            }
            reader.Close();
            con.Close();

            model.Users = new SelectList(listLogin, "Login", "DisplayName");
            return(View(model));
        }
示例#2
0
        private LdapDto DoLogin(string loginId)
        {
            var item = new LdapDto();
            EntityConnectionStringBuilder e = new EntityConnectionStringBuilder(ConfigurationManager.ConnectionStrings["FMSEntities"].ConnectionString);
            string        connectionString  = e.ProviderConnectionString;
            SqlConnection con = new SqlConnection(connectionString);

            con.Open();
            SqlCommand    query  = new SqlCommand("SELECT AD_GROUP, EMPLOYEE_ID, LOGIN, DISPLAY_NAME FROM LOGIN_FOR_VTI WHERE LOGIN = '******'", con);
            SqlDataReader reader = query.ExecuteReader();

            while (reader.Read())
            {
                item.ADGroup     = reader[0].ToString();
                item.EmployeeId  = reader[1].ToString();
                item.Login       = reader[2].ToString();
                item.DisplayName = reader[3].ToString();
                item.RoleName    = "USER";
                var arsplit = new List <string>();
                if (!string.IsNullOrEmpty(item.ADGroup))
                {
                    arsplit = item.ADGroup.Split(' ').ToList();
                    arsplit.RemoveAt(arsplit.Count - 1);
                    arsplit.RemoveAt(arsplit.Count - 1);
                    item.RoleName = string.Join(" ", arsplit.ToArray());
                    item.RoleName = item.RoleName.Substring(23);
                }
            }
            reader.Close();
            con.Close();

            return(item);
        }
示例#3
0
        public ActionResult Index(LoginFormModel model)
        {
            var item = new LdapDto();

            item = DoLogin(model.Login.UserId);

            IRoleBLL _roleBll = MvcApplication.GetInstance <RoleBLL>();

            if (item.Login != null)
            {
                var roles = _roleBll.GetRoles();
                CurrentUser                = new Login();
                CurrentUser.UserRole       = _roleBll.GetUserRole(item.RoleName);
                CurrentUser.AuthorizePages = roles.Where(x => x.RoleName == item.RoleName).ToList();
                CurrentUser.EMPLOYEE_ID    = item.EmployeeId;
                CurrentUser.USERNAME       = item.DisplayName;
                CurrentUser.USER_ID        = item.Login;

                CurrentUser.LoginFor = new List <LoginFor>();

                var delegationsList = _delegationBLL.GetDelegation().Where(x => x.LoginTo == item.Login &&
                                                                           x.DateFrom <= DateTime.Now &&
                                                                           x.DateTo >= DateTime.Now).ToList();
                foreach (var delegationDto in delegationsList)
                {
                    var loginForDto = DoLogin(delegationDto.LoginFrom);
                    if (loginForDto.Login != null)
                    {
                        CurrentUser.LoginFor.Add(new LoginFor()
                        {
                            UserRole       = _roleBll.GetUserRole(loginForDto.RoleName),
                            AuthorizePages = roles.Where(x => x.RoleName == loginForDto.RoleName).ToList(),
                            EMPLOYEE_ID    = loginForDto.EmployeeId,
                            EMPLOYEE_NAME  = loginForDto.DisplayName,
                            USER_ID        = loginForDto.Login
                        });
                    }
                }


                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Unauthorized", "Error"));
        }
示例#4
0
        public List <LdapDto> GetRoleUsers()
        {
            IRoleBLL _userBll = MvcApplication.GetInstance <RoleBLL>();
            EntityConnectionStringBuilder e = new EntityConnectionStringBuilder(ConfigurationManager.ConnectionStrings["FMSEntities"].ConnectionString);
            string        connectionString  = e.ProviderConnectionString;
            SqlConnection con = new SqlConnection(connectionString);

            con.Open();
            var list    = new List <String>();
            var typeEnv = ConfigurationManager.AppSettings["Environment"];
            var getrole = new List <LdapDto>();

            SqlCommand query =
                new SqlCommand("SELECT SETTING_VALUE FROM MST_SETTING WHERE SETTING_GROUP = 'USER_ROLE'", con);
            SqlDataReader reader = query.ExecuteReader();

            while (reader.Read())
            {
                var roleName = reader[0].ToString();
                list.Add(roleName);
            }
            reader.Close();

            if (typeEnv == "VTI")
            {
                query =
                    new SqlCommand("SELECT AD_GROUP, EMPLOYEE_ID, LOGIN,DISPLAY_NAME, EMAIL from LOGIN_FOR_VTI",
                                   con);

                reader = query.ExecuteReader();
                while (reader.Read())
                {
                    var data = new LdapDto();
                    data.ADGroup     = reader[0].ToString();
                    data.EmployeeId  = reader[1].ToString();
                    data.Login       = reader[2].ToString();
                    data.DisplayName = reader[3].ToString();
                    data.RoleName    = "USER";
                    var arsplit = new List <string>();
                    if (!string.IsNullOrEmpty(data.ADGroup))
                    {
                        arsplit = data.ADGroup.Split(' ').ToList();
                        arsplit.RemoveAt(arsplit.Count - 1);
                        arsplit.RemoveAt(arsplit.Count - 1);
                        data.RoleName = string.Join(" ", arsplit.ToArray());
                        data.RoleName = data.RoleName.Substring(23);
                        getrole.Add(data);
                    }
                }
                reader.Close();
            }
            else
            {
                foreach (var item in list)
                {
                    query =
                        new SqlCommand(
                            "SELECT ADGroup = '" + item +
                            "', employeeID, login = sAMAccountName, displayName FROM OPENQUERY(ADSI, 'SELECT employeeID, sAMAccountName, displayName, name, givenName, whenCreated, whenChanged, SN, manager, distinguishedName, info FROM ''LDAP://DC=PMINTL,DC=NET'' WHERE memberOf = ''CN = " +
                            item +
                            ", OU = ID, OU = Security, OU = IMDL Managed Groups, OU = Global, OU = Users & Workstations, DC = PMINTL, DC = NET''') ",
                            con);
                    reader = query.ExecuteReader();
                    while (reader.Read())
                    {
                        var data = new LdapDto();
                        data.ADGroup     = reader[0].ToString();
                        data.EmployeeId  = reader[1].ToString();
                        data.Login       = reader[2].ToString();
                        data.DisplayName = reader[3].ToString();
                        var arsplit = data.ADGroup.Split(' ').ToList();
                        arsplit.RemoveAt(arsplit.Count - 1);
                        arsplit.RemoveAt(arsplit.Count - 1);
                        data.RoleName = string.Join(" ", arsplit.ToArray());
                        data.RoleName = data.RoleName.Substring(23);
                        getrole.Add(data);
                    }
                    reader.Close();
                }
            }


            return(getrole);
        }