Пример #1
0
        public List <Dictionary <string, object> > validateUser(HttpRequestMessage req)
        {
            var    postedString  = req.Content.ReadAsStringAsync().Result;
            string base64Encoded = postedString;
            string base64Decoded;

            byte[] data = System.Convert.FromBase64String(base64Encoded);
            base64Decoded = System.Text.ASCIIEncoding.ASCII.GetString(data);
            dynamic d = JObject.Parse(Convert.ToString(base64Decoded));

            string username = Convert.ToString(d.username);
            string pwd      = Convert.ToString(d.password);
            List <Dictionary <string, object> > rows = new List <Dictionary <string, object> >();
            Dictionary <string, object>         row;

            row = new Dictionary <string, object>();
            obj = new DSL();
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "IEA"))
            {
                bool isValid = pc.ValidateCredentials(username, pwd, ContextOptions.Negotiate);
                if (isValid)
                {
                    using (UserPrincipal user = UserPrincipal.FindByIdentity(pc, username))
                    {
                        if (user != null)
                        {
                            //string employeeID = user.EmployeeId;
                            int get_session_id = obj.getSessionID(user.SamAccountName);
                            if (get_session_id > 0)
                            {
                                string Name = user.DisplayName;
                                row.Add("UserName", username);
                                row.Add("Name", Name);
                                row.Add("UserValidated", "true");
                                row.Add("UserID", user.SamAccountName);
                                row.Add("SessionID", get_session_id);
                                rows.Add(row);
                            }
                            else
                            {
                                string Name = user.DisplayName;
                                row.Add("UserName", username);
                                row.Add("Name", Name);
                                row.Add("UserValidated", "true");
                                row.Add("UserID", user.SamAccountName);
                                row.Add("SessionID", -1);
                                rows.Add(row);
                            }
                            return(rows);
                        }
                        else
                        {
                            row.Add("UserName", username);
                            row.Add("Name", "Not Found");
                            row.Add("UserValidated", "true");
                            row.Add("SessionID", -1);
                            rows.Add(row);
                            //string employeeID = user.EmployeeId;
                            return(rows);
                        }
                    }
                }
                else
                {
                    row.Add("UserName", username);
                    row.Add("Name", "Not Found");
                    row.Add("UserValidated", "false");
                    rows.Add(row);
                    //string employeeID = user.EmployeeId;
                    return(rows);
                }
            }
        }