public ActionResult Create([Bind(Include = "Id,UserId,Description,Content")] CreatePictureViewModel picture, string tags, HttpPostedFileBase ContentFile)
        {
            if (ContentFile == null)
            {
                ViewBag.Error     = "You have not chosen a picture.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (ModelState.IsValid)
            {
                var tagsList      = tags.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var currentUserId = AuthManager.GetAuthenticated().Id;
                var description   = picture.Description;
                var contentFile   = ContentFile;

                var content       = PictureUtilities.PictureToByteArray(contentFile);
                var pictureEntity = new Picture()
                {
                    Content     = content,
                    Description = description,
                    UserId      = currentUserId
                };
                pictureEntity = TagsController.Create(tagsList, pictureEntity, db);
                db.Pictures.Add(pictureEntity);
                db.SaveChanges();
                return(RedirectToAction("Details/" + currentUserId, "Users"));
            }
            return(View(picture));
        }
        private async Task <bool> openHiddenImage(StorageFile hiddenImageFile)
        {
            if (await this.isHiddenImageTooLarge(hiddenImageFile))
            {
                return(false);
            }

            var copyBitmapImage = await FileUtilities.MakeCopyOfTheImage(hiddenImageFile);

            await PictureUtilities.LoadImageData(this.HiddenPicture, hiddenImageFile, copyBitmapImage);

            return(true);
        }
        public ActionResult Edit([Bind(Include = "Id,Name,Username,Password,Email,RepeatPassword,Biography,IsPrivate")] User user, HttpPostedFileBase profilePictureFile)
        {
            if (!UserValidations.ValidateEmail(user.Email))
            {
                ViewBag.Error     = "Your email is invalid. Please enter a valid one.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidateUsername(user.Username))
            {
                ViewBag.Error     = "Your username is invalid. It should be between 3 and 50 characters long.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidatePassword(user.Password))
            {
                ViewBag.Error     = "Your password is invalid. It should be at least 8 characters long, contain at least one small and one big letter and one digit.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidateRepeatedPassword(user.Password, user.RepeatPassword))
            {
                ViewBag.Error     = "Your passwords do not match.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidateProfilePicture(profilePictureFile))
            {
                ViewBag.Error     = "You have not chosen a profile picture.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (ModelState.IsValid)
            {
                user.RegisterProfilePicture = PictureUtilities.PictureToByteArray(profilePictureFile);
                repo.Update(user);
                return(RedirectToAction("Details/" + AuthManager.GetAuthenticated().Id, "Users"));
            }
            return(View(user));
        }
        private async Task <bool> isTextFileTooBig()
        {
            var textArray = this.HiddenText.StringToBitArray();
            var pixels    = PictureUtilities.ConvertBytesIntoBitArray(this.SourcePicture);

            if (textArray.Length > pixels.Length / ImageConstants.ByteLength * this.BitsPerColorChannel)
            {
                await this.showMessageCantFitDialog(textArray, pixels);

                return(true);
            }

            return(false);
        }
        private async Task openDraggedFile(DragEventArgs dragEvent)
        {
            if (dragEvent.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await dragEvent.DataView.GetStorageItemsAsync();

                var sourceImageFile = items[0] as StorageFile;
                var copyBitmapImage = await FileUtilities.MakeCopyOfTheImage(sourceImageFile);

                if (sourceImageFile != null)
                {
                    await PictureUtilities.LoadImageData(this.SourcePicture, sourceImageFile, copyBitmapImage);
                }
            }
        }
        /// <summary>
        ///     Opens the source image.
        /// </summary>
        /// <returns>
        ///     true if file opened, false otherwise
        /// </returns>
        public async Task <bool> OpenSourceImage()
        {
            var sourceImageFile = await FileUtilities.SelectFile();

            if (!await this.isFileValid(sourceImageFile))
            {
                return(false);
            }

            var copyBitmapImage = await FileUtilities.MakeCopyOfTheImage(sourceImageFile);

            await PictureUtilities.LoadImageData(this.SourcePicture, sourceImageFile, copyBitmapImage);

            return(true);
        }
Beispiel #7
0
        private string extractTextFromBytes()
        {
            var text       = new StringBuilder();
            var binaryText = new StringBuilder();
            var pixels     = PictureUtilities.ConvertBytesIntoBitArray(this.sourcePicture);

            for (var i = 0; i < pixels.Length; i++)
            {
                if (this.getTextFromBits(i, pixels, binaryText, text, out var extractTextFromBytes1))
                {
                    return(extractTextFromBytes1);
                }
            }

            return(text.ToString());
        }
Beispiel #8
0
        private void textEmbedding(string text)
        {
            text  = this.removeNonLettersIfNotEncrypted(text);
            text += this.endOfText;
            var textArray      = text.StringToBitArray();
            var textArrayIndex = 0;
            var pixels         = PictureUtilities.ConvertBytesIntoBitArray(this.sourcePicture);

            this.MessageTooLarge = false;
            for (var i = 0; i < pixels.Length; i++)
            {
                if (this.changeBitsPerByte(i, pixels, textArray, ref textArrayIndex))
                {
                    return;
                }
            }
        }
        /// <summary>
        ///     Converts image to Picture then saves it.
        /// </summary>
        /// <param name="image">The image.</param>
        public async Task SaveImage(Image image)
        {
            var picture = await PictureUtilities.ConvertImageToPicture(image);

            FileUtilities.SaveImage(picture);
        }
Beispiel #10
0
        public ActionResult Create([Bind(Include = "Id,Name,Username,Password,Email,RepeatPassword,Biography,IsPrivate")] User user, HttpPostedFileBase profilePictureFile)
        {
            if (!UserValidations.ValidateEmail(user.Email))
            {
                ViewBag.Error     = "Your email is invalid. Please enter a valid one.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (UserUtilities.IsEmailTaken(user.Email, db))
            {
                ViewBag.Error     = "This email is already taken. Please register with another one.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidateUsername(user.Username))
            {
                ViewBag.Error     = "Your username is invalid. It should be between 3 and 50 characters long.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (UserUtilities.IsUserExisting(user.Username, db))
            {
                ViewBag.Error     = "This username is already taken. Please register with another one.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidatePassword(user.Password))
            {
                ViewBag.Error     = "Your password is invalid. It should be at least 8 characters long, contain at least one small and one big letter and one digit.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidateRepeatedPassword(user.Password, user.RepeatPassword))
            {
                ViewBag.Error     = "Your passwords do not match.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidateProfilePicture(profilePictureFile))
            {
                ViewBag.Error     = "You have not chosen a profile picture.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (ModelState.IsValid)
            {
                user.RegisterProfilePicture = PictureUtilities.PictureToByteArray(profilePictureFile);
                db.Users.Add(user);
                db.SaveChanges();
                AuthManager.SetCurrentUser(user.Username, user.Password);
                return(RedirectToAction("Details/" + AuthManager.GetAuthenticated().Id, "Users"));
            }
            return(View(user));
        }