forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookieOptionsWrapper.cs
More file actions
125 lines (115 loc) · 4.05 KB
/
CookieOptionsWrapper.cs
File metadata and controls
125 lines (115 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using Microsoft.AspNetCore.Http;
using OneScript.Contexts;
using OneScript.Values;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;
using System;
namespace OneScript.Web.Server
{
[ContextClass("ПараметрыCookie", "CookieOptions")]
public class CookieOptionsWrapper: AutoContext<CookieOptionsWrapper>
{
internal readonly CookieOptions _cookieOptions = new CookieOptions();
[ContextProperty("Домен", "Domain")]
public IValue Domain
{
get
{
if (_cookieOptions.Domain == null)
return BslUndefinedValue.Instance;
else
return BslStringValue.Create(_cookieOptions.Domain);
}
set
{
if (value is BslUndefinedValue)
_cookieOptions.Domain = null;
else
_cookieOptions.Domain = ContextValuesMarshaller.ConvertValueStrict<string>(value);
}
}
[ContextProperty("Путь", "Path")]
public IValue Path
{
get => _cookieOptions.Path == null ? BslUndefinedValue.Instance : BslStringValue.Create(_cookieOptions.Path);
set
{
if (value is BslUndefinedValue)
_cookieOptions.Path = null;
else
_cookieOptions.Path = ContextValuesMarshaller.ConvertValueStrict<string>(value);;
}
}
[ContextProperty("Истекает", "Expires")]
public IValue Expires
{
get
{
if (_cookieOptions.Expires.HasValue)
return BslDateValue.Create(_cookieOptions.Expires.Value.UtcDateTime);
else
return BslUndefinedValue.Instance;
}
set
{
if (value is BslUndefinedValue)
_cookieOptions.Expires = null;
else
_cookieOptions.Expires = new DateTimeOffset(value.AsDate());
}
}
[ContextProperty("Безопасный", "Secure")]
public bool Secure
{
get => _cookieOptions.Secure;
set => _cookieOptions.Secure = value;
}
[ContextProperty("РежимSameSite", "SameSiteMode")]
public SameSiteModeEnum SameSiteMode
{
get => (SameSiteModeEnum)_cookieOptions.SameSite;
set => _cookieOptions.SameSite = (Microsoft.AspNetCore.Http.SameSiteMode)value;
}
[ContextProperty("ТолькоHttp", "HttpOnly")]
public bool HttpOnly
{
get => _cookieOptions.HttpOnly;
set => _cookieOptions.HttpOnly = value;
}
[ContextProperty("МаксимальныйВозраст", "MaxAge")]
public IValue MaxAge
{
get
{
if (_cookieOptions.MaxAge.HasValue)
return BslNumericValue.Create((decimal)_cookieOptions.MaxAge.Value.TotalSeconds);
else
return BslUndefinedValue.Instance;
}
set
{
if (value is BslUndefinedValue)
_cookieOptions.MaxAge = null;
else
_cookieOptions.MaxAge = TimeSpan.FromSeconds((double)value.AsNumber());
}
}
[ContextProperty("Важный", "IsEssential")]
public bool IsEssential
{
get => _cookieOptions.IsEssential;
set => _cookieOptions.IsEssential = value;
}
[ScriptConstructor]
public static CookieOptionsWrapper Create()
{
return new CookieOptionsWrapper();
}
}
}