This repository has been archived by the owner on Feb 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
View.ascx.vb
817 lines (635 loc) · 38.5 KB
/
View.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
'***********************************************************************************
' Connect UsersLibrary
'
' Copyright (C) 2013-2014 DNN-Connect Association, Philipp Becker
' http://dnn-connect.org
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; either version 2
' of the License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'
'***********************************************************************************
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
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Common.Globals
Imports DotNetNuke.Common.Utilities
Imports System.Net
Imports System.IO
Imports DotNetNuke.Services.Log.EventLog
Namespace Connect.Modules.UserManagement.AccountRegistration
Partial Class View
Inherits ConnectUsersModuleBase
Implements IActionable
#Region "Event Handlers"
#Region "Event Handlers"
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'DotNetNuke.Framework.AJAX.RegisterScriptManager()
ProcessFormTemplate(plhRegister, GetTemplate(ModuleTheme, Constants.TemplateName_Form, CurrentLocale, False), Nothing)
Dim btnUpdate As Button = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_UpdateButton), Button)
If Not btnUpdate Is Nothing Then
AddHandler btnUpdate.Click, AddressOf btnUpdate_Click
End If
Dim btnLogin As Button = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_LoginButton), Button)
If Not btnLogin Is Nothing Then
AddHandler btnLogin.Click, AddressOf btnLogin_Click
End If
Dim btnLostPassword As Button = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_LostPasswordButton), Button)
If Not btnLostPassword Is Nothing Then
AddHandler btnLostPassword.Click, AddressOf btnLostPassword_Click
End If
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim blnHasCaptchaControl As Boolean = False
Dim blnIsValid As Boolean = True
Dim strResultCode As String = ""
Dim checkControl As Control = FindControlRecursive(plhRegister, plhRegister.ID & "_ReCaptchaPanel")
If Not checkControl Is Nothing Then
blnHasCaptchaControl = True
blnIsValid = False
End If
If blnHasCaptchaControl Then
ReCaptcha.Validate(ReCaptchaKey, blnIsValid, strResultCode)
End If
If blnIsValid Then
Register()
Else
pnlError.Visible = True
pnlSuccess.Visible = False
Select Case strResultCode.ToLower
Case "invalid-site-private-key"
'reCaptcha set up not correct, register anyway.
DotNetNuke.Services.Exceptions.LogException(New Exception(Localization.GetString(strResultCode.ToLower & ".Error", LocalResourceFile)))
Register()
Case "invalid-request-cookie"
lblError.Text = Localization.GetString(strResultCode.ToLower & ".Error", LocalResourceFile)
Case "incorrect-captcha-sol"
lblError.Text = Localization.GetString(strResultCode.ToLower & ".Error", LocalResourceFile)
Case "captcha-timeout"
lblError.Text = Localization.GetString(strResultCode.ToLower & ".Error", LocalResourceFile)
Case "recaptcha-not-reachable"
'reCaptcha server not reachable. Register anyway.
DotNetNuke.Services.Exceptions.LogException(New Exception(Localization.GetString(strResultCode.ToLower & ".Error", LocalResourceFile)))
Register()
Case Else
lblError.Text = Localization.GetString("recaptcha-common-error.Error", LocalResourceFile)
End Select
End If
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
HandleLogin()
End Sub
Protected Sub btnLostPassword_Click(ByVal sender As Object, ByVal e As System.EventArgs)
HandleLostPassword()
End Sub
Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
ManageRegionLabel(Me.plhRegister)
End Sub
#End Region
#Region "Private Methods"
Private Sub HandleLostPassword()
Response.Redirect(NavigateURL(TabId, "", "ctl=SendPassword"))
End Sub
Private Sub HandleLogin()
Dim txtUsername As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_UsernameForLogin), TextBox)
Dim txtPassword As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_PasswordForLogin), TextBox)
Dim chkRemember As CheckBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_RememberForLogin), CheckBox)
If Not txtUsername Is Nothing AndAlso Not txtPassword Is Nothing Then
Dim loginStatus As DotNetNuke.Security.Membership.UserLoginStatus
Dim objUser As UserInfo = UserController.ValidateUser(PortalId, txtUsername.Text, txtPassword.Text, "", PortalSettings.PortalName, Request.UserHostAddress, loginStatus)
Select Case loginStatus
Case UserLoginStatus.LOGIN_FAILURE
lblError.Text = Localization.GetString("LOGIN_FAILURE", LocalResourceFile)
pnlError.Visible = True
Case UserLoginStatus.LOGIN_INSECUREADMINPASSWORD, UserLoginStatus.LOGIN_INSECUREHOSTPASSWORD, UserLoginStatus.LOGIN_SUPERUSER, UserLoginStatus.LOGIN_SUCCESS
Dim blnPersistent As Boolean = False
If Not chkRemember Is Nothing Then
blnPersistent = chkRemember.Checked
End If
UserController.UserLogin(PortalId, objUser, PortalSettings.PortalName, Request.UserHostAddress, blnPersistent)
If Not Request.QueryString("ReturnURL") Is Nothing Then
Response.Redirect(Server.UrlDecode(Request.QueryString("ReturnURL")), True)
End If
If RedirectAfterLogin <> Null.NullInteger Then
Response.Redirect(NavigateURL(RedirectAfterLogin))
Else
Response.Redirect(NavigateURL(PortalSettings.HomeTabId))
End If
Case UserLoginStatus.LOGIN_USERLOCKEDOUT
lblError.Text = Localization.GetString("LOGIN_USERLOCKEDOUT", LocalResourceFile)
pnlError.Visible = True
Case UserLoginStatus.LOGIN_USERNOTAPPROVED
lblError.Text = Localization.GetString("LOGIN_USERNOTAPPROVED", LocalResourceFile)
pnlError.Visible = True
End Select
End If
End Sub
Private Sub Register()
pnlSuccess.Visible = False
pnlError.Visible = False
Dim strMessages As New List(Of String)
Dim blnUpdateUsername As Boolean = False
Dim blnUpdateFirstname As Boolean = False
Dim blnUpdateLastname As Boolean = False
Dim blnUpdateDisplayname As Boolean = False
Dim blnUpdatePassword As Boolean = False
Dim blnUpdateEmail As Boolean = False
Dim txtUsername As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Username), TextBox)
blnUpdateUsername = (Not txtUsername Is Nothing)
If blnUpdateUsername Then
If Not IsValidUserAttribute(Constants.User_Username, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingUsername", LocalResourceFile))
AddErrorIndicator(Constants.User_Username, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Username, plhRegister, True)
End If
End If
Dim txtEmail As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Email), TextBox)
blnUpdateEmail = (Not txtEmail Is Nothing)
If blnUpdateEmail Then
If Not IsValidUserAttribute(Constants.User_Email, plhRegister) Then
strMessages.Add(Localization.GetString("Error_InvalidEmail", LocalResourceFile))
AddErrorIndicator(Constants.User_Email, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Email, plhRegister, True)
End If
End If
Dim txtPassword As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Password1), TextBox)
Dim txtPassword2 As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Password2), TextBox)
blnUpdatePassword = (Not txtPassword Is Nothing AndAlso Not txtPassword2 Is Nothing)
If blnUpdatePassword Then
If Not IsValidUserAttribute(Constants.User_Password1, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingPassword1", LocalResourceFile))
AddErrorIndicator(Constants.User_Password1, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Password1, plhRegister, True)
End If
If Not IsValidUserAttribute(Constants.User_Password2, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingPassword2", LocalResourceFile))
AddErrorIndicator(Constants.User_Password2, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Password2, plhRegister, True)
End If
End If
Dim txtPasswordQuestion As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_PasswordQuestion), TextBox)
Dim blnUpdatePasswordQuestion As Boolean = (Not txtPasswordQuestion Is Nothing)
If blnUpdatePasswordQuestion Then
If Not IsValidUserAttribute(Constants.User_PasswordQuestion, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingPasswordQuestion", LocalResourceFile))
AddErrorIndicator(Constants.User_PasswordQuestion, plhRegister)
Else
RemoveErrorIndicator(Constants.User_PasswordQuestion, plhRegister, True)
End If
End If
Dim txtPasswordAnswer As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_PasswordAnswer), TextBox)
Dim blnUpdatePasswordAnswer As Boolean = (Not txtPasswordAnswer Is Nothing)
If blnUpdatePasswordAnswer Then
If Not IsValidUserAttribute(Constants.User_PasswordAnswer, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingPasswordAnswer", LocalResourceFile))
AddErrorIndicator(Constants.User_PasswordAnswer, plhRegister)
Else
RemoveErrorIndicator(Constants.User_PasswordAnswer, plhRegister, True)
End If
End If
Dim txtFirstName As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Firstname), TextBox)
blnUpdateFirstname = (Not txtFirstName Is Nothing)
If blnUpdateFirstname Then
If Not IsValidUserAttribute(Constants.User_Firstname, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingFirstname", LocalResourceFile))
AddErrorIndicator(Constants.User_Firstname, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Firstname, plhRegister, True)
End If
End If
Dim txtLastName As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Lastname), TextBox)
blnUpdateLastname = (Not txtLastName Is Nothing)
If blnUpdateLastname Then
If Not IsValidUserAttribute(Constants.User_Lastname, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingFirstname", LocalResourceFile))
AddErrorIndicator(Constants.User_Lastname, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Lastname, plhRegister, True)
End If
End If
If CompareFirstNameLastName AndAlso (blnUpdateFirstname And blnUpdateLastname) Then
If txtLastName.Text.ToLower.Trim = txtFirstName.Text.ToLower.Trim Then
strMessages.Add(Localization.GetString("Error_LastnameLikeFirstname", LocalResourceFile))
AddErrorIndicator(Constants.User_Firstname, plhRegister)
End If
End If
Dim txtDisplayName As TextBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_Displayname), TextBox)
blnUpdateDisplayname = (Not txtDisplayName Is Nothing)
If blnUpdateDisplayname Then
If Not IsValidUserAttribute(Constants.User_Displayname, plhRegister) Then
strMessages.Add(Localization.GetString("Error_MissingDisplayName", LocalResourceFile))
AddErrorIndicator(Constants.User_Displayname, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Displayname, plhRegister, True)
End If
End If
Dim blnProfileErrorAdded As Boolean = False
For Each itemProp As String In GetPropertiesFromTempate(GetTemplate(ModuleTheme, Constants.TemplateName_Form, CurrentLocale, False))
Try
Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalId, itemProp.Substring(2)) 'itemprop comes in the form U:Propertyname or P:Propertyname
If Not prop Is Nothing Then
If Not IsValidProperty(Nothing, prop, plhRegister) Then
If blnProfileErrorAdded = False Then
strMessages.Add(Localization.GetString("Error_MissingProfileField", LocalResourceFile))
blnProfileErrorAdded = True
End If
AddErrorIndicator(prop.PropertyDefinitionId.ToString, plhRegister)
Else
RemoveErrorIndicator(prop.PropertyDefinitionId.ToString, plhRegister, prop.Required)
End If
End If
Catch
End Try
Next
'Create the actual user object
Dim oUser As UserInfo = New UserInfo
'approve membership if applicable
If PortalSettings.UserRegistration = PortalRegistrationType.PublicRegistration Then
oUser.Membership.Approved = True
Else
oUser.Membership.Approved = False
End If
'set defaults
oUser.AffiliateID = Null.NullInteger
oUser.PortalID = PortalSettings.PortalId
oUser.IsDeleted = False
oUser.IsSuperUser = False
oUser.LastIPAddress = Request.UserHostAddress
oUser.Profile = New UserProfile
oUser.Username = ""
oUser.DisplayName = ""
oUser.Email = ""
oUser.Membership.Password = ""
'set username depending on module setting
Select Case UsernameMode
Case UsernameUpdateMode.Email
If blnUpdateEmail Then
oUser.Username = txtEmail.Text.Trim
End If
Case UsernameUpdateMode.FirstLetterLastname
If blnUpdateLastname AndAlso blnUpdateFirstname Then
oUser.Username = txtFirstName.Text.Trim.Substring(0, 1) & "." & txtLastName.Text
End If
Case UsernameUpdateMode.FirstnameLastname
If blnUpdateLastname AndAlso blnUpdateFirstname Then
oUser.Username = txtFirstName.Text & "." & txtLastName.Text
End If
Case UsernameUpdateMode.Lastname
If blnUpdateLastname Then
oUser.Username = txtLastName.Text
End If
Case UsernameUpdateMode.UserSelect
If blnUpdateUsername Then
oUser.Username = txtUsername.Text
End If
End Select
'set displayname depending on module setting
Select Case DisplaynameMode
Case DisplaynameUpdateMode.Email
If blnUpdateEmail Then
oUser.DisplayName = txtEmail.Text.Trim
End If
Case DisplaynameUpdateMode.FirstLetterLastname
If blnUpdateLastname AndAlso blnUpdateFirstname Then
oUser.DisplayName = txtFirstName.Text.Trim.Substring(0, 1) & ". " & txtLastName.Text
End If
Case DisplaynameUpdateMode.FirstnameLastname
If blnUpdateLastname AndAlso blnUpdateFirstname Then
oUser.DisplayName = txtFirstName.Text & " " & txtLastName.Text
Else
End If
Case DisplaynameUpdateMode.Lastname
If blnUpdateLastname Then
oUser.DisplayName = txtLastName.Text
End If
Case DisplaynameUpdateMode.UserSelect
If blnUpdateDisplayname Then
oUser.DisplayName = txtDisplayName.Text
End If
End Select
If blnUpdateEmail Then
oUser.Email = txtEmail.Text
End If
'try updating password
If blnUpdatePassword Then 'only true once both password fields are found in the template
If txtPassword.Text = txtPassword2.Text Then
If UserController.ValidatePassword(txtPassword.Text) Then 'let DNN validate password policy
oUser.Membership.Password = txtPassword.Text
Else 'check failed, provide feedback about actual password policy
Dim MinLength As Integer = 0
Dim MinNonAlphaNumeric As Integer = 0
Try
MinLength = DotNetNuke.Security.Membership.MembershipProvider.Instance().MinPasswordLength
Catch
End Try
Try
MinNonAlphaNumeric = DotNetNuke.Security.Membership.MembershipProvider.Instance().MinNonAlphanumericCharacters
Catch
End Try
Dim strPolicy As String = String.Format(Localization.GetString("PasswordPolicy_MinLength", LocalResourceFile), MinLength.ToString)
If MinNonAlphaNumeric > 0 Then
strPolicy += String.Format(Localization.GetString("PasswordPolicy_MinNonAlphaNumeric", LocalResourceFile), MinNonAlphaNumeric.ToString)
End If
strMessages.Add(String.Format(Localization.GetString("InvalidPassword", LocalResourceFile), strPolicy))
End If
Else
strMessages.Add(Localization.GetString("PasswordsDontMatch.Text", LocalResourceFile))
End If
Else 'no password fields in template, auto-generate password
oUser.Membership.Password = UserController.GeneratePassword(DotNetNuke.Security.Membership.MembershipProvider.Instance().MinPasswordLength)
End If
If blnUpdatePasswordQuestion AndAlso blnUpdatePasswordAnswer Then
oUser.Membership.PasswordQuestion = txtPasswordQuestion.Text
oUser.Membership.PasswordAnswer = txtPasswordAnswer.Text
End If
If oUser.Username = "" Or oUser.Email = "" Or oUser.DisplayName = "" Or oUser.Membership.Password = "" Then
'template must be setup up wrong, some fields missing most likely
strMessages.Add(String.Format(Localization.GetString("TemplateingError.Text", LocalResourceFile), PortalSettings.Email))
End If
'set up profile object
oUser.Profile = New UserProfile
oUser.Profile.InitialiseProfile(PortalSettings.PortalId, True)
oUser.Profile.PreferredLocale = PortalSettings.DefaultLanguage
oUser.Profile.PreferredTimeZone = PortalSettings.TimeZone
'retrieve properties from template
Dim propertiesCollection As New ProfilePropertyDefinitionCollection
UpdateProfileProperties(plhRegister, oUser, propertiesCollection, GetPropertiesFromTempate(GetTemplate(ModuleTheme, Constants.TemplateName_Form, CurrentLocale, False)))
'-------------------------------------------------------------------------------------
' Call the Validation interface as a last resort to stop registration
'-------------------------------------------------------------------------------------
Dim externalValidationPass As Boolean = True
If ExternalInterface <> Null.NullString Then
Dim objInterface As Object = Nothing
If ExternalInterface.Contains(",") Then
Dim strAssembly As String = ExternalInterface.Split(Char.Parse(","))(0).Trim
Dim strClass As String = ExternalInterface.Split(Char.Parse(","))(1).Trim
objInterface = System.Activator.CreateInstance(strAssembly, strClass).Unwrap
End If
If Not objInterface Is Nothing Then
externalValidationPass = CType(objInterface, Interfaces.iAccountRegistration).ValidateRegistration(Server, Response, Request, oUser, propertiesCollection, strMessages)
End If
End If
If strMessages.Count > 0 OrElse Not externalValidationPass Then
Me.pnlError.Visible = True
Me.lblError.Text = "<ul>"
If strMessages.Count = 0 Then
lblError.Text += "<li>" & Localization.GetString("Error_Unknown", LocalResourceFile) & "</li>"
Else
For Each strMessage As String In strMessages
lblError.Text += "<li>" & strMessage & "</li>"
Next
End If
lblError.Text += "</ul>"
Exit Sub
End If
'everything fine so far, let's create the account
Dim createStatus As UserCreateStatus = UserController.CreateUser(oUser)
Dim strStatus As String = ""
If createStatus <> UserCreateStatus.Success Then
Select Case createStatus
Case UserCreateStatus.UsernameAlreadyExists
Select Case UsernameMode
Case UsernameUpdateMode.UserSelect
strStatus = Localization.GetString("UsernameAlreadyExists", Me.LocalResourceFile)
Case UsernameUpdateMode.Email
strStatus = Localization.GetString("DuplicateEmail", Me.LocalResourceFile)
Case UsernameUpdateMode.FirstnameLastname, UsernameUpdateMode.FirstLetterLastname, UsernameUpdateMode.Lastname
strStatus = Localization.GetString("NameAlreadyExists", Me.LocalResourceFile)
End Select
Case Else
strStatus = String.Format(Localization.GetString("CreateError", Me.LocalResourceFile), createStatus.ToString)
End Select
If strStatus <> "" Then
strStatus = "<li>" & strStatus & "</li>"
Else
strStatus = "<li>" & createStatus.ToString & "</li>"
End If
Me.pnlError.Visible = True
Me.lblError.Text = "<ul>" & strStatus & "</ul>"
Exit Sub
End If
oUser = ProfileController.UpdateUserProfile(oUser, propertiesCollection)
If blnUpdateFirstname = True Then
oUser.Profile.FirstName = txtFirstName.Text
oUser.FirstName = txtFirstName.Text
Else
If oUser.Profile.FirstName <> "" Then
oUser.FirstName = oUser.Profile.FirstName
End If
End If
If blnUpdateLastname = True Then
oUser.Profile.LastName = txtLastName.Text
oUser.LastName = txtLastName.Text
Else
If oUser.Profile.LastName <> "" Then
oUser.LastName = oUser.Profile.LastName
End If
End If
Try
oUser.Profile.SetProfileProperty("Email", oUser.Email)
Catch
End Try
'update profile
ProfileController.UpdateUserProfile(oUser)
UserController.UpdateUser(PortalId, oUser)
Dim strUserBody As String = ""
Dim strAdminBody As String = ""
If NotifyUser Then
If PortalSettings.UserRegistration = PortalRegistrationType.PrivateRegistration Then
strUserBody = GetTemplate(ModuleTheme, Constants.TemplateName_EmailToUser_Private, CurrentLocale, False)
ElseIf PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
strUserBody = GetTemplate(ModuleTheme, Constants.TemplateName_EmailToUser_Verified, CurrentLocale, False)
Else
strUserBody = GetTemplate(ModuleTheme, Constants.TemplateName_EmailToUser, CurrentLocale, False)
End If
End If
If NotifyRole <> "" Then
strAdminBody = GetTemplate(ModuleTheme, Constants.TemplateName_EmailToAdmin, CurrentLocale, False)
End If
If strAdminBody <> "" Then
ProcessAdminNotification(strAdminBody, oUser)
End If
If strUserBody <> "" Then
ProcessUserNotification(strUserBody, oUser)
End If
'add to role
If AddToRoleOnSubmit <> Null.NullInteger Then
Try
Dim rc As New RoleController
If AddToRoleStatus.ToLower = "pending" Then
rc.AddUserRole(PortalId, oUser.UserID, AddToRoleOnSubmit, RoleStatus.Pending, False, Date.Now, Null.NullDate)
Else
rc.AddUserRole(PortalId, oUser.UserID, AddToRoleOnSubmit, RoleStatus.Approved, False, Date.Now, Null.NullDate)
End If
Catch
End Try
End If
Dim blnAddMembership As Boolean = False
Dim chkTest As CheckBox = CType(FindMembershipControlsRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_RoleMembership), CheckBox)
If Not chkTest Is Nothing Then
'at least on role membership checkbox found. Now lookup roles that could match
Dim rc As New RoleController
Dim roles As ArrayList
roles = rc.GetPortalRoles(PortalId)
For Each objRole As RoleInfo In roles
Dim blnPending As Boolean = False
Dim chkRole As CheckBox = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_RoleMembership & objRole.RoleName.Replace(" ", "")), CheckBox)
If chkRole Is Nothing Then
chkRole = CType(FindControlRecursive(plhRegister, plhRegister.ID & "_" & Constants.ControlId_RoleMembership & objRole.RoleName.Replace(" ", "") & "_Pending"), CheckBox)
blnPending = True
End If
If Not chkRole Is Nothing Then
If blnPending Then
rc.AddUserRole(PortalId, oUser.UserID, objRole.RoleID, RoleStatus.Pending, False, Date.Now, Null.NullDate)
Else
rc.AddUserRole(PortalId, oUser.UserID, objRole.RoleID, RoleStatus.Approved, False, Date.Now, Null.NullDate)
End If
End If
Next
End If
If PortalSettings.UserRegistration = PortalRegistrationType.PublicRegistration Then
'logon user
Dim logonStatus As DotNetNuke.Security.Membership.UserLoginStatus = UserLoginStatus.LOGIN_FAILURE
UserController.UserLogin(PortalId, oUser.Username, oUser.Membership.Password, "", PortalSettings.PortalName, Request.UserHostAddress, logonStatus, True)
'see if all worked
If logonStatus <> UserLoginStatus.LOGIN_SUCCESS Then
strStatus += logonStatus.ToString
Me.pnlError.Visible = True
Me.lblError.Text = strStatus
Exit Sub
End If
End If
Dim strResult As String = ""
Select Case PortalSettings.UserRegistration
Case PortalRegistrationType.PublicRegistration
strResult = String.Format(Localization.GetString("RegisterSuccess_Public", LocalResourceFile), NavigateURL(PortalSettings.HomeTabId))
Case PortalRegistrationType.PrivateRegistration
strResult = String.Format(Localization.GetString("RegisterSuccess_Private", LocalResourceFile), NavigateURL(PortalSettings.HomeTabId))
Case PortalRegistrationType.VerifiedRegistration
strResult = String.Format(Localization.GetString("RegisterSuccess_Verified", LocalResourceFile), NavigateURL(PortalSettings.HomeTabId))
End Select
lblSucess.Text = "<ul><li>" & strResult & "</li></ul>"
pnlSuccess.Visible = True
'run the final interface if applicable
If ExternalInterface <> Null.NullString Then
Dim objInterface As Object = Nothing
If ExternalInterface.Contains(",") Then
Dim strClass As String = ExternalInterface.Split(Char.Parse(","))(0).Trim
Dim strAssembly As String = ExternalInterface.Split(Char.Parse(","))(1).Trim
objInterface = System.Activator.CreateInstance(strAssembly, strClass).Unwrap
End If
If Not objInterface Is Nothing Then
CType(objInterface, Interfaces.iAccountRegistration).FinalizeAccountRegistration(Server, Response, Request, oUser)
End If
End If
'the following might not be processed if the interfaces manipulate the current response!
If Not Request.QueryString("ReturnURL") Is Nothing Then
Response.Redirect(Server.UrlDecode(Request.QueryString("ReturnURL")), True)
End If
If RedirectAfterSubmit <> Null.NullInteger Then
Response.Redirect(NavigateURL(RedirectAfterSubmit))
End If
End Sub
Private Sub ProcessAdminNotification(ByVal Body As String, CurrentUser As UserInfo)
Body = Body.Replace("[PORTALURL]", PortalSettings.PortalAlias.HTTPAlias)
Body = Body.Replace("[PORTALNAME]", PortalSettings.PortalName)
Body = Body.Replace("[USERID]", CurrentUser.UserID)
Body = Body.Replace("[DISPLAYNAME]", CurrentUser.DisplayName)
If MembershipProvider.Instance().PasswordRetrievalEnabled Then
Body = Body.Replace("[PASSWORD]", MembershipProvider.Instance().GetPassword(User, ""))
End If
Body = Body.Replace("[USERNAME]", CurrentUser.Username)
Body = Body.Replace("[FIRSTNAME]", CurrentUser.FirstName)
Body = Body.Replace("[LASTNAME]", CurrentUser.LastName)
Body = Body.Replace("[EMAIL]", CurrentUser.Email)
If PortalSettings.UserRegistration = PortalRegistrationType.PrivateRegistration Then
Body = Body.Replace("[ADMINACTION]", Localization.GetString("AuthorizeAccount.Action", LocalResourceFile))
Body = Body.Replace("[REGISTRATIONMODE]", Localization.GetString("RegistrationMode_Private.Text", LocalResourceFile))
ElseIf PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
Body = Body.Replace("[ADMINACTION]", Localization.GetString("VerifyAccount.Action", LocalResourceFile))
Body = Body.Replace("[REGISTRATIONMODE]", Localization.GetString("RegistrationMode_Verified.Text", LocalResourceFile))
Else
Body = Body.Replace("[ADMINACTION]", Localization.GetString("NoAction.Action", LocalResourceFile))
Body = Body.Replace("[REGISTRATIONMODE]", Localization.GetString("RegistrationMode_Public.Text", LocalResourceFile))
End If
Body = Body.Replace("[USERURL]", NavigateURL(UsermanagementTab, "", "uid=" & CurrentUser.UserID.ToString, "RoleId=" & PortalSettings.RegisteredRoleId.ToString))
Dim ctrlRoles As New RoleController
Dim NotificationUsers As ArrayList = ctrlRoles.GetUsersByRoleName(PortalId, NotifyRole)
For Each NotificationUser As UserInfo In NotificationUsers
Try
Body = Body.Replace("[RECIPIENTUSERID]", NotificationUser.UserID.ToString)
Body = Body.Replace("[USERID]", NotificationUser.UserID.ToString)
DotNetNuke.Services.Mail.Mail.SendMail(PortalSettings.Email, NotificationUser.Email, "", String.Format(Localization.GetString("NotifySubject_UserRegistered.Text", LocalResourceFile), PortalSettings.PortalName), Body, "", "HTML", "", "", "", "")
Catch
End Try
Next
End Sub
Private Sub ProcessUserNotification(ByVal Body As String, CurrentUser As UserInfo)
Body = Body.Replace("[PORTALURL]", PortalSettings.PortalAlias.HTTPAlias)
Body = Body.Replace("[PORTALNAME]", PortalSettings.PortalName)
Body = Body.Replace("[USERID]", CurrentUser.UserID)
Body = Body.Replace("[DISPLAYNAME]", CurrentUser.DisplayName)
If MembershipProvider.Instance().PasswordRetrievalEnabled Then
Body = Body.Replace("[PASSWORD]", MembershipProvider.Instance().GetPassword(User, ""))
End If
Body = Body.Replace("[USERNAME]", CurrentUser.Username)
Body = Body.Replace("[FIRSTNAME]", CurrentUser.FirstName)
Body = Body.Replace("[LASTNAME]", CurrentUser.LastName)
Body = Body.Replace("[EMAIL]", CurrentUser.Email)
'verification code is now expected to be encrypted. Bummer.
'Body = Body.Replace("[VERIFICATIONCODE]", PortalSettings.PortalId.ToString & "-" & CurrentUser.UserID.ToString)
Body = Body.Replace("[VERIFICATIONCODE]", Utilities.GetVerificationCode(CurrentUser))
Body = Body.Replace("[RECIPIENTUSERID]", CurrentUser.UserID.ToString)
Body = Body.Replace("[USERID]", CurrentUser.UserID.ToString)
If PortalSettings.UserTabId <> Null.NullInteger Then
Body = Body.Replace("[USERURL]", NavigateURL(PortalSettings.UserTabId))
Else
Body = Body.Replace("[USERURL]", NavigateURL(PortalSettings.HomeTabId, "ctl=Profile"))
End If
Dim returnurl As String = ""
Dim loginurl As String = ""
Dim verificationkey As String = PortalSettings.PortalId.ToString & "-" & CurrentUser.UserID.ToString
If PortalSettings.LoginTabId <> Null.NullInteger Then
loginurl = NavigateURL(PortalSettings.LoginTabId, "", "VerificationCode=" & verificationkey)
Else
loginurl = NavigateURL(PortalSettings.HomeTabId, "", "ctl=Login", "VerificationCode=" & verificationkey)
End If
Body = Body.Replace("[VERIFYURL]", loginurl)
Try
DotNetNuke.Services.Mail.Mail.SendMail(PortalSettings.Email, CurrentUser.Email, "", String.Format(Localization.GetString("NotifySubject_UserDetails.Text", LocalResourceFile), PortalSettings.PortalName), Body, "", "HTML", "", "", "", "")
Catch
End Try
End Sub
#End Region
#End Region
#Region "Optional Interfaces"
Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
Get
Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
Actions.Add(GetNextActionID, Localization.GetString("ManageTemplates.Action", LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl("ManageTemplates"), False, DotNetNuke.Security.SecurityAccessLevel.Edit, True, False)
Return Actions
End Get
End Property
#End Region
End Class
End Namespace