use a class to take optional parameters.

pull/5828/head
İlkay İlknur 5 years ago
parent c8cfcb5e9f
commit 5ee239c3c9

@ -0,0 +1,11 @@
using System;
namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
public class CookieOptions
{
public DateTimeOffset? ExpireDate { get; set; }
public string Path { get; set; }
public bool Secure { get; set; }
}
}

@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.JSInterop;
using Volo.Abp.DependencyInjection;
@ -15,9 +14,9 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
JsRuntime = jsRuntime;
}
public async ValueTask SetAsync(string key, string value, DateTimeOffset? expireDate = null, string path = null)
public async ValueTask SetAsync(string key, string value, CookieOptions options)
{
await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, expireDate?.ToString("r"), path);
await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, options?.ExpireDate?.ToString("r"), options?.Path, options?.Secure);
}
public async ValueTask<string> GetAsync(string key)

@ -5,7 +5,7 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
public interface ICookieService
{
public ValueTask SetAsync(string key, string value, DateTimeOffset? expireDate = null, string path = null);
public ValueTask SetAsync(string key, string value, CookieOptions options = null);
public ValueTask<string> GetAsync(string key);
public ValueTask DeleteAsync(string key, string path = null);
}

@ -1,4 +1,14 @@
window.abp.utils.setCookieValue = function (key, value, expireDate, path) {
/**
* Sets a cookie value for given key.
* This is a simple implementation created to be used by ABP.
* Please use a complete cookie library if you need.
* @param {string} key
* @param {string} value
* @param {string} expireDate (optional). If not specified the cookie will expire at the end of session.
* @param {string} path (optional)
* @param {bool} secure (optional)
*/
window.abp.utils.setCookieValue = function (key, value, expireDate, path, secure) {
var cookieValue = encodeURIComponent(key) + '=';
if (value) {
cookieValue = cookieValue + encodeURIComponent(value);
@ -12,6 +22,10 @@
cookieValue = cookieValue + "; path=" + path;
}
if (secure) {
cookieValue = cookieValue + "; secure";
}
document.cookie = cookieValue;
};

Loading…
Cancel
Save