Ejemplo n.º 1
0
 public static string DoAction(string version, string data)
 {
     if (SiteMaster.VerifyRequest(HttpContext.Current.Session))
     {
         var          updateData = JsonConvert.DeserializeObject <CPOAction>(data);
         var          user       = HttpContext.Current.Session[SKeys.User] as User;
         ResponseType result     = ResponseType.ErrorCPOUnknown;
         try
         {
             result = ChangePOTracker.PerformAction(user, updateData);
         }
         catch
         {
             return(ApiResponse.JSONError(ResponseType.ErrorCPOUnknown));
         }
         if (result == ResponseType.SuccessCPO)
         {
             return(ApiResponse.JSONSuccess(ResponseDescription.Get(result)));
         }
         else
         {
             return(ApiResponse.JSONError(result));
         }
     }
     else
     {
         return(ApiResponse.JSONError(ResponseType.ErrorAuth));
     }
 }
Ejemplo n.º 2
0
        public string SubmitSupportRequest(string version, string data)
        {
            HttpSessionState session = HttpContext.Current.Session;
            var requestInfo          = HttpContext.Current.Request;

            var report = JsonConvert.DeserializeObject <ReportDetail>(data);

            if (report == null)
            {
                return(JsonConvert.SerializeObject(ApiResponse.Error(ResponseType.ErrorInvalidData), new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }
            else if (string.IsNullOrEmpty(report.Email))
            {
                return(JsonConvert.SerializeObject(ApiResponse.Error(ResponseType.ErrorSupportEmailRequired), new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }
            else if (string.IsNullOrEmpty(report.Message))
            {
                return(JsonConvert.SerializeObject(ApiResponse.Error(ResponseType.ErrorSupportMessageRequired), new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }

            string username = "";
            string customer = "EDIO";
            string partner  = "EDIO";
            var    user     = session[SKeys.User] as User;

            if (user != null)
            {
                username = user.UserName;
                customer = user.Customer;
                partner  = user.ActivePartner;
            }
            if (SupportRequest.Submit(requestInfo, report, username, customer, partner))
            {
                return(JsonConvert.SerializeObject(ApiResponse.Success(ResponseDescription.Get(ResponseType.SuccessSupportRequest)), new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }
            else
            {
                return(JsonConvert.SerializeObject(ApiResponse.Error(ResponseType.ErrorSupportUnknownError), new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }
        }
Ejemplo n.º 3
0
        public static string CheckUpload(string version, string data)
        {
            if (SiteMaster.VerifyRequest(HttpContext.Current.Session))
            {
                var user    = HttpContext.Current.Session[SKeys.User] as User;
                var session = HttpContext.Current.Session;
                if (session[SKeys.UploadResponse] == null)
                {
                    // No upload response.
                    return(ApiResponse.JSONSuccess());
                }
                var respStr = session[SKeys.UploadResponse] as string;
                if (string.IsNullOrWhiteSpace(respStr))
                {
                    // Key set, but no content.
                    return(ApiResponse.JSONSuccess());
                }
                session.Remove(SKeys.UploadResponse);

                ApiResponse response = JsonConvert.DeserializeObject <ApiResponse>(respStr);
                if (!response.success)
                {
                    // Error happened, so return that.
                    return(respStr);
                }

                // Get upload data.
                UploadDetail up = ((JObject)response.data).ToObject <UploadDetail>();
                if (up == null || string.IsNullOrWhiteSpace(up.Extension) || string.IsNullOrWhiteSpace(up.Token) || !SiteFileSystem.IsExtensionAllowed(up.Extension))
                {
                    // Response data was bad for some reason.
                    return(ApiResponse.JSONSuccess());
                }
                // Check upload data.
                if (Crypt.IsTokenGood(up.Token))
                {
                    string outFile = Path.Combine(SiteFileSystem.GetTempFileDirectory(), Path.GetRandomFileName());
                    string ecFile  = Path.Combine(SiteFileSystem.GetTempFileDirectory(), up.Token.Substring(32));
                    if (Crypt.DecryptTempFileToFile(user, outFile, up.Token))
                    {
                        // Remove old file.
                        File.Delete(ecFile);
                        // Then do verification.
                        ResponseType resp = POAcknowledgeManager.VerifyFile(user, outFile);
                        if (resp == ResponseType.SuccessAPO || resp == ResponseType.WarningAPOUnverifiedAccept)
                        {
                            // Good response, move the file
                            var isTest = (HttpContext.Current.Session[SKeys.IsTest] as bool?) == true;
                            try
                            {
                                var uploadFilePath = SiteFileSystem.GetUploadFileName(user, isTest, "855", up.Extension);
                                File.Move(outFile, uploadFilePath);
                                ProcessQueue.CreateUploadRecord(user, DateTime.Now, "855", Path.GetFileName(uploadFilePath));
                            }
                            catch
                            {
                                return(ApiResponse.JSONError(ResponseType.ErrorAPOUnknown));
                            }
                            if (resp == ResponseType.SuccessAPO)
                            {
                                return(ApiResponse.JSONSuccess(ResponseDescription.Get(resp)));
                            }
                            else
                            {
                                return(ApiResponse.JSONWarning(ResponseDescription.Get(resp)));
                            }
                        }
                        else
                        {
                            // Fail response, delete the file.
                            File.Delete(outFile);
                            return(ApiResponse.JSONError(resp));
                        }
                    }
                    else
                    {
                        return(ApiResponse.JSONError(ResponseType.ErrorAPOUnknown));
                    }
                }
                else
                {
                    // Bad token.
                    return(ApiResponse.JSONError(ResponseType.ErrorAPOUnknown));
                }
            }
            else
            {
                return(ApiResponse.JSONError(ResponseType.ErrorAuth));
            }
        }