Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Csp security options, and remove unused usings #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Abstractions
namespace AspNetCoreHero.ToastNotification.Abstractions
{
public interface ITempDataService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Abstractions
namespace AspNetCoreHero.ToastNotification.Abstractions
{
public interface IToastNotificationService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using AspNetCoreHero.ToastNotification.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Abstractions
{
Expand All @@ -13,7 +8,7 @@ public Notification(ToastNotificationType type, string message, int? durationInS
{
Message = message;
Type = type;
Duration = (durationInSeconds == null || durationInSeconds == 0) ? null : durationInSeconds * 1000;
Duration = durationInSeconds == null || durationInSeconds == 0 ? null : durationInSeconds * 1000;
}
public string Message { get; set; }
public string BackgroundColor { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Mukesh Murugan</Authors>
<Authors>Mukesh Murugan, Artem Konkin</Authors>
<Company>aspnetcorehero</Company>
<Product>AspNetCoreHero.ToastNotification</Product>
<Description>Elegant Toast Notifications for ASP.NET Core Applications. Compatilble with ASP.NET Core 3.1 and .NET 5.</Description>
<Copyright>2020</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<AssemblyVersion>1.1.0</AssemblyVersion>
<FileVersion>1.1.0</FileVersion>
<Version>1.1.0</Version>
<PackageIcon>logo-transparent.png</PackageIcon>
<Version>1.1.1</Version>
<PackageProjectUrl>https://github.com/aspnetcorehero/ToastNotification</PackageProjectUrl>
<RepositoryUrl>https://github.com/aspnetcorehero/ToastNotification</RepositoryUrl>
</PropertyGroup>
Expand All @@ -27,13 +26,4 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
<None Include="D:\Photoshop\ANCH\logo-transparent.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>



</Project>
</Project>
4 changes: 0 additions & 4 deletions AspNetCoreHero.ToastNotification/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification
{
Expand All @@ -35,7 +32,7 @@ public static void AddToastify(this IServiceCollection services, Action<Toastify
//Add the ToastNotification implementation
services.AddScoped<IToastifyService, ToastifyService>();
services.AddSingleton(toastify);

}
private static void AddFrameworkServices(this IServiceCollection services)
{
Expand All @@ -60,7 +57,7 @@ public static void AddNotyf(this IServiceCollection services, Action<NotyfConfig
{
var configurationValue = new NotyfConfig();
configure(configurationValue);
var options = new NotyfEntity(configurationValue.DurationInSeconds, configurationValue.Position, configurationValue.IsDismissable);
var options = new NotyfEntity(configurationValue.DurationInSeconds, configurationValue.Position, configurationValue.IsDismissable, isCspSecure: configurationValue.IsCspSecure);
if (services == null)
{
throw new ArgumentNullException(nameof(services));
Expand All @@ -79,7 +76,7 @@ public static void AddNotyf(this IServiceCollection services, Action<NotyfConfig
//Middleware
services.AddScoped<NotyfMiddleware>();
services.AddSingleton(options);

}
}
}
}
5 changes: 0 additions & 5 deletions AspNetCoreHero.ToastNotification/Helpers/JsonSerialization.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Helpers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ private Task Callback(object context)
var messages = new NotyfViewModel
{
Configuration = _options.ToJson(),
isCspSecure = _options.cspSecure,
Notifications = _toastNotification.ReadAllNotifications()
};

if (messages.Notifications != null && messages.Notifications.Any())
{
var accessControlExposeHeaders = $"{GetControlExposeHeaders(httpContext.Response.Headers)}";
Expand All @@ -65,4 +67,4 @@ private object GetControlExposeHeaders(IHeaderDictionary headers)
}
}
}
}
}
6 changes: 1 addition & 5 deletions AspNetCoreHero.ToastNotification/Notyf/Models/Config.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AspNetCoreHero.ToastNotification.Notyf.Models
namespace AspNetCoreHero.ToastNotification.Notyf.Models
{
public class Config
{
Expand Down
8 changes: 2 additions & 6 deletions AspNetCoreHero.ToastNotification/Notyf/Models/Icon.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AspNetCoreHero.ToastNotification.Notyf.Models
namespace AspNetCoreHero.ToastNotification.Notyf.Models
{
public class Icon
{
public string className { get; set; }
public string tagName { get; set; }
public string text { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion AspNetCoreHero.ToastNotification/Notyf/Models/NotyfConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class NotyfConfig
public int DurationInSeconds { get; set; }
public NotyfPosition Position { get; set; } = NotyfPosition.BottomRight;
public bool IsDismissable { get; set; } = false;
public bool IsCspSecure { get; set; } = false;
public bool HasRippleEffect { get; set; } = true;
}
}
}
12 changes: 7 additions & 5 deletions AspNetCoreHero.ToastNotification/Notyf/Models/NotyfEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ namespace AspNetCoreHero.ToastNotification.Notyf.Models
{
public class NotyfEntity
{
public NotyfEntity(int durationInSeconds = 5, NotyfPosition toastPosition = NotyfPosition.BottomRight, bool isDismissible = true)
public NotyfEntity(int durationInSeconds = 5, NotyfPosition toastPosition = NotyfPosition.BottomRight, bool isDismissible = true, bool isCspSecure = false)
{
duration = (durationInSeconds > 0) ? durationInSeconds * 1000 : 5000;
duration = durationInSeconds > 0 ? durationInSeconds * 1000 : 5000;
dismissible = isDismissible;
ripple = true;
cspSecure = isCspSecure;
try
{
string description = ToDescriptionString(toastPosition);
var positionArray = description.Split('-');
position = new Position()
{
x = (positionArray is null) ? "right" : positionArray[0],
y = (positionArray is null) ? "bottom" : positionArray[1]
x = positionArray is null ? "right" : positionArray[0],
y = positionArray is null ? "bottom" : positionArray[1]
};
}
catch
Expand Down Expand Up @@ -73,6 +74,7 @@ public NotyfEntity(int durationInSeconds = 5, NotyfPosition toastPosition = Noty
public int duration { get; set; }
public Position position { get; set; }
public bool dismissible { get; set; } = true;
public bool cspSecure { get; set; } = false;
public bool ripple { get; set; } = true;
public List<Config> types { get; set; }
private static string ToDescriptionString(NotyfPosition val)
Expand All @@ -81,4 +83,4 @@ private static string ToDescriptionString(NotyfPosition val)
return attributes.Length > 0 ? attributes[0].Description : "right-bottom";
}
}
}
}
6 changes: 1 addition & 5 deletions AspNetCoreHero.ToastNotification/Notyf/Models/Position.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AspNetCoreHero.ToastNotification.Notyf.Models
namespace AspNetCoreHero.ToastNotification.Notyf.Models
{
public class Position
{
Expand Down
7 changes: 2 additions & 5 deletions AspNetCoreHero.ToastNotification/Notyf/NotyfViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using AspNetCoreHero.ToastNotification.Notyf.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Notyf
{
public class NotyfViewModel
{
public string Configuration { get; set; }
public bool isCspSecure { get; set; }
public IEnumerable<NotyfNotification> Notifications { get; set; }
}
}
}
5 changes: 0 additions & 5 deletions AspNetCoreHero.ToastNotification/Services/TempDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Services
{
Expand Down
7 changes: 1 addition & 6 deletions AspNetCoreHero.ToastNotification/Toastify/Enums/Gravity.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace AspNetCoreHero.ToastNotification
{
Expand Down
7 changes: 1 addition & 6 deletions AspNetCoreHero.ToastNotification/Toastify/Enums/Position.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace AspNetCoreHero.ToastNotification
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using AspNetCoreHero.ToastNotification.Abstractions;
using AspNetCoreHero.ToastNotification.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Toastify.Models
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AspNetCoreHero.ToastNotification.Abstractions;
using AspNetCoreHero.ToastNotification.Enums;
using AspNetCoreHero.ToastNotification.Toastify.Models;
using System;
using System.Collections.Generic;

namespace AspNetCoreHero.ToastNotification.Toastify
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using AspNetCoreHero.ToastNotification.Toastify.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCoreHero.ToastNotification.Toastify
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@model AspNetCoreHero.ToastNotification.Notyf.NotyfViewModel
@using AspNetCoreHero.ToastNotification.Enums
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="~/_content/AspNetCoreHero.ToastNotification/notyf.min.css">
<script src="~/_content/AspNetCoreHero.ToastNotification/notyf.min.js"></script>
<script>

<link rel="stylesheet" href="~/libs/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="~/notyf.min.css">

<script src="~/notyf.min.js"></script>

<script @(Model.isCspSecure ? "nonce=\"@ViewContext.HttpContext.Items[\"CspRequestHash\"]?.ToString()" : "")>
const notyf = new Notyf(@Html.Raw(Model.Configuration));
</script>

@{
@if (Model.Notifications != null)
{
Expand Down Expand Up @@ -48,11 +52,10 @@
break;
}
}

}

}
<script type="text/javascript">

<script @(Model.isCspSecure ? "nonce=\"@ViewContext.HttpContext.Items[\"CspRequestHash\"]?.ToString()" : "")>

function toastNotifySuccess(message, duration) {
if (duration) { notyf.success({ message: message, duration: duration }); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public IViewComponentResult Invoke()
var model = new NotyfViewModel
{
Configuration = _options.ToJson(),
isCspSecure = _options.cspSecure,
Notifications = _service.ReadAllNotifications()
};

return View("Default", model);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@model AspNetCoreHero.ToastNotification.Toastify.ToastifyViewModel
@using AspNetCoreHero.ToastNotification.Enums
@using AspNetCoreHero.ToastNotification.Helpers
<link rel="stylesheet" href="~/_content/AspNetCoreHero.ToastNotification/toastify.css">
<script src="~/_content/AspNetCoreHero.ToastNotification/toastify.js"></script>

<link rel="stylesheet" href="~/toastify.css">
<script src="~/toastify.js"></script>

@{
@if (Model.Notifications != null)
{
Expand Down
Loading