-
-
Notifications
You must be signed in to change notification settings - Fork 780
Expand file tree
/
Copy pathDataConsent.ascx.cs
More file actions
209 lines (185 loc) · 9.43 KB
/
Copy pathDataConsent.ascx.cs
File metadata and controls
209 lines (185 loc) · 9.43 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Modules.Admin.Users
{
using System;
using System.Web;
using DotNetNuke.Abstractions;
using DotNetNuke.Abstractions.Application;
using DotNetNuke.Abstractions.Logging;
using DotNetNuke.Common.Lists;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security;
using Microsoft.Extensions.DependencyInjection;
/// <summary>A control which handles a user's consent to the site's usage of their data.</summary>
/// <param name="navigationManager">The navigation manager.</param>
/// <param name="eventLogger">The event logger.</param>
/// <param name="listController">The list controller.</param>
/// <param name="hostSettings">The host settings.</param>
public partial class DataConsent(INavigationManager navigationManager, IEventLogger eventLogger, ListController listController, IHostSettings hostSettings)
: UserModuleBase(listController, hostSettings)
{
private readonly INavigationManager navigationManager = navigationManager ?? Common.Globals.GetCurrentServiceProvider().GetRequiredService<INavigationManager>();
private readonly IEventLogger eventLogger = eventLogger ?? Common.Globals.GetCurrentServiceProvider().GetRequiredService<IEventLogger>();
/// <summary>Initializes a new instance of the <see cref="DataConsent"/> class.</summary>
[Obsolete("Deprecated in DotNetNuke 10.0.2. Please use overload with INavigationManager. Scheduled removal in v12.0.0.")]
public DataConsent()
: this(null, null, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="DataConsent"/> class.</summary>
/// <param name="navigationManager">The navigation manager.</param>
[Obsolete("Deprecated in DotNetNuke 10.2.2. Please use overload with IEventLogger. Scheduled removal in v12.0.0.")]
public DataConsent(INavigationManager navigationManager)
: this(navigationManager, null, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="DataConsent"/> class.</summary>
/// <param name="navigationManager">The navigation manager.</param>
/// <param name="eventLogger">The event logger.</param>
[Obsolete("Deprecated in DotNetNuke 10.2.4. Please use overload with ListController. Scheduled removal in v12.0.0.")]
public DataConsent(INavigationManager navigationManager, IEventLogger eventLogger)
: this(navigationManager, eventLogger, null, null)
{
}
/// <summary>A function which handles the <see cref="DataConsent.DataConsentCompleted"/> event.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
public delegate void DataConsentEventHandler(object sender, DataConsentEventArgs e);
/// <summary>An event which is triggered when the user takes a data consent action.</summary>
public event DataConsentEventHandler DataConsentCompleted;
/// <summary>The options a user can take from the data consent screen.</summary>
public enum DataConsentStatus
{
/// <summary>Consented.</summary>
Consented = 0,
/// <summary>Cancelled.</summary>
Cancelled = 1,
/// <summary>Removed account.</summary>
RemovedAccount = 2,
/// <summary>Failed to remove account.</summary>
FailedToRemoveAccount = 3,
}
/// <summary>Gets the confirmation text to display when a user chooses for their account to be deleted.</summary>
public string DeleteMeConfirmString
{
get
{
switch (this.PortalSettings.DataConsentUserDeleteAction)
{
case PortalSettings.UserDeleteAction.Manual:
return this.LocalizeText("ManualDelete.Confirm");
case PortalSettings.UserDeleteAction.DelayedHardDelete:
return this.LocalizeText("DelayedHardDelete.Confirm");
case PortalSettings.UserDeleteAction.HardDelete:
return this.LocalizeText("HardDelete.Confirm");
}
return string.Empty;
}
}
/// <summary>Gets the HTML to display with the statement agreeing to the terms and privacy policies.</summary>
protected IHtmlString DataConsentHtml
{
get
{
var termsUrl = this.PortalSettings.TermsTabId == Null.NullInteger
? this.navigationManager.NavigateURL(this.TabId, "Terms")
: this.navigationManager.NavigateURL(this.PortalSettings.TermsTabId);
var privacyUrl = this.PortalSettings.PrivacyTabId == Null.NullInteger
? this.navigationManager.NavigateURL(this.TabId, "Privacy")
: this.navigationManager.NavigateURL(this.PortalSettings.PrivacyTabId);
var dataConsentHtml = string.Format(
this.LocalizeText("DataConsent"),
termsUrl,
privacyUrl);
return new HtmlString(dataConsentHtml);
}
}
/// <summary>Called when any data consent action is completed.</summary>
/// <param name="e">The details of the action.</param>
public void OnDataConsentComplete(DataConsentEventArgs e)
{
this.DataConsentCompleted?.Invoke(this, e);
}
/// <inheritdoc />
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.cmdCancel.Click += this.CmdCancel_Click;
this.cmdSubmit.Click += this.CmdSubmit_Click;
this.cmdDeleteMe.Click += this.CmdDeleteMe_Click;
this.cmdDeleteMe.Visible = this.PortalSettings.DataConsentUserDeleteAction != PortalSettings.UserDeleteAction.Off;
if (!this.Page.IsPostBack)
{
this.chkAgree.Checked = false;
this.cmdSubmit.Enabled = false;
this.pnlNoAgreement.Visible = false;
}
this.chkAgree.Attributes.Add(
"onclick",
$"document.getElementById({HttpUtility.JavaScriptStringEncode(this.cmdSubmit.ClientID, addDoubleQuotes: true)}).disabled = !this.checked;");
this.cmdDeleteMe.Attributes.Add(
"onclick",
$"if (!confirm({HttpUtility.JavaScriptStringEncode(this.DeleteMeConfirmString, addDoubleQuotes: true)})) event.preventDefault();");
}
private void CmdCancel_Click(object sender, EventArgs e)
{
this.OnDataConsentComplete(new DataConsentEventArgs(DataConsentStatus.Cancelled));
}
private void CmdSubmit_Click(object sender, EventArgs e)
{
if (this.chkAgree.Checked)
{
UserController.UserAgreedToTerms(this.User);
this.User.HasAgreedToTerms = true;
this.OnDataConsentComplete(new DataConsentEventArgs(DataConsentStatus.Consented));
}
}
private void CmdDeleteMe_Click(object sender, EventArgs e)
{
var success = false;
switch (this.PortalSettings.DataConsentUserDeleteAction)
{
case PortalSettings.UserDeleteAction.Manual:
this.User.Membership.Approved = false;
UserController.UpdateUser(this.eventLogger, this.PortalSettings.PortalId, this.User);
UserController.UserRequestsRemoval(this.User, true);
success = true;
break;
case PortalSettings.UserDeleteAction.DelayedHardDelete:
var user = this.User;
success = UserController.DeleteUser(this.eventLogger, ref user, true, false);
UserController.UserRequestsRemoval(this.User, true);
break;
case PortalSettings.UserDeleteAction.HardDelete:
success = UserController.RemoveUser(this.User);
break;
}
if (success)
{
PortalSecurity.Instance.SignOut();
this.OnDataConsentComplete(new DataConsentEventArgs(DataConsentStatus.RemovedAccount));
}
else
{
this.OnDataConsentComplete(new DataConsentEventArgs(DataConsentStatus.FailedToRemoveAccount));
}
}
/// <summary>The DataConsentEventArgs class provides a customised EventArgs class for the <see cref="DataConsent.DataConsentCompleted"/> Event.</summary>
public class DataConsentEventArgs
{
/// <summary>Initializes a new instance of the <see cref="DataConsentEventArgs"/> class.</summary>
/// <param name="status">The Data Consent Status.</param>
public DataConsentEventArgs(DataConsentStatus status)
{
this.Status = status;
}
/// <summary>Gets or sets the Update Status.</summary>
public DataConsentStatus Status { get; set; }
}
}
}