Example #1
0
        /// <summary>
        /// Author:         Josephine Monteza
        /// Date Created:   14/Oct/2015
        /// Description:    Call API to update password in LDAP
        /// </summary>
        /// <returns></returns>
        public static void ChangePasswordInLDAP(string sUsername, string sNewPassword)
        {
            try
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sAPI = MUser.GetLDAP();
                    client.Headers.Add("content-type", "application/json");
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                    string sAPI_URL   = sAPI + "resetpass";
                    string sAPI_param = "user="******"&pass="******"LDAP Error: " + ex.Message;
            }
        }
Example #2
0
        /// <summary>
        /// Author:         Josephine Monteza
        /// Date Created:   14/Oct/2015
        /// Description:    Call API to update password in LDAP
        /// </summary>
        /// <returns></returns>
        public static void DeactivateUserInLDAP(string sUsername)
        {
            try
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sAPI = MUser.GetLDAP();
                    client.Headers.Add("content-type", "application/json");
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                    string sAPI_URL   = sAPI + "deactivate";
                    string sAPI_param = "user="******"&company=" + MUser.GetLDAPCompany();

                    string sResult = client.UploadString(sAPI_URL, sAPI_param);
                }
            }
            catch (Exception ex)
            {
                string sMsg = "LDAP Error: " + ex.Message;
            }
        }
Example #3
0
        /// <summary>
        /// Author:         Josephine Monteza
        /// Date Created:   15/Dec/2015
        /// Description:    Call API to logout user in LDAP
        /// </summary>
        /// <returns></returns>
        public static void LogoutUserInLDAP(string sUser)
        {
            try
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sAPI = MUser.GetLDAP();
                    client.Headers.Add("content-type", "application/json");
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                    string sAPI_URL   = sAPI + "signout";
                    string sAPI_param = "user="******"UserName"]);
                    sAPI_param = sAPI_param + "&company=" + MUser.GetLDAPCompany();

                    string sResult = client.UploadString(sAPI_URL, sAPI_param);
                }
            }
            catch (Exception ex)
            {
                string sMsg = "LDAP Error: " + ex.Message;
                throw ex;
            }
        }
