Example #1
0
        public string Encrypt(string plainText)
        {
            var key  = _applicationConfiguration.GetSetting("encryptionKey");
            var salt = _applicationConfiguration.GetSetting("encryptionSalt");

            return(Encrypt(plainText, key, salt));
        }
Example #2
0
        public string GetRequiredSetting(string key)
        {
            string setting = _settings.GetSetting(key);

            if (setting == null)
            {
                string message = string.Format("The application setting '{0}' does not exist in the application configuration file.", key);
                throw new ApplicationException(message);
            }

            return(setting);
        }
 public EmailNotificationService(IApplicationConfiguration applicationConfiguration)
 {
     _applicationConfiguration = applicationConfiguration;
     _server    = _applicationConfiguration.GetSetting("smtp_server");
     _altServer = _applicationConfiguration.GetSetting("alt_smtp_server");
     _port      = int.Parse(_applicationConfiguration.GetSetting("smtp_port"));
     _enabled   = bool.Parse(_applicationConfiguration.GetSetting("smtp_enabled"));
     _url       = _applicationConfiguration.GetSetting("website_url");
     _username  = _applicationConfiguration.GetSetting("smtp_username");
     _password  = _applicationConfiguration.GetSetting("smtp_password");
 }
Example #4
0
        public string UploadFile(string filename, byte[] fileData, string folder, string containerDirectory)
        {
            var destinationBlobName = $"{filename}";
            var connectionString    = _applicationConfiguration.GetSetting("storage_connection_string");
            var retryStrategy       = new FixedInterval(3, TimeSpan.FromSeconds(1));
            var retryPolicy         = new RetryPolicy <StorageTransientErrorDetectionStrategy>(retryStrategy);

            try
            {
                retryPolicy.ExecuteAction(
                    () =>
                {
                    var storageAccount     = CloudStorageAccount.Parse(connectionString);
                    var cloudBlobClient    = storageAccount.CreateCloudBlobClient();
                    var cloudBlobContainer = cloudBlobClient.GetContainerReference(containerDirectory);
                    cloudBlobContainer.CreateIfNotExists();
                    cloudBlobContainer.SetPermissions(new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Off
                    });
                    var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(destinationBlobName);
                    cloudBlockBlob.Properties.ContentType  = MimeMapping.GetMimeMapping(filename);
                    cloudBlockBlob.Properties.CacheControl = BlobCacheControl;
                    cloudBlockBlob.UploadFromByteArray(fileData, 0, fileData.Length);
                    return(filename);
                });
            }
            catch (Exception exception)
            {
                //_logger.Error(string.Format("Signature Blob storage exception {0}", e.Message), e);
                var e = exception.Message;
                throw;
            }

            return(filename);
        }
        public virtual async void CreateAuthenticationTicket(User user, bool isPersistent = false, string authenticationScheme = ApplicationConfig.DefaultAuthenticationScheme, string imitatorEmail = null)
        {
            var subject = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.Email, user.Email),
                new Claim(ClaimTypes.NameIdentifier, user.Guid.ToString()),
                new Claim(ClaimTypes.Actor, imitatorEmail ?? ""),
                new Claim(ClaimTypes.IsPersistent, isPersistent.ToString()),
            }, authenticationScheme);

            if (authenticationScheme == ApplicationConfig.ApiAuthenticationScheme)
            {
                // authentication successful so generate jwt token
                var tokenHandler    = new JwtSecurityTokenHandler();
                var key             = Encoding.UTF8.GetBytes(_applicationConfiguration.GetSetting(ApplicationConfig.AppSettingsApiSecret));
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject            = subject,
                    Expires            = DateTime.UtcNow.AddDays(7),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature),
                    Issuer             = _generalSettings.StoreDomain
                };
                var token       = tokenHandler.CreateToken(tokenDescriptor);
                var tokenString = tokenHandler.WriteToken(token);
                ApplicationEngine.CurrentHttpContext.SetApiToken(tokenString);
            }
            else
            {
                //sign in the user. this will create the authentication cookie
                await ApplicationEngine.CurrentHttpContext.SignInAsync(authenticationScheme,
                                                                       new ClaimsPrincipal(subject), new AuthenticationProperties()
                {
                    IsPersistent = isPersistent
                });
            }
        }
        public MediaController(IMediaService mediaService, ITagService tagService, IApplicationConfiguration applicationConfiguration,
                               IDownloadService downloadService,
                               INopFileProvider fileProvider,
                               IPictureService pictureService
                               )
        {
            _downloadService = downloadService;
            _fileProvider    = fileProvider;
            _pictureService  = pictureService;

            _mediaService             = mediaService;
            _tagService               = tagService;
            _applicationConfiguration = applicationConfiguration;

            _mediaSettings = new MediaSettings()
            {
                ThumbnailPictureSize     = "100x100",
                SmallProfilePictureSize  = "64x64",
                MediumProfilePictureSize = "128x128",
                SmallCoverPictureSize    = "300x50",
                MediumCoverPictureSize   = "800x300",
                PictureSaveLocation      = MediaSaveLocation.FileSystem,
                PictureSavePath          = _applicationConfiguration.GetSetting(ConstantKey.PictureSavePath),
                VideoSavePath            = _applicationConfiguration.GetSetting(ConstantKey.VideoSavePath),

                OtherMediaSaveLocation     = MediaSaveLocation.FileSystem,
                OtherMediaSavePath         = _applicationConfiguration.GetSetting(ConstantKey.OtherMediaSavePath),
                DefaultUserProfileImageUrl = "/Content/Media/d_male.jpg"
            };
            _generalSettings = new GeneralSettings()
            {
                MediaSaveLocation = _applicationConfiguration.GetSetting(ConstantKey.MediaSaveLocation),
                ImageServerDomain = _applicationConfiguration.GetSetting(ConstantKey.ImageServerUrl),
                VideoServerDomain = _applicationConfiguration.GetSetting(ConstantKey.ImageServerUrl)
            };
        }