コード例 #1
0
ファイル: security.cs プロジェクト: yarivat/Admin
        public object compare(string password, string hashedPassword)
        {
            string         url     = BaseUrl + "/security/compare";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("password", password);
            data.Add("hashedPassword", hashedPassword);

            request.setRequestHeader("content-type", "application/json");

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            request.send(jss.Serialize(data));

            if (request.status == 200)
            {
                return(true);
            }
            else if (request.status == 401)
            {
                return(false);
            }

            else
            {
                throw new Durados.DuradosException("Server return status " + request.status + ", " + request.responseText);
            }
        }
コード例 #2
0
ファイル: filesBackand.cs プロジェクト: yarivat/Admin
        protected string UploadFile(Dictionary <string, object> data)
        {
            if (!data.ContainsKey(StorageKeys.Storage) || data[StorageKeys.Storage] == null)
            {
                throw new Durados.DuradosException(Messages.MissingStorageObjectInJS);
            }

            if (!(data[StorageKeys.Storage] as Dictionary <string, object>).ContainsKey(StorageKeys.FileName))
            {
                throw new Durados.DuradosException(Messages.MissingFileName);
            }

            string fileName = ((Dictionary <string, object>)data[StorageKeys.Storage])[StorageKeys.FileName].ToString();

            string         url     = BaseUrl + "/uploadFile";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);

            request.setRequestHeader("content-type", "application/json");

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            jss.MaxJsonLength = int.MaxValue;
            request.send(jss.Serialize(data));


            if (request.status != 200)
            {
                if (Logger != null)
                {
                    Logger.Log("files", "upload", fileName, "Server return status " + request.status, request.responseText, 1, "upload " + fileName, DateTime.Now, 0);
                }

                throw new Durados.DuradosException(request.responseText);//"Server return status " + request.status + ", " +
            }

            if (Logger != null)
            {
                Logger.Log("files", "upload", fileName, null, 3, "upload " + fileName, DateTime.Now, 0);
            }


            Dictionary <string, object> response = null;

            try
            {
                response = jss.Deserialize <Dictionary <string, object> >(request.responseText);
            }
            catch (Exception exception)
            {
                throw new Durados.DuradosException("Could not parse upload response", exception);
            }

            if (!response.ContainsKey("link"))
            {
                throw new Durados.DuradosException("The response does not contain the link");
            }
            return(response["link"].ToString());
        }
コード例 #3
0
        public override void delete(string fileName, string bucket, string path)
        {
            string         url     = BaseUrl + "/deleteFile";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);

            Dictionary <string, object> data = GetFileDetails(fileName, bucket, path);

            request.setRequestHeader("content-type", "application/json");

            request.send(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(data));

            if (request.status != 200)
            {
                throw new Durados.DuradosException(request.responseText);//"Server return status " + request.status + ", " +
            }
        }
コード例 #4
0
ファイル: filesBackand.cs プロジェクト: yarivat/Admin
        public virtual void delete(string fileName, string bucket = null, string path = null)
        {
            string         url     = BaseUrl + "/deleteFile";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);

            string appName = System.Web.HttpContext.Current.Items[Durados.Database.AppName].ToString();
            Dictionary <string, object> data = GetFileDetails(fileName, S3FilesBucket, appName);

            request.setRequestHeader("content-type", "application/json");

            request.send(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(data));

            if (request.status != 200)
            {
                throw new Durados.DuradosException("Server return status " + request.status + ", " + request.responseText);
            }
        }
コード例 #5
0
ファイル: security.cs プロジェクト: yarivat/Admin
        public object hash(string password, string salt)
        {
            string         url     = BaseUrl + "/security/hash";
            XMLHttpRequest request = new XMLHttpRequest();

            request.open("POST", url, false);
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("password", password);
            if (!string.IsNullOrEmpty(salt))
            {
                data.Add("salt", salt);
            }

            request.setRequestHeader("content-type", "application/json");

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            request.send(jss.Serialize(data));

            if (request.status == 200)
            {
                Dictionary <string, object> response = null;
                try
                {
                    response = jss.Deserialize <Dictionary <string, object> >(request.responseText);
                }
                catch (Exception exception)
                {
                    throw new Durados.DuradosException("Failed to deserialize hash response " + request.status + ", " + request.responseText, exception);
                }
                if (!response.ContainsKey(Encrypted))
                {
                    throw new Durados.DuradosException("hash response not contain encrypted " + request.status + ", " + request.responseText);
                }
                return(response[Encrypted]);
            }
            else
            {
                throw new Durados.DuradosException("Server return status " + request.status + ", " + request.responseText);
            }
        }
コード例 #6
0
ファイル: socket.cs プロジェクト: yarivat/Admin
        private object EmitPrivate(string eventName, object data, string appName, string mode, string role = "", object users = null)
        {
            try
            {
                XMLHttpRequest xmlHttpRequest = new XMLHttpRequest();
                xmlHttpRequest.open("POST", GetNodeUrl() + "/socket/emit", false);
                xmlHttpRequest.setRequestHeader("Content-Type", "application/json");
                xmlHttpRequest.setRequestHeader("app", appName ?? GetAppName());
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

                // data
                Dictionary <string, object> newData = new Dictionary <string, object>();
                newData.Add("eventName", eventName);
                newData.Add("mode", mode);


                switch (mode)
                {
                case "Role":
                    newData.Add("role", role);
                    break;

                case "Users":
                    newData.Add("users", users);
                    break;

                default:
                    break;
                }


                object json = data;
                try
                {
                    if (data != null && data is string)
                    {
                        json = serializer.Deserialize <Dictionary <string, object> >((string)data);
                    }
                }
                catch
                {
                }

                newData.Add("data", json);

                // save requests for tests
                if (SentMessagesMock != null)
                {
                    SentMessagesMock.Add(xmlHttpRequest);
                }

                // sehd data to server
                xmlHttpRequest.send(serializer.Serialize(newData));

                if (Logger != null)
                {
                    Logger.Log("socket", "emit", eventName, null, 3, "emit " + mode + " " + eventName, DateTime.Now, 0);
                }

                // send response to user
                return(new { status = xmlHttpRequest.status, message = xmlHttpRequest.responseText });
            }
            catch (Exception exception)
            {
                if (Logger != null)
                {
                    Logger.Log("socket", "emit", eventName, exception, 1, "emit " + mode + " " + eventName, DateTime.Now, 0);
                }
                return(new { status = 502, message = exception.Message });
            }
        }