Example #4
0
        /// <summary>
        /// Author:         Josephine Monteza
        /// Date Created:   30/Oct/2015
        /// Description:    Check if Session valid in LDAP
        /// </summary>
        public static string EmailUserLDAP(string sUser, string sPurpose)
        {
            string sReturn = "";

            try
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sAPI = MUser.GetLDAPUrl();
                    client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";


                    string sParam = "username="******"&company=" + MUser.GetLDAPCompany() + "&purpose=" + sPurpose;
                    //string sResult = client.DownloadString(sAPI + "emailcenter.php" + sParam);
                    string sResult = client.UploadString(sAPI + "emailcenter.php", sParam);

                    string[] sResultArray;
                    sResultArray = sResult.Split(",{".ToCharArray());

                    string   sStatus = "";
                    string[] sStatusArray;
                    for (int i = 0; i < sResultArray.Count(); i++)
                    {
                        if (sResultArray[i].Contains("\"statuscode\""))
                        {
                            sStatusArray = sResultArray[i].Split(":".ToCharArray());
                            sStatus      = sStatusArray[1].Replace("\"", "");
                            sStatus      = sStatus.Replace("}", "");
                        }
                    }

                    ////verify if the sid is valid for the user
                    //string sAPI_sid = sAPI + "sid";
                    //string sAPI_param = "sid=" + sLDAPSid;
                    //string sSID_User = "";
                    //string sSID_Message = "";
                    //string sSID_Company = "";

                    //string[] sSID_MessageArray;


                    ////verify if the sid is valid in LDAP
                    //client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    //sResult = client.UploadString(sAPI_sid, sAPI_param);
                    //sResultArray = sResult.Split(",{".ToCharArray());

                    //for (int i = 0; i < sResultArray.Count(); i++)
                    //{
                    //    if (sResultArray[i].Contains("\"message\""))
                    //    {
                    //        sSID_MessageArray = sResultArray[i].Split(":".ToCharArray());
                    //        sSID_Message = sSID_MessageArray[1].Replace("\"", "");
                    //        sSID_Message = sSID_Message.Replace("}", "");
                    //    }

                    //    if (sResultArray[i].Contains("\"user\""))
                    //    {
                    //        sSID_MessageArray = sResultArray[i].Split(":".ToCharArray());
                    //        sSID_User = sSID_MessageArray[1].Replace("\"", "");
                    //        sSID_User = sSID_User.Replace("}", "");
                    //    }
                    //    if (sResultArray[i].Contains("\"cn\""))
                    //    {
                    //        sSID_MessageArray = sResultArray[i].Split(":".ToCharArray());
                    //        sSID_Company = sSID_MessageArray[1].Replace("\"", "");
                    //        sSID_Company = sSID_Company.Replace("}", "");
                    //    }
                    //}

                    sReturn = sStatus;
                }
                return(sReturn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        public static List <UserList_LDAP> GetLDAPUser(string sEmail)
        {
            List <UserList_LDAP> list = new List <UserList_LDAP>();

            string sCompany;

            using (System.Net.WebClient client = new System.Net.WebClient())
            {
                string sAPI = MUser.GetLDAP();


                client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers


                //verify if the username exist in LDAP
                string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray());


                foreach (var arrayValue in ArrayResult)
                {
                    var key   = arrayValue.Key;
                    var value = arrayValue.Value;

                    if (key == "status")
                    {
                        if (GlobalCode.Field2String(value).ToLower() == "true")
                        {
                        }
                        else
                        {
                            break;
                        }
                    }
                    else if (key == "result")
                    {
                        if (value != null)
                        {
                            ArrayResultChild = (Dictionary <string, object>)value;
                            foreach (var ResultChild in ArrayResultChild)
                            {
                                var resultChildKey   = ResultChild.Key;
                                var resultChildValue = ResultChild.Value;

                                //if (resultChildKey == "entries")
                                //{
                                //    if (resultChildValue != null)
                                //    {
                                //        ArrayResultEntries = (Dictionary<string, object>)resultChildValue;
                                //        foreach (var resultEntries in ArrayResultEntries)
                                //        {
                                //            if (resultEntries.Key == "uid")
                                //                sUserName = GlobalCode.Field2String(resultEntries.Value);
                                //        }
                                //    }
                                //}
                                if (resultChildKey == "member")
                                {
                                    if (resultChildValue != null)
                                    {
                                        var arrCompanyValue = (ArrayList)resultChildValue;//(List<string>)resultChildValue;

                                        for (var i = 0; i < arrCompanyValue.Count; i++)
                                        {
                                            if (GlobalCode.Field2String(arrCompanyValue[i]) == MUser.GetLDAPCompany())
                                            {
                                                sCompany = GlobalCode.Field2String(GlobalCode.Field2String(arrCompanyValue[i]));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(list);
        }
Example #6
0
        /// <summary>
        /// Author:         Josephine Monteza
        /// Date Created:   30/Oct/2015
        /// Description:    Check if Session valid in LDAP
        /// </summary>
        public static bool IsLDAPSessionValid(string sLDAPUser, string sLDAPSid)
        {
            bool bReturn = false;

            try
            {
                if (sLDAPSid == "")
                {
                    return(true);
                }
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sAPI = MUser.GetLDAP();
                    client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers


                    //verify if the username exist in LDAP
                    string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray());

                    string   sUserName = "";
                    string[] sUserNameArray;
                    for (int i = 0; i < sResultArray.Count(); i++)
                    {
                        if (sResultArray[i].Contains("\"uid\""))
                        {
                            sUserNameArray = sResultArray[i].Split(":".ToCharArray());
                            sUserName      = sUserNameArray[1].Replace("\"", "");
                            sUserName      = sUserName.Replace("}", "");
                        }
                    }

                    //verify if the sid is valid for the user
                    string sAPI_sid     = sAPI + "sid";
                    string sAPI_param   = "sid=" + sLDAPSid;
                    string sSID_User    = "";
                    string sSID_Message = "";
                    string sSID_Company = "";

                    string[] sSID_MessageArray;


                    //verify if the sid is valid in LDAP
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    sResult      = client.UploadString(sAPI_sid, sAPI_param);
                    sResultArray = sResult.Split(",{".ToCharArray());

                    for (int i = 0; i < sResultArray.Count(); i++)
                    {
                        if (sResultArray[i].Contains("\"message\""))
                        {
                            sSID_MessageArray = sResultArray[i].Split(":".ToCharArray());
                            sSID_Message      = sSID_MessageArray[1].Replace("\"", "");
                            sSID_Message      = sSID_Message.Replace("}", "");
                        }

                        if (sResultArray[i].Contains("\"user\""))
                        {
                            sSID_MessageArray = sResultArray[i].Split(":".ToCharArray());
                            sSID_User         = sSID_MessageArray[1].Replace("\"", "");
                            sSID_User         = sSID_User.Replace("}", "");
                        }
                        if (sResultArray[i].Contains("\"cn\""))
                        {
                            sSID_MessageArray = sResultArray[i].Split(":".ToCharArray());
                            sSID_Company      = sSID_MessageArray[1].Replace("\"", "");
                            sSID_Company      = sSID_Company.Replace("}", "");
                        }
                    }

                    if (sSID_Message != "Session is valid.")
                    {
                        //LabelLoginErrorDetails.Text = "LDAP Authentication: Invalid Session ID!";
                        return(false);
                    }
                    if (sSID_User.ToLower() != sUserName.ToLower())
                    {
                        //LabelLoginErrorDetails.Text = "LDAP Authentication: Username is not valid!";
                        return(false);
                    }

                    string sAPICompany = MUser.GetLDAPCompany();
                    if (sSID_Company.ToLower() != sAPICompany.ToLower())
                    {
                        //LabelLoginErrorDetails.Text = "LDAP Authentication: Invalid company!";
                        return(false);
                    }
                    bReturn = true;
                }
                return(bReturn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        /// <summary>
        /// Date Created:   28/Oct/2015
        /// Created By:     Josephine Monteza
        /// (description)   Add/Edit user from LDAP
        /// </summary>
        public static string AddEditUserFromLDAP(string strUsername, string strFName,
                                                 string strLName, string strEmail, string strPWD, string sType, string strEmailNew)
        {
            string sReturn = "";

            try
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sAPI = MUser.GetLDAP();


                    client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers


                    //verify if the username exist in LDAP
                    string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray());

                    string sUserName = "";
                    string sCompany  = "";
                    //bool IsExistinLDAP = false;

                    foreach (var arrayValue in ArrayResult)
                    {
                        var key   = arrayValue.Key;
                        var value = arrayValue.Value;

                        if (key == "status")
                        {
                            if (GlobalCode.Field2String(value).ToLower() == "true")
                            {
                                sUserName = strUsername;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else if (key == "result")
                        {
                            if (value != null)
                            {
                                ArrayResultChild = (Dictionary <string, object>)value;
                                foreach (var ResultChild in ArrayResultChild)
                                {
                                    var resultChildKey   = ResultChild.Key;
                                    var resultChildValue = ResultChild.Value;

                                    //if (resultChildKey == "entries")
                                    //{
                                    //    if (resultChildValue != null)
                                    //    {
                                    //        ArrayResultEntries = (Dictionary<string, object>)resultChildValue;
                                    //        foreach (var resultEntries in ArrayResultEntries)
                                    //        {
                                    //            if (resultEntries.Key == "uid")
                                    //                sUserName = GlobalCode.Field2String(resultEntries.Value);
                                    //        }
                                    //    }
                                    //}
                                    if (resultChildKey == "member")
                                    {
                                        if (resultChildValue != null)
                                        {
                                            var arrCompanyValue = (ArrayList)resultChildValue;//(List<string>)resultChildValue;

                                            for (var i = 0; i < arrCompanyValue.Count; i++)
                                            {
                                                if (GlobalCode.Field2String(arrCompanyValue[i]) == MUser.GetLDAPCompany())
                                                {
                                                    sCompany = GlobalCode.Field2String(GlobalCode.Field2String(arrCompanyValue[i]));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";


                    //if user exist in LDAP TM, do not do anything
                    if (strUsername == sUserName && sCompany == MUser.GetLDAPCompany())
                    {
                        //Update user
                        string sEditUser  = sAPI + "modify";
                        string sParameter = "user="******"&firstname=" + strFName;
                        //sParameter = sParameter + "&middlename=" + "";
                        //sParameter = sParameter + "&lastname=" + strLName;
                        //sParameter = sParameter + "&description=EditedFromTravelmartSite";
                        //sParameter = sParameter + "&active=1";

                        //sResult = client.UploadString(sEditUser, sParameter);

                        //Update Email
                        sEditUser  = sAPI + "changemail";
                        sParameter = "user="******"&email=" + strEmailNew;

                        client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                        sResult = client.UploadString(sEditUser, sParameter);

                        sResultArray = sResult.Split(",{".ToCharArray());
                        string[] sSuccessArray;
                        string   sSuccessfull;

                        for (int i = 0; i < sResultArray.Count(); i++)
                        {
                            if (sResultArray[i].Contains("\"message\""))
                            {
                                sSuccessArray = sResultArray[i].Split(":".ToCharArray());
                                sSuccessfull  = sSuccessArray[1].Replace("\"", "");
                                sReturn       = sSuccessfull.Replace("}", "");
                            }
                        }

                        sReturn = " User Edit: " + sReturn;
                    }

                    //if user exist but no TM app, password is blank
                    else if (strUsername == sUserName && sCompany != MUser.GetLDAPCompany())
                    {
                        string sAddUser   = sAPI + "add";
                        string sParameter = "user="******"&pass="******"&email=" + strEmail;
                        sParameter = sParameter + "&firstname=" + strFName;
                        sParameter = sParameter + "&middlename=" + "";
                        sParameter = sParameter + "&lastname=" + strLName;
                        sParameter = sParameter + "&description=AddedFromTravelmartSite";
                        sParameter = sParameter + "&company=" + MUser.GetLDAPCompany();


                        sResult      = client.UploadString(sAddUser, sParameter);
                        sResultArray = sResult.Split(",{".ToCharArray());
                        string[] sSuccessArray;
                        string   sSuccessfull;

                        for (int i = 0; i < sResultArray.Count(); i++)
                        {
                            if (sResultArray[i].Contains("\"message\""))
                            {
                                sSuccessArray = sResultArray[i].Split(":".ToCharArray());
                                sSuccessfull  = sSuccessArray[1].Replace("\"", "");
                                sReturn       = sSuccessfull.Replace("}", "");
                            }
                        }
                        sReturn = " User Add with Other App: " + sReturn;
                    }
                    else
                    {
                        if (sType == "Edit")
                        {
                            MembershipUser mUser     = Membership.GetUser(strUsername);
                            string         sPassword = DateTime.Now.ToLongTimeString().Replace(" ", "").Replace(":", "");
                            strPWD = sPassword;
                        }

                        string sAddUser   = sAPI + "add";
                        string sParameter = "user="******"&pass="******"&email=" + strEmail;
                        sParameter = sParameter + "&firstname=" + strFName;
                        sParameter = sParameter + "&middlename=" + "";
                        sParameter = sParameter + "&lastname=" + strLName;
                        sParameter = sParameter + "&description=FirstAddedFromTravelmartSite";
                        sParameter = sParameter + "&company=" + MUser.GetLDAPCompany();


                        sResult      = client.UploadString(sAddUser, sParameter);
                        sResultArray = sResult.Split(",{".ToCharArray());
                        string[] sSuccessArray;
                        string   sSuccessfull;

                        for (int i = 0; i < sResultArray.Count(); i++)
                        {
                            if (sResultArray[i].Contains("\"message\""))
                            {
                                sSuccessArray = sResultArray[i].Split(":".ToCharArray());
                                sSuccessfull  = sSuccessArray[1].Replace("\"", "");
                                sReturn       = sSuccessfull.Replace("}", "");
                            }
                        }
                        sReturn = " User Add New User: "******" - " + ex.Message;
                throw ex;
            }
            finally
            {
                sReturn = "";
            }
        }