forked from DNN-Connect/UserAccountRegistration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Templates.ascx.vb
344 lines (247 loc) · 13.5 KB
/
Templates.ascx.vb
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
Imports DotNetNuke.Entities.Modules
Imports Connect.Libraries.UserManagement
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Security.Membership
Imports Telerik.Web.UI
Imports DotNetNuke.Security.Roles
Imports DotNetNuke.Entities.Profile
Imports DotNetNuke.UI.Skins.Controls
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Common.Globals
Imports DotNetNuke.Framework.JavaScriptLibraries
Namespace Connect.Modules.UserManagement.AccountRegistration
Partial Class Templates
Inherits ConnectUsersModuleBase
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
JavaScript.RequestRegistration(CommonJs.DnnPlugins)
End Sub
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
LocalizeForm()
If Not Page.IsPostBack Then
BindThemes()
BindLocales()
If Settings.Contains("ModuleTheme") Then
Try
SelectTheme(CType(Settings("ModuleTheme"), String))
Catch
End Try
End If
BindSelectedTheme()
VerifyPasswordSettings()
End If
End Sub
Private Sub drpThemes_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpThemes.SelectedIndexChanged
BindSelectedTheme()
End Sub
Private Sub cmdUpdate_Click(sender As Object, e As System.EventArgs) Handles cmdUpdate.Click
Dim blnSucess As Boolean = False
SaveTemplates(blnSucess)
If blnSucess Then
UpdateSettings()
End If
End Sub
Private Sub cmdUpdateExit_Click(sender As Object, e As System.EventArgs) Handles cmdUpdateExit.Click
Dim blnSucess As Boolean = False
SaveTemplates(blnSucess)
If blnSucess Then
UpdateSettings()
End If
Response.Redirect(NavigateURL())
End Sub
Private Sub cmdDeleteSelected_Click(sender As Object, e As System.EventArgs) Handles cmdDeleteSelected.Click
Try
DeleteTheme()
Catch ex As Exception
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblDeleteThemeError", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
End Try
End Sub
Private Sub cmdCancel_Click(sender As Object, e As System.EventArgs) Handles cmdCancel.Click
Response.Redirect(NavigateURL())
End Sub
Private Sub drpLocales_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles drpLocales.SelectedIndexChanged
BindSelectedTheme()
End Sub
Private Sub cmdCopySelected_Click(sender As Object, e As System.EventArgs) Handles cmdCopySelected.Click
pnlTemplateName.Visible = True
End Sub
Private Sub VerifyPasswordSettings()
If MembershipProvider.Instance().PasswordRetrievalEnabled = False Then
Dim strNote As String = Localization.GetString("lblPasswordRetrievalDisabled", LocalResourceFile)
If MembershipProvider.Instance().RequiresQuestionAndAnswer Then
strNote += Localization.GetString("lblRequiresQuestionAndAnswer", LocalResourceFile)
End If
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, strNote, ModuleMessage.ModuleMessageType.BlueInfo)
End If
End Sub
Private Sub LocalizeForm()
cmdCancel.Text = Localization.GetString("cmdCancel", LocalResourceFile)
cmdUpdateExit.Text = Localization.GetString("cmdUpdateExit", LocalResourceFile)
cmdUpdate.Text = Localization.GetString("cmdUpdate", LocalResourceFile)
cmdCopySelected.Text = Localization.GetString("cmdCopySelected", LocalResourceFile)
cmdDeleteSelected.Text = Localization.GetString("cmdDeleteSelected", LocalResourceFile)
End Sub
Private Sub BindThemes()
drpThemes.Items.Clear()
Dim basepath As String = Server.MapPath(Me.TemplateSourceDirectory & "/templates/")
For Each folder As String In System.IO.Directory.GetDirectories(basepath)
Dim foldername As String = folder.Substring(folder.LastIndexOf("\") + 1)
drpThemes.Items.Add(New ListItem(foldername, folder))
Next
End Sub
Private Sub SelectTheme(ThemeName As String)
drpThemes.Items.FindByText(ThemeName).Selected = True
End Sub
Private Sub BindSelectedTheme()
cmdDeleteSelected.Visible = (drpThemes.SelectedIndex <> 0)
If Settings.Contains("ModuleTheme") Then
Try
If CType(Settings("ModuleTheme"), String) = drpThemes.SelectedItem.Text Then
chkUseTheme.Checked = True
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDeleteSelected, Localization.GetSafeJSString(Localization.GetString("lblThemeInUse", LocalResourceFile)))
Else
chkUseTheme.Checked = False
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDeleteSelected, Localization.GetSafeJSString(Localization.GetString("lblConfirmDelete", LocalResourceFile)))
End If
Catch
End Try
Else
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDeleteSelected, Localization.GetSafeJSString(Localization.GetString("lblConfirmDelete", LocalResourceFile)))
chkUseTheme.Checked = False
End If
Dim path As String = drpThemes.SelectedValue
For Each file As String In System.IO.Directory.GetFiles(path)
If file.EndsWith(Constants.TemplateName_EmailToAdmin) Then
txtEmailAdminTemplate.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailToAdmin, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailToUser_Private) Then
txtEmailUserPrivate.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailToUser_Private, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailToUser_Verified) Then
txtEmailUserVerified.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailToUser_Verified, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_EmailToUser) Then
txtEmailUser.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_EmailToUser, drpLocales.SelectedValue, True)
End If
If file.EndsWith(Constants.TemplateName_Form) Then
txtFormTemplate.Text = GetTemplate(drpThemes.SelectedItem.Value, Constants.TemplateName_Form, drpLocales.SelectedValue, True)
End If
Next
End Sub
Private Sub SaveTemplate(SelectedTheme As String, TemplateName As String, Locale As String)
Dim path As String = SelectedTheme & "\" & TemplateName.Replace(Constants.TemplateName_Extension, "." & Locale & Constants.TemplateName_Extension)
If (PortalSettings.DefaultLanguage.ToLower = Locale.ToLower) Or String.IsNullOrEmpty(Locale) Then
path = SelectedTheme & "\" & TemplateName
End If
Dim sw As New System.IO.StreamWriter(path, False)
If TemplateName = Constants.TemplateName_EmailToAdmin Then
sw.Write(txtEmailAdminTemplate.Text)
End If
If TemplateName = Constants.TemplateName_EmailToUser_Private Then
sw.Write(txtEmailUserPrivate.Text)
End If
If TemplateName = Constants.TemplateName_EmailToUser_Verified Then
sw.Write(txtEmailUserVerified.Text)
End If
If TemplateName = Constants.TemplateName_EmailToUser Then
sw.Write(txtEmailUser.Text)
End If
If TemplateName = Constants.TemplateName_Form Then
sw.Write(txtFormTemplate.Text)
End If
sw.Close()
sw.Dispose()
End Sub
Private Sub SaveTemplates(ByRef blnSucess As Boolean)
Dim basepath As String = drpThemes.SelectedValue
If pnlTemplateName.Visible Then
If String.IsNullOrEmpty(txtTemplateName.Text) Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblMustEnterTemplateName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End If
If String.IsNullOrEmpty(txtEmailAdminTemplate.Text) Or String.IsNullOrEmpty(txtEmailUser.Text) Or String.IsNullOrEmpty(txtEmailUserPrivate.Text) Or String.IsNullOrEmpty(txtEmailUserVerified.Text) Or String.IsNullOrEmpty(txtFormTemplate.Text) Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblMustEnterTemplate", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End If
Dim newpath As String = Server.MapPath(Me.TemplateSourceDirectory & "/templates/") & txtTemplateName.Text
Try
System.IO.Directory.CreateDirectory(newpath)
Catch
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblInvalidFolderName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End Try
Try
For Each file As String In System.IO.Directory.GetFiles(basepath)
Dim destinationpath As String = newpath & "\" & file.Substring(file.LastIndexOf("\") + 1)
System.IO.File.Copy(file, destinationpath)
Next
basepath = newpath
Catch ex As Exception
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblCouldNotCopyTheme", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End Try
pnlTemplateName.Visible = False
BindThemes()
SelectTheme(txtTemplateName.Text)
cmdDeleteSelected.Visible = True
End If
Try
For Each file As String In System.IO.Directory.GetFiles(basepath)
If file.EndsWith(Constants.TemplateName_EmailToAdmin) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailToAdmin, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailToUser_Private) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailToUser_Private, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailToUser_Verified) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailToUser_Verified, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_EmailToUser) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_EmailToUser, drpLocales.SelectedValue)
End If
If file.EndsWith(Constants.TemplateName_Form) Then
SaveTemplate(drpThemes.SelectedValue, Constants.TemplateName_Form, drpLocales.SelectedValue)
End If
Next
Catch ex As Exception
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("lblCouldNotWriteTheme", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError)
blnSucess = False
Exit Sub
End Try
blnSucess = True
End Sub
Private Sub UpdateSettings()
Dim ctrl As New ModuleController
ctrl.UpdateTabModuleSetting(TabModuleId, "ModuleTheme", drpThemes.SelectedItem.Text)
End Sub
Private Sub DeleteTheme()
Dim basepath As String = drpThemes.SelectedValue
For Each file As String In System.IO.Directory.GetFiles(basepath)
System.IO.File.Delete(file)
Next
System.IO.Directory.Delete(basepath)
BindThemes()
UpdateSettings()
BindSelectedTheme()
End Sub
Private Sub BindLocales()
Dim dicLocales As Dictionary(Of String, DotNetNuke.Services.Localization.Locale) = LocaleController.Instance().GetLocales(PortalId)
If dicLocales.Count > 1 Then
pnlLocales.Visible = True
End If
For Each objLocale As DotNetNuke.Services.Localization.Locale In dicLocales.Values
Dim item As New ListItem
item.Text = objLocale.Text
item.Value = objLocale.Code
Me.drpLocales.Items.Add(item)
Next
Try
drpLocales.Items(0).Selected = True
Catch
End Try
End Sub
End Class
End Namespace