public JObject GetGallery() { try { var id = HttpProxy.GetQueryString(CommonConst.CommonField.DISPLAY_ID); if (_paramContainer.GetKey(CommonConst.CommonField.DISPLAY_ID) != null) { id = (string)_paramContainer.GetKey(CommonConst.CommonField.DISPLAY_ID); Logger.Debug(string.Format("Filter on Gallery {0}", id)); ; } if (string.IsNullOrEmpty(id)) { return(GetAllGalleries()); } else { return(GetGalleryImages(id)); } } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject Scan() { try { var path = HttpProxy.GetQueryString(ImageProcessor.PATH); if (string.IsNullOrEmpty(path)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } var file_path = AppSettingService.GetAppSettingData("my_photo_path"); if (string.IsNullOrEmpty(file_path)) { Logger.Error("No file path from App setting"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } ImageProcessor ip = new ImageProcessor(); ip.Scan(file_path, path, DBProxy, KeyValueStorage, (string mesage) => { Logger.Debug(string.Format("ImageBackgroundSync: {0}", mesage)); return(true); }); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject Bookmark() { try { var fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); if (string.IsNullOrEmpty(fileHash) || string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (!ImageGalleryHelper.HasAccess(DBProxy, SessionProvider, galleryId, fileHash)) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); var filter = new JObject(); filter[CommonConst.CommonField.USER_ID] = user.user_id; var bookmarkData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_IMAGE_BOOKMARK_COLLECTION, filter.ToString()); if (bookmarkData == null) { bookmarkData = new JObject(); bookmarkData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID(); bookmarkData[CommonConst.CommonField.USER_ID] = user.user_id; bookmarkData[ImageProcessor.IMAGES] = new JArray(); } JObject bookmarrkResponse = new JObject(); var bookmarkFile = (bookmarkData[ImageProcessor.IMAGES] as JArray).FirstOrDefault(f => f[ImageProcessor.FILE_HASH].ToString() == fileHash); Logger.Debug("Get Bookmark data"); if (bookmarkFile != null) { (bookmarkData[ImageProcessor.IMAGES] as JArray).Remove(bookmarkFile); bookmarrkResponse[ImageProcessor.COUNT] = -1; Logger.Debug("Removed"); } else { bookmarkFile = new JObject(); bookmarkFile[ImageProcessor.FILE_HASH] = fileHash; bookmarkFile[ImageProcessor.GALLERY_ID] = galleryId; (bookmarkData[ImageProcessor.IMAGES] as JArray).Add(bookmarkFile); bookmarrkResponse[ImageProcessor.COUNT] = +1; Logger.Debug("Adding"); } DBProxy.Update(ImageProcessor.MYPHOTO_IMAGE_BOOKMARK_COLLECTION, filter.ToString(), bookmarkData, true, MergeArrayHandling.Replace); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, bookmarrkResponse)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
JObject GetGalleryPageData(JObject data) { string strPagesize = HttpProxy.GetQueryString(CommonConst.CommonField.PAGE_SIZE_KEY.ToLower()); string strCurrentPage = HttpProxy.GetQueryString(CommonConst.CommonField.CURRENT_PAGE_KEY.ToLower()); if (_paramContainer.GetKey(CommonConst.CommonField.PAGE_SIZE_KEY.ToLower()) != null) { strPagesize = (string)_paramContainer.GetKey(CommonConst.CommonField.PAGE_SIZE_KEY.ToLower()); } if (_paramContainer.GetKey(CommonConst.CommonField.CURRENT_PAGE_KEY.ToLower()) != null) { strCurrentPage = (string)_paramContainer.GetKey(CommonConst.CommonField.CURRENT_PAGE_KEY.ToLower()); } int pageSize = 50; int currentPage = 1; int.TryParse(strPagesize, out pageSize); int.TryParse(strCurrentPage, out currentPage); int startCount = (pageSize * (currentPage)); int endCount = startCount + pageSize; if (data[ImageProcessor.FILE_HASHS] == null) { data[ImageProcessor.FILE_HASHS] = new JArray(); } var fileHashs = (data[ImageProcessor.FILE_HASHS] as JArray); int totalPages = 0; if (fileHashs.Count > 0 && pageSize != 0) { totalPages = fileHashs.Count / pageSize; } var images = new JArray(); for (int i = startCount; i < endCount && i < fileHashs.Count; i++) { var fileData = ImageGalleryHelper.GetImageData(DBProxy, SessionProvider, fileHashs[i].ToString()); if (fileData.Count == 0) { Logger.Error(string.Format("Image File not found {0}", fileHashs[i].ToString())); } else { images.Add(fileData[0]); } } data.Remove(ImageProcessor.FILE_HASHS); data[ImageProcessor.IMAGES] = images; data[CommonConst.CommonField.PAGE_SIZE_KEY] = pageSize; data[CommonConst.CommonField.TOTAL_RECORD_COUNT_KEY] = fileHashs.Count; data[CommonConst.CommonField.TOTAL_PAGES_KEY] = totalPages; data[CommonConst.CommonField.CURRENT_PAGE_KEY] = currentPage; return(data); }
public JObject Like() { try { var fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); if (string.IsNullOrEmpty(fileHash) || string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (!ImageGalleryHelper.HasAccess(DBProxy, SessionProvider, galleryId, fileHash)) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); var filter = new JObject(); filter[ImageProcessor.FILE_HASH] = fileHash; var likeData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_IMAGE_LIKE_COLLECTION, filter.ToString()); if (likeData == null) { likeData = new JObject(); likeData[ImageProcessor.USERS] = new JArray(); likeData[ImageProcessor.FILE_HASH] = fileHash; likeData[ImageProcessor.COUNT] = 0; likeData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID(); } var totalCount = 0; int.TryParse(likeData[ImageProcessor.COUNT].ToString(), out totalCount); JObject like = new JObject(); var likeUser = (likeData[ImageProcessor.USERS] as JArray).FirstOrDefault(f => f.ToString() == user.user_id); if (likeUser != null) { (likeData[ImageProcessor.USERS] as JArray).Remove(likeUser); totalCount--; like[ImageProcessor.COUNT] = -1; } else { (likeData[ImageProcessor.USERS] as JArray).Add(user.user_id); totalCount++; like[ImageProcessor.COUNT] = +1; } likeData[ImageProcessor.COUNT] = (likeData[ImageProcessor.USERS] as JArray).Count; DBProxy.Update(ImageProcessor.MYPHOTO_IMAGE_LIKE_COLLECTION, filter.ToString(), likeData, true, MergeArrayHandling.Replace); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, like)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject UpdateAlbum() { try { var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); var requestBody = HttpProxy.GetRequestBody <JObject>(); if (requestBody == null || string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } var filter = new JObject(); filter[CommonConst.CommonField.DISPLAY_ID] = galleryId; var data = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString()); if (data == null) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (requestBody[ImageProcessor.DISPLAY_NAME] != null) { data[ImageProcessor.DISPLAY_NAME] = requestBody[ImageProcessor.DISPLAY_NAME].ToString(); } if (requestBody[ImageProcessor.DESCRIPTION] != null) { data[ImageProcessor.DESCRIPTION] = requestBody[ImageProcessor.DESCRIPTION].ToString(); } if (requestBody[ImageProcessor.GALLERY_THUMBNAIL] != null) { data[ImageProcessor.GALLERY_THUMBNAIL] = requestBody[ImageProcessor.GALLERY_THUMBNAIL].ToString(); } if (requestBody[ImageProcessor.AUTH_USERS] != null) { data[ImageProcessor.AUTH_USERS] = requestBody[ImageProcessor.AUTH_USERS]; } if (DBProxy.Update(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString(), data, false, MergeArrayHandling.Replace) != 1) { return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject DeleteImage() { try { var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); var fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); if (string.IsNullOrEmpty(galleryId) || string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } var filter = new JObject(); filter[CommonConst.CommonField.DISPLAY_ID] = galleryId; var galleryData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString()); if (galleryData == null) { Logger.Error(string.Format("Gallery Not found : Gallery: {0} ", galleryId)); return(ResponseBuilder.CreateReponse(CommonConst._404_RESOURCE_NOT_FOUND)); } if (galleryData[ImageProcessor.FILE_HASHS] == null) { return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } var filehashData = (galleryData[ImageProcessor.FILE_HASHS] as JArray).FirstOrDefault(f => f.ToString() == fileHash); if (filehashData != null) { (galleryData[ImageProcessor.FILE_HASHS] as JArray).Remove(filehashData); DBProxy.Update(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString(), galleryData, false, MergeArrayHandling.Replace); JObject responseData = new JObject(); responseData[ImageProcessor.FILE_HASH] = fileHash; return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, responseData)); } else { Logger.Error(string.Format("File Hash Not found : FileHash: {0} Gallery: {1} ", fileHash, galleryId)); return(ResponseBuilder.CreateReponse(CommonConst._404_RESOURCE_NOT_FOUND)); } } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public ModuleInstaller(ParamContainer requestParam) : base(requestParam) { _moduleInstaller = new ZNxtApp.Core.ModuleInstaller.Installer.ModuleInstaller(Logger, DBProxy); _moduleUninstaller = new ZNxtApp.Core.ModuleInstaller.Installer.Uninstaller(Logger, DBProxy); _moduleMethodCaller = (Func <string, JObject> methodCall) => { try { if (ApplicationConfig.GetApplicationMode == ApplicationMode.Maintenance) { var moduleName = HttpProxy.GetQueryString("module_name"); if (string.IsNullOrEmpty(moduleName)) { Logger.Info("ModuleInstaller module name is empty"); return(ResponseBuilder.CreateReponse(ModuleInstallerResponseCode._MODULE_NAME_EMPTY)); } try { var response = methodCall(moduleName); return(response); } catch (DirectoryNotFoundException dx) { Logger.Error(string.Format("ModuleInstaller module not found. Erro:{0}", dx.Message), dx); return(ResponseBuilder.CreateReponse(ModuleInstallerResponseCode._MODULE_NOT_FOUND)); } catch (FileNotFoundException fx) { Logger.Error(string.Format("ModuleInstaller module config not found. Erro:{0}", fx.Message), fx); return(ResponseBuilder.CreateReponse(ModuleInstallerResponseCode._MODULE_CONFIG_MISSING)); } } else { Logger.Info("ModuleInstaller.GetModuleDetails MAINTANCE_MODE_OFF"); return(ResponseBuilder.CreateReponse(ModuleInstallerResponseCode._MAINTANCE_MODE_OFF)); } } catch (Exception ex) { Logger.Error(string.Format("ModuleInstaller, Error:", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }; }
public JObject Get() { try { var collection = HttpProxy.GetQueryString("collection"); if (string.IsNullOrEmpty(collection)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } return(GetPaggedData(collection)); } catch (Exception ex) { Logger.Error(string.Format("CommonGetController.Get {0}", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject GetUserInfo() { try { var user_id = HttpProxy.GetQueryString(CommonConst.CommonField.USER_ID); if (string.IsNullOrEmpty(user_id)) { Logger.Debug("User id query string is null"); return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } var userData = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); if (userData == null) { Logger.Debug("User session data is null"); return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } if (userData.user_id != user_id) { Logger.Debug("User id conflict with session data"); return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } if (SignupHelper.IsValidToken(userData, SessionProvider, Logger, isOauthVerification)) { JArray joinData = new JArray(); JObject collectionJoin = GetCollectionJoin(CommonConst.CommonField.USER_ID, CommonConst.Collection.USER_INFO, CommonConst.CommonField.USER_ID, null, ModuleAppConsts.Field.USER_INFO); joinData.Add(collectionJoin); JObject filter = new JObject(); filter[CommonConst.CommonField.USER_ID] = user_id; var data = GetPaggedData(CommonConst.Collection.USERS, joinData, filter.ToString()); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data[CommonConst.CommonField.DATA][0])); } else { Logger.Debug("User Auth token is not valid"); SessionProvider.ResetSession(); return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } } catch (Exception ex) { Logger.Error(string.Format("UsersController.GetUserInfo {0}", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
private JObject ValidateOAuthTokenCreateUser(string authToken) { var redirect_url = HttpProxy.GetQueryString(CommonConst.CommonField.REDIRECT_URL_KEY); var URL = string.Format("https://graph.facebook.com/v2.8/me?access_token={0}&method=get&pretty=0&sdk=joey&suppress_http_code=1", authToken); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List data response. HttpResponseMessage response = client.GetAsync("").Result; // Blocking call! if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var dataObjects = response.Content.ReadAsStringAsync().Result; JObject responseJson = JObject.Parse(dataObjects); if (responseJson[CommonConst.CommonField.DISPLAY_ID] == null || responseJson[CommonConst.CommonField.NAME] == null) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } else { var userId = responseJson[CommonConst.CommonField.DISPLAY_ID].ToString(); if (CreateUser(userId, responseJson[CommonConst.CommonField.NAME].ToString(), UserIDType.Facebook)) { return(CreateSesssion(authToken, userId, redirect_url)); } else { return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } } else { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } }
//private List<string> GetCurrentAuthGroups() //{ // var user = SessionProvider.GetValue<UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); // var auth_users = new List<String> { "*" }; // if (user != null) // { // auth_users.Add(user.user_id); // auth_users.AddRange(user.groups); // } // return auth_users; //} //private bool IsValidaUser(JToken GalleryData) //{ // var auth_users = GetCurrentAuthGroups(); // bool isValid = false; // foreach (var auth in GalleryData[ImageProcessor.AUTH_USERS]) // { // if (auth_users.IndexOf(auth.ToString()) != -1) // { // isValid = true; // break; // } // } // return isValid; //} public JObject Get() { try { string fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); if (string.IsNullOrEmpty(fileHash)) { return(GetAll()); } else { return(GetFileInfo(fileHash)); } } catch (Exception ex) { Logger.Error(GetAllMessages(ex), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public JObject AddImage() { try { var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); if (string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } Logger.Debug(string.Format("File Count {0}", _fileUploader.GetFiles().Count)); if (_fileUploader.GetFiles().Count > 0) { JArray fileHashs = new JArray(); foreach (var fileName in _fileUploader.GetFiles()) { fileHashs.Add(UploadFile(galleryId, user, fileName, KeyValueStorage)); } JObject responseData = new JObject(); responseData[ImageProcessor.FILE_HASHS] = fileHashs; return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, responseData)); } else { Logger.Error("no File found"); return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
private JObject ValidateOAuthTokenCreateUser(string authToken) { var redirect_url = HttpProxy.GetQueryString(CommonConst.CommonField.REDIRECT_URL_KEY); var URL = string.Format("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={0}", authToken); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); HttpResponseMessage response = client.GetAsync("").Result; Logger.Debug("Getting data"); if (response.IsSuccessStatusCode) { var dataObjects = response.Content.ReadAsStringAsync().Result; JObject responseJson = JObject.Parse(dataObjects); Logger.Debug("Data", responseJson); if (responseJson["sub"] != null) { var userId = responseJson["sub"].ToString(); if (CreateUser(userId, responseJson[CommonConst.CommonField.NAME].ToString(), UserIDType.Google)) { return(CreateSesssion(authToken, userId, redirect_url)); } else { return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } else { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } } else { Logger.Debug("Http error " + response.RequestMessage); return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } }
private JObject GetFileInfo(string fileHash) { var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); if (string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } var galleryImages = GetGalleryImages(galleryId); if (galleryImages[CommonConst.CommonField.HTTP_RESPONE_CODE].ToString() != "1") { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } var data = ImageGalleryHelper.GetImageData(DBProxy, SessionProvider, fileHash, new List <string> { ImageProcessor.METADATA, ImageProcessor.TAGS, ImageProcessor.FILE_PATHS }); if (data.Count == 0) { return(ResponseBuilder.CreateReponse(CommonConst._404_RESOURCE_NOT_FOUND)); } else { AddToUserView(galleryId, fileHash); //JArray files = galleryImages[CommonConst.CommonField.DATA][ImageProcessor.IMAGES] as JArray; //data[0][ImageProcessor.RELATED_FILES] = new JArray(); //for (int i = 0; i < 10 && i < files.Count; i++) //{ // (data[0][ImageProcessor.RELATED_FILES] as JArray).Add(files[GetRandomNumberInRange(1, (files.Count - 1))]); //} return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, data[0])); } }
public JObject AdminChangeUserImage() { var user_id = HttpProxy.GetQueryString(CommonConst.CommonField.USER_ID); if (string.IsNullOrEmpty(user_id)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } Logger.Debug(string.Format("File Count {0}", _fileUploader.GetFiles().Count)); if (_fileUploader.GetFiles().Count > 0) { var path = string.Format("/frontend/{0}/{1}", "userpic", user_id); FileInfo fi = new FileInfo(_fileUploader.GetFiles()[0]); Logger.Debug(string.Format("Getting File Data")); byte[] fileData = _fileUploader.GetFileData(_fileUploader.GetFiles()[0]); JObject uploadReponse = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, Convert.ToBase64String(fileData)); Logger.Debug(string.Format("Uploaded default file"), uploadReponse); JObject uploadReponseS = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetSmallImage(fileData)); Logger.Debug(string.Format("Uploaded small file"), uploadReponseS); JObject uploadReponseM = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetMediumImage(fileData)); Logger.Debug(string.Format("Uploaded medium file"), uploadReponseM); JObject uploadReponseL = _fileUploader.SaveToDB(DBProxy, fi.Name, path, CommonConst.Collection.STATIC_CONTECT, null, ImageUtility.GetLargeImage(fileData)); Logger.Debug(string.Format("Uploaded large file"), uploadReponseL); if (uploadReponse != null && uploadReponseS != null && uploadReponseM != null && uploadReponseL != null) { var filePath = uploadReponse[CommonConst.CommonField.FILE_PATH].ToString(); var filePathS = uploadReponseS[CommonConst.CommonField.FILE_PATH].ToString(); var filePathM = uploadReponseM[CommonConst.CommonField.FILE_PATH].ToString(); var filePathL = uploadReponseL[CommonConst.CommonField.FILE_PATH].ToString(); JObject updateFilter = new JObject(); updateFilter[CommonConst.CommonField.USER_ID] = user_id; JObject userdata = new JObject(); userdata[ModuleAppConsts.Field.USER_PIC] = filePath; userdata[ModuleAppConsts.Field.USER_PIC_S] = filePathS; userdata[ModuleAppConsts.Field.USER_PIC_M] = filePathM; userdata[ModuleAppConsts.Field.USER_PIC_L] = filePathL; userdata[CommonConst.CommonField.USER_ID] = user_id; Logger.Debug("Updating User AdminChangeUserImage", userdata); var updateCount = DBProxy.Update(CommonConst.Collection.USER_INFO, updateFilter.ToString(), userdata, true); Logger.Debug(string.Format("AdminChangeUserImage UpdateCount:{0}", userdata)); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, userdata)); } else { Logger.Error(string.Format("Error while uploading image AdminChangeUserImage")); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR, uploadReponse)); } } else { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } }
public JObject Rotate() { try { var fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); var galleryId = HttpProxy.GetQueryString(ImageProcessor.GALLERY_ID); if (string.IsNullOrEmpty(fileHash) || string.IsNullOrEmpty(galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } if (!ImageGalleryHelper.IsOwner(DBProxy, SessionProvider, galleryId)) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } var fileData = ImageGalleryHelper.GetImage(DBProxy, fileHash); if (fileHash == null) { Logger.Error(string.Format("File not found ::{0}", fileHash)); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } var path = string.Empty; var baseFolderPath = AppSettingService.GetAppSettingData("my_photo_path"); if (string.IsNullOrEmpty(baseFolderPath)) { throw new KeyNotFoundException("my_photo_path"); } if (fileData[ImageProcessor.FILE_PATHS] == null) { throw new KeyNotFoundException(ImageProcessor.FILE_PATHS); } Logger.Debug(string.Format("Getting file info BasePath : {0}", baseFolderPath)); foreach (var item in fileData[ImageProcessor.FILE_PATHS]) { if (File.Exists(string.Concat(baseFolderPath, "\\", item.ToString()))) { path = string.Concat(baseFolderPath, "\\", item.ToString()); break; } } if (!File.Exists(path)) { throw new FileNotFoundException(path); } var changesetNo = 0; if (fileData[ImageProcessor.CHANGESET_NO] != null) { Logger.Debug(string.Format("changesetNo value from fileData {0}", fileData[ImageProcessor.CHANGESET_NO].ToString())); int.TryParse(fileData[ImageProcessor.CHANGESET_NO].ToString(), out changesetNo); } else { Logger.Debug(string.Format("changesetNo is null in fileData")); } Logger.Debug(string.Format("Image file path info BasePath : {0} File Name :{1}", baseFolderPath, path)); using (var image = ImageGalleryHelper.GetImageBitmapFromFile(path)) { Logger.Debug(string.Format("Processing Image BasePath : {0} File Name :{1}", baseFolderPath, path)); int rotate = 90; if (fileData[ImageProcessor.IMAGE_ROTATE] != null && int.TryParse(fileData[ImageProcessor.IMAGE_ROTATE].ToString(), out rotate)) { rotate += 90; if (rotate >= 360) { rotate = 0; } } switch (rotate) { case 90: ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.Rotate90FlipNone); Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.Rotate90FlipNone.ToString())); break; case 180: ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.Rotate180FlipNone); Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.Rotate180FlipNone.ToString())); break; case 270: ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.Rotate270FlipNone); Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.Rotate270FlipNone.ToString())); break; default: ImageGalleryHelper.ProcessImage(fileData, image, KeyValueStorage, RotateFlipType.RotateNoneFlipNone); Logger.Debug(string.Format("Rotate image to {0}. {1}", rotate, RotateFlipType.RotateNoneFlipNone.ToString())); break; } fileData[ImageProcessor.IMAGE_ROTATE] = rotate; } Logger.Debug(string.Format("changesetNo : {0}. FileHash: {1}", changesetNo, fileHash)); fileData[ImageProcessor.CHANGESET_NO] = (changesetNo + 1); JObject filter = new JObject(); filter[ImageProcessor.FILE_HASH] = fileHash; DBProxy.Update(ImageProcessor.MYPHOTO_COLLECTION, filter.ToString(), fileData, true, MergeArrayHandling.Replace); fileData.Remove(ImageProcessor.IMAGE_L_BASE64); fileData.Remove(ImageProcessor.IMAGE_M_BASE64); fileData.Remove(ImageProcessor.IMAGE_S_BASE64); return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, fileData)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public byte[] Get() { try { Logger.Debug("Calling Get JS "); var path = HttpProxy.GetQueryString("path"); if (string.IsNullOrEmpty(path)) { Logger.Error("Path is missing in the query string"); return(null); } var filterQuery = "{" + CommonConst.CommonField.FILE_PATH + ":/.js$/i}"; var data = DBProxy.Get(CommonConst.Collection.STATIC_CONTECT, filterQuery, new List <string> { CommonConst.CommonField.FILE_PATH }); Logger.Debug("Fetch value from Get JS"); var listOfArrays = new List <byte[]>(); var queryRecords = data.Select(l => new { length = l[CommonConst.CommonField.FILE_PATH].ToString().Length, file_path = l[CommonConst.CommonField.FILE_PATH].ToString() }).OrderBy(o => o.length).ToList(); Logger.Debug("Apply by Order by Get JS"); foreach (var item in queryRecords) { if (!string.IsNullOrEmpty(item.file_path) && item.file_path.IndexOf(path) == 0) { string jspath = item.file_path; if (jspath.IndexOf(CommonConst.CommonValue.APP_BACKEND_FOLDERPATH) == 1) { jspath = jspath.Replace(string.Format("/{0}", CommonConst.CommonValue.APP_BACKEND_FOLDERPATH), ApplicationConfig.AppBackendPath); } else if (jspath.IndexOf(CommonConst.CommonValue.APP_FRONTEND_FOLDERPATH) == 1) { jspath = jspath.Replace(string.Format("/{0}", CommonConst.CommonValue.APP_FRONTEND_FOLDERPATH), "/"); } var content = ContentHandler.GetContent(jspath); if (content != null) { if (ApplicationConfig.GetApplicationMode != ApplicationMode.Live) { listOfArrays.Add(Encoding.UTF8.GetBytes(string.Format("\n/*File: {0}*/\n", item.file_path))); } listOfArrays.Add(content); listOfArrays.Add(Encoding.UTF8.GetBytes("\n")); } } } return(listOfArrays .SelectMany(a => a) .ToArray()); } catch (Exception ex) { Logger.Error(string.Format("Error in GetJs {0}", ex.Message), ex); throw; } }
public JObject CreateUser() { Logger.Debug("Calling CreateUser"); JObject request = HttpProxy.GetRequestBody <JObject>(); var redirect_url = HttpProxy.GetQueryString(CommonConst.CommonField.REDIRECT_URL_KEY); if (request == null) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } var requestUser = GetUserDataFromRequest(request); if (IsOTPCheckEnable()) { var signUpUser = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY); if (signUpUser == null) { return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_NOT_FOUND)); } if (signUpUser.user_id != requestUser.user_id) { return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_DATA_MISMATCH)); } } if (request[CommonConst.CommonField.PASSWORD].ToString() != request[CommonConst.CommonField.CONFIRM_PASSWORD].ToString()) { return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_DATA_MISMATCH)); } var recaptchaResponse = request[ModuleAppConsts.Field.GOOGLE_RECAPTCHA_RESPONSE_KEY].ToString(); var capchaChecked = SessionProvider.GetValue <bool>(USER_REGISTRATION_CAPCHA_VALIDATION_SESSION_KEY); if (capchaChecked && !GoogleCaptchaHelper.ValidateResponse(Logger, recaptchaResponse, AppSettingService.GetAppSettingData(ModuleAppConsts.Field.GOOGLE_RECAPTCHA_SECRECT_SETTING_KEY), AppSettingService.GetAppSettingData(ModuleAppConsts.Field.GOOGLE_RECAPTCHA_VALIDATE_URL_SETTING_KEY))) { Logger.Info("Captcha validate fail"); return(ResponseBuilder.CreateReponse(AppResponseCode._CAPTCHA_VALIDATION_FAIL)); } else { SessionProvider.SetValue <bool>(USER_REGISTRATION_CAPCHA_VALIDATION_SESSION_KEY, true); } if (!IsUserExists(requestUser.user_id)) { if (CreateUser(requestUser, request[CommonConst.CommonField.PASSWORD].ToString())) { var user = DBProxy.FirstOrDefault <UserModel>(CommonConst.Collection.USERS, CommonConst.CommonField.USER_ID, requestUser.user_id); if (user == null) { Logger.Error(string.Format("User not found user_id : {0} ", requestUser.user_id)); return(ResponseBuilder.CreateReponse(AppResponseCode._USER_NOT_FOUND)); } else { SessionProvider.SetValue(CommonConst.CommonValue.SESSION_USER_KEY, user); var rurl = AppSettingService.GetAppSettingData(ModuleAppConsts.Field.SIGNUP_LENDING_PAGE_SETTING_KEY); JObject resonseData = new JObject(); if (string.IsNullOrEmpty(redirect_url)) { resonseData[CommonConst.CommonField.REDIRECT_URL_KEY] = rurl; } else { resonseData[CommonConst.CommonField.REDIRECT_URL_KEY] = string.Format("{0}?{1}={2}", rurl, CommonConst.CommonField.REDIRECT_URL_KEY, redirect_url); } return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, null, resonseData)); } } else { Logger.Error("Error while addd new user"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } else { Logger.Info(string.Format("User Exits with this phone number {0}", requestUser.user_id)); return(ResponseBuilder.CreateReponse(AppResponseCode._USER_EXISTS)); } }
public JObject ResetPassword() { try { Logger.Debug("Calling ResetPassword"); JObject request = HttpProxy.GetRequestBody <JObject>(); Logger.Debug("ResetPassword Request data", request); var redirect_url = HttpProxy.GetQueryString(CommonConst.CommonField.REDIRECT_URL_KEY); if (request == null) { return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST)); } var otp = request[CommonConst.CommonField.OTP].ToString(); var requestUser = GetUserDataFromRequest(request); var forgetpasswordUser = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SIGN_UP_SESSION_USER_KEY); if (forgetpasswordUser == null) { return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_NOT_FOUND)); } if (forgetpasswordUser.user_id != requestUser.user_id) { return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_DATA_MISMATCH)); } if (request[CommonConst.CommonField.PASSWORD].ToString() != request[CommonConst.CommonField.CONFIRM_PASSWORD].ToString()) { return(ResponseBuilder.CreateReponse(AppResponseCode._SESSION_USER_DATA_MISMATCH)); } var capchaChecked = SessionProvider.GetValue <bool>(USER_REGISTRATION_CAPCHA_VALIDATION_SESSION_KEY); if (!capchaChecked) { Logger.Info("Captcha validate fail"); return(ResponseBuilder.CreateReponse(AppResponseCode._CAPTCHA_VALIDATION_FAIL)); } bool OTPValidate = false; if (requestUser.user_type == UserIDType.PhoneNumber.ToString() && OTPService.Validate(requestUser.user_id, otp, OTPType.Forgetpassword, string.Empty)) { OTPValidate = true; } else if (requestUser.user_type == UserIDType.Email.ToString() && OTPService.ValidateEmail(requestUser.user_id, otp, OTPType.Forgetpassword, string.Empty)) { OTPValidate = true; } else { Logger.Error("Error OTP validation fail"); return(ResponseBuilder.CreateReponse(AppResponseCode._OTP_VALIDATION_FAIL)); } if (ResetPass(requestUser, request[CommonConst.CommonField.PASSWORD].ToString()) && OTPValidate) { var user = DBProxy.FirstOrDefault <UserModel>(CommonConst.Collection.USERS, CommonConst.CommonField.USER_ID, requestUser.user_id); var rurl = AppSettingService.GetAppSettingData(ModuleAppConsts.Field.FORGET_PASS_LENDING_PAGE_SETTING_KEY); JObject resonseData = new JObject(); if (string.IsNullOrEmpty(redirect_url)) { resonseData[CommonConst.CommonField.REDIRECT_URL_KEY] = rurl; } else { resonseData[CommonConst.CommonField.REDIRECT_URL_KEY] = string.Format("{0}?{1}={2}", rurl, CommonConst.CommonField.REDIRECT_URL_KEY, redirect_url); } return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, null, resonseData)); } else { Logger.Error("Error while ResetPassword"); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } } catch (Exception ex) { Logger.Error(string.Format("Forgetpassword.ResetPassword error : {0}", ex.Message), ex); return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR)); } }
public byte[] GetImage() { try { var fileHash = HttpProxy.GetQueryString(ImageProcessor.FILE_HASH); var type = HttpProxy.GetQueryString("t"); if (string.IsNullOrEmpty(fileHash)) { HttpProxy.SetResponse(400); } if (string.IsNullOrEmpty(type)) { type = "s"; } var imageType = ImageProcessor.IMAGE_S_BASE64; switch (type.Trim().ToLower()) { case "l": imageType = ImageProcessor.IMAGE_L_BASE64; break; case "m": imageType = ImageProcessor.IMAGE_M_BASE64; break; } JObject filter = new JObject(); filter[ImageProcessor.FILE_HASH] = fileHash; var data = DBProxy.Get(ImageProcessor.MYPHOTO_COLLECTION, filter.ToString(), new List <string> { imageType }); if (data.Count == 0) { Logger.Error("Data not found"); HttpProxy.SetResponse(404); return(null); } else { var base64 = string.Empty; if (data[0][imageType] != null) { base64 = data[0][imageType].ToString(); } else { try { base64 = KeyValueStorage.Get <string>(ImageProcessor.IMAGE_KEY_VALUE_BUCKET, ImageProcessor.GetFileKey(imageType, fileHash)); } catch (KeyNotFoundException ex) { Logger.Error(ex.Message, ex); } } if (string.IsNullOrEmpty(base64)) { HttpProxy.SetResponse(404); return(null); } HttpProxy.ResponseHeaders["Cache-Control"] = "public, max-age=172800"; return(System.Convert.FromBase64String(base64)); } } catch (Exception ex) { HttpProxy.SetResponse(500); Logger.Error(ex.Message, ex); return(null); } }
private JObject GetAllGalleries() { string filterKey = "filter"; var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY); var userId = HttpProxy.GetQueryString(CommonConst.CommonField.USER_ID); if (_paramContainer.GetKey(CommonConst.CommonField.USER_ID) != null) { userId = (string)_paramContainer.GetKey(CommonConst.CommonField.USER_ID); } if (!string.IsNullOrEmpty(userId) && user != null && userId != user.user_id) { return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED)); } int pagesize = 100; int currentpage = 1; string filter = "{}"; if (!string.IsNullOrEmpty(HttpProxy.GetQueryString(CommonConst.CommonField.PAGE_SIZE_KEY))) { int.TryParse(HttpProxy.GetQueryString(CommonConst.CommonField.PAGE_SIZE_KEY), out pagesize); } if (!string.IsNullOrEmpty(HttpProxy.GetQueryString(CommonConst.CommonField.CURRENT_PAGE_KEY))) { int.TryParse(HttpProxy.GetQueryString(CommonConst.CommonField.CURRENT_PAGE_KEY), out currentpage); } if (!string.IsNullOrEmpty(HttpProxy.GetQueryString(filterKey))) { var filterValue = HttpProxy.GetQueryString(filterKey); filter = "{display_name:{'$regex' : '" + filterValue + "', '$options' : 'i'}}"; Logger.Debug(filter); } //var sort = new Dictionary<string, int>(); //sort[CommonConst.CommonField.NAME] = 1; //sort[CommonConst.CommonField.ID] = 1; var response = GetPagedData(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter, new List <string> { CommonConst.CommonField.DISPLAY_ID, ImageProcessor.DISPLAY_NAME, ImageProcessor.DESCRIPTION, CommonConst.CommonField.NAME, ImageProcessor.FILES_COUNT, ImageProcessor.GALLERY_THUMBNAIL, ImageProcessor.AUTH_USERS, ImageProcessor.OWNER }, null, pagesize, currentpage); List <JToken> filterData = new List <JToken>(); foreach (var item in response[CommonConst.CommonField.DATA]) { if (string.IsNullOrEmpty(userId)) { ImageGalleryHelper.AddDefaultOwner(item); if (!ImageGalleryHelper.IsValidaUser(item, SessionProvider)) { filterData.Add(item); } else { if (item[ImageProcessor.OWNER] == null) { item[ImageProcessor.OWNER] = ImageProcessor.DEFAULT_OWNER; } AddGalleryThumbnailImage(item); } } else { if (item[ImageProcessor.OWNER] != null && item[ImageProcessor.OWNER].ToString() == userId) { AddGalleryThumbnailImage(item); } else { filterData.Add(item); } } } foreach (var item in filterData) { (response[CommonConst.CommonField.DATA] as JArray).Remove(item); } return(response); }