public virtual JsonResult Upload(long id, ApplicationFileType type, HttpPostedFileBase file)
		{
			var bytes = file.GetBytes();

			var fileId = _files.Add(id, type, file.FileName, bytes);

			AddFileUploadEvent(id, TypesMapping[type], file.FileName, bytes);

			return Json(new { id = fileId });
		}
Exemple #2
0
		public void EditUserProfileImages(User user, bool removeAvatar, bool removePhoto, HttpPostedFileBase avatarFile, HttpPostedFileBase photoFile)
		{
			var profile = _profileRepository.GetProfile(user.UserID);
			if (removeAvatar)
			{
				_userAvatarRepository.DeleteAvatarsByUserID(user.UserID);
				profile.AvatarID = null;
			}
			if (removePhoto)
			{
				_userImageRepository.DeleteImagesByUserID(user.UserID);
				profile.ImageID = null;
			}
			_profileRepository.Update(profile);

			if (avatarFile != null && avatarFile.ContentLength > 0)
			{
				_userAvatarRepository.DeleteAvatarsByUserID(user.UserID);
				var bytes = _imageService.ConstrainResize(avatarFile.GetBytes(), _settingsManager.Current.UserAvatarMaxWidth, _settingsManager.Current.UserAvatarMaxHeight, 70);
				var avatarID = _userAvatarRepository.SaveNewAvatar(user.UserID, bytes, DateTime.UtcNow);
				profile.AvatarID = avatarID;
				_profileRepository.Update(profile);
			}

			if (photoFile != null && photoFile.ContentLength > 0)
			{
				_userImageRepository.DeleteImagesByUserID(user.UserID);
				var bytes = _imageService.ConstrainResize(photoFile.GetBytes(), _settingsManager.Current.UserImageMaxWidth, _settingsManager.Current.UserImageMaxHeight, 70);
				var imageID = _userImageRepository.SaveNewImage(user.UserID, 0, _settingsManager.Current.IsNewUserImageApproved, bytes, DateTime.UtcNow);
				profile.ImageID = imageID;
				_profileRepository.Update(profile);
			}
		}
        private byte[] GetAvatar(HttpPostedFileBase avatar)
        {
            if (avatar != null)
            {
                byte[] imageData = avatar.GetBytes();

                if (imageData.Length > RegisterUserModel.maxAvatarSize)
                {
                    return null;
                }
                return imageData;
            }
            else
                return GetDefaultAvatar();
        }
Exemple #4
0
		public void EditUser(User targetUser, UserEdit userEdit, bool removeAvatar, bool removePhoto, HttpPostedFileBase avatarFile, HttpPostedFileBase photoFile, string ip, User user)
		{
			if (!String.IsNullOrWhiteSpace(userEdit.NewEmail))
				ChangeEmail(targetUser, userEdit.NewEmail, user, ip, userEdit.IsApproved);
			if (!String.IsNullOrWhiteSpace(userEdit.NewPassword))
				SetPassword(targetUser, userEdit.NewPassword, ip, user);
			if (targetUser.IsApproved != userEdit.IsApproved)
				UpdateIsApproved(targetUser, userEdit.IsApproved, user, ip);

			var profile = _profileRepository.GetProfile(targetUser.UserID);
			profile.IsSubscribed = userEdit.IsSubscribed;
			profile.ShowDetails = userEdit.ShowDetails;
			profile.IsPlainText = userEdit.IsPlainText;
			profile.HideVanity = userEdit.HideVanity;
			profile.TimeZone = userEdit.TimeZone;
			profile.IsDaylightSaving = userEdit.IsDaylightSaving;
			profile.Signature = _textParsingService.ForumCodeToHtml(userEdit.Signature);
			profile.Location = userEdit.Location;
			profile.Dob = userEdit.Dob;
			profile.Web = userEdit.Web;
			profile.Aim = userEdit.Aim;
			profile.Icq = userEdit.Icq;
			profile.YahooMessenger = userEdit.YahooMessenger;
			profile.Facebook = userEdit.Facebook;
			profile.Twitter = userEdit.Twitter;
			if (removeAvatar)
				profile.AvatarID = null;
			if (removePhoto)
				profile.ImageID = null;
			_profileRepository.Update(profile);

			var newRoles = userEdit.Roles ?? new string[0];
			_roleRepository.ReplaceUserRoles(targetUser.UserID, newRoles);
			foreach (var role in targetUser.Roles)
				if (!newRoles.Contains(role))
					_securityLogService.CreateLogEntry(user, targetUser, ip, role, SecurityLogType.UserRemovedFromRole);
			foreach (var role in newRoles)
				if (!targetUser.Roles.Contains(role))
					_securityLogService.CreateLogEntry(user, targetUser, ip, role, SecurityLogType.UserAddedToRole);

			if (avatarFile != null && avatarFile.ContentLength > 0)
			{
				var avatarID = _userAvatarRepository.SaveNewAvatar(targetUser.UserID, avatarFile.GetBytes(), DateTime.UtcNow);
				profile.AvatarID = avatarID;
				_profileRepository.Update(profile);
			}

			if (photoFile != null && photoFile.ContentLength > 0)
			{
				var imageID = _userImageRepository.SaveNewImage(targetUser.UserID, 0, true, photoFile.GetBytes(), DateTime.UtcNow);
				profile.ImageID = imageID;
				_profileRepository.Update(profile);
			}
		}