Skip to content

Commit

Permalink
Add support for "pre" registration validation
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
vmasanas committed Jul 3, 2014
1 parent 53b4dde commit d8fb658
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
3 changes: 3 additions & 0 deletions App_LocalResources/View.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@
<data name="lblEmailRegex.Text" xml:space="preserve">
<value />
</data>
<data name="Error_Unknown.Text" xml:space="preserve">
<value>The data you provided is not valid. Please review and try again</value>
</data>
</root>
96 changes: 57 additions & 39 deletions View.ascx.vb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If blnUpdateUsername Then
If Not IsValidUserAttribute(Constants.User_Username, plhRegister) Then
strMessages.Add("Error_MissingUsername")
strMessages.Add(Localization.GetString("Error_MissingUsername", LocalResourceFile))
AddErrorIndicator(Constants.User_Username, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Username, plhRegister, True)
Expand All @@ -191,7 +191,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If blnUpdateEmail Then
If Not IsValidUserAttribute(Constants.User_Email, plhRegister) Then
strMessages.Add("Error_InvalidEmail")
strMessages.Add(Localization.GetString("Error_InvalidEmail", LocalResourceFile))
AddErrorIndicator(Constants.User_Email, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Email, plhRegister, True)
Expand All @@ -204,13 +204,13 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If blnUpdatePassword Then
If Not IsValidUserAttribute(Constants.User_Password1, plhRegister) Then
strMessages.Add("Error_MissingPassword1")
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("Error_MissingPassword2")
strMessages.Add(Localization.GetString("Error_MissingPassword2", LocalResourceFile))
AddErrorIndicator(Constants.User_Password2, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Password2, plhRegister, True)
Expand All @@ -221,7 +221,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration
Dim blnUpdatePasswordQuestion As Boolean = (Not txtPasswordQuestion Is Nothing)
If blnUpdatePasswordQuestion Then
If Not IsValidUserAttribute(Constants.User_PasswordQuestion, plhRegister) Then
strMessages.Add("Error_MissingPasswordQuestion")
strMessages.Add(Localization.GetString("Error_MissingPasswordQuestion", LocalResourceFile))
AddErrorIndicator(Constants.User_PasswordQuestion, plhRegister)
Else
RemoveErrorIndicator(Constants.User_PasswordQuestion, plhRegister, True)
Expand All @@ -232,7 +232,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration
Dim blnUpdatePasswordAnswer As Boolean = (Not txtPasswordAnswer Is Nothing)
If blnUpdatePasswordAnswer Then
If Not IsValidUserAttribute(Constants.User_PasswordAnswer, plhRegister) Then
strMessages.Add("Error_MissingPasswordAnswer")
strMessages.Add(Localization.GetString("Error_MissingPasswordAnswer", LocalResourceFile))
AddErrorIndicator(Constants.User_PasswordAnswer, plhRegister)
Else
RemoveErrorIndicator(Constants.User_PasswordAnswer, plhRegister, True)
Expand All @@ -245,7 +245,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If blnUpdateFirstname Then
If Not IsValidUserAttribute(Constants.User_Firstname, plhRegister) Then
strMessages.Add("Error_MissingFirstname")
strMessages.Add(Localization.GetString("Error_MissingFirstname", LocalResourceFile))
AddErrorIndicator(Constants.User_Firstname, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Firstname, plhRegister, True)
Expand All @@ -257,7 +257,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If blnUpdateLastname Then
If Not IsValidUserAttribute(Constants.User_Lastname, plhRegister) Then
strMessages.Add("Error_MissingLastname")
strMessages.Add(Localization.GetString("Error_MissingLastname", LocalResourceFile))
AddErrorIndicator(Constants.User_Lastname, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Lastname, plhRegister, True)
Expand All @@ -266,7 +266,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If CompareFirstNameLastName AndAlso (blnUpdateFirstname And blnUpdateLastname) Then
If txtLastName.Text.ToLower.Trim = txtFirstName.Text.ToLower.Trim Then
strMessages.Add("Error_LastnameLikeFirstname")
strMessages.Add(Localization.GetString("Error_LastnameLikeFirstname", LocalResourceFile))
AddErrorIndicator(Constants.User_Firstname, plhRegister)
End If
End If
Expand All @@ -276,7 +276,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If blnUpdateDisplayname Then
If Not IsValidUserAttribute(Constants.User_Displayname, plhRegister) Then
strMessages.Add("Error_MissingDisplayName")
strMessages.Add(Localization.GetString("Error_MissingDisplayName", LocalResourceFile))
AddErrorIndicator(Constants.User_Displayname, plhRegister)
Else
RemoveErrorIndicator(Constants.User_Displayname, plhRegister, True)
Expand All @@ -290,7 +290,7 @@ Namespace Connect.Modules.UserManagement.AccountRegistration
If Not prop Is Nothing Then
If Not IsValidProperty(Nothing, prop, plhRegister) Then
If blnProfileErrorAdded = False Then
strMessages.Add("Error_MissingProfileField")
strMessages.Add(Localization.GetString("Error_MissingProfileField", LocalResourceFile))
blnProfileErrorAdded = True
End If
AddErrorIndicator(prop.PropertyDefinitionId.ToString, plhRegister)
Expand All @@ -302,17 +302,6 @@ Namespace Connect.Modules.UserManagement.AccountRegistration
End Try
Next

If strMessages.Count > 0 Then
Me.pnlError.Visible = True
Me.lblError.Text = "<ul>"
For Each strMessage As String In strMessages
lblError.Text += "<li>" & Localization.GetString(strMessage, LocalResourceFile) & "</li>"
Next
lblError.Text += "</ul>"
Exit Sub
End If


Dim oUser As UserInfo = New UserInfo

'approve membership if applicable
Expand Down Expand Up @@ -414,14 +403,10 @@ Namespace Connect.Modules.UserManagement.AccountRegistration
strPolicy += String.Format(Localization.GetString("PasswordPolicy_MinNonAlphaNumeric", LocalResourceFile), MinNonAlphaNumeric.ToString)
End If

Me.pnlError.Visible = True
Me.lblError.Text = "<ul><li>" & String.Format(Localization.GetString("InvalidPassword", LocalResourceFile), strPolicy) & "</li></ul>"
Exit Sub
strMessages.Add(String.Format(Localization.GetString("InvalidPassword", LocalResourceFile), strPolicy))
End If
Else
Me.pnlError.Visible = True
Me.lblError.Text = "<ul><li>" & Localization.GetString("PasswordsDontMatch.Text", LocalResourceFile) & "</li></ul>"
Exit Sub
strMessages.Add(Localization.GetString("PasswordsDontMatch.Text", LocalResourceFile))
End If
Else
'auto-generate password
Expand All @@ -435,35 +420,70 @@ Namespace Connect.Modules.UserManagement.AccountRegistration

If oUser.Username = "" Or oUser.Email = "" Or oUser.DisplayName = "" Or oUser.Membership.Password = "" Then
'template must be setup up wrong
Me.pnlError.Visible = True
Me.lblError.Text = "<ul><li>" & String.Format(Localization.GetString("TemplateingError.Text", LocalResourceFile), PortalSettings.Email)
strMessages.Add(String.Format(Localization.GetString("TemplateingError.Text", LocalResourceFile), PortalSettings.Email))

If oUser.Username = "" Then
lblError.Text += " | Username is empty"
strMessages.Add(LocalizeString("Error_MissingUsername"))
End If

If oUser.Email = "" Then
lblError.Text += " | E-mail is empty"
strMessages.Add(LocalizeString("Error_InvalidEmail"))
End If

If oUser.DisplayName = "" Then
lblError.Text += " | Displayname is empty"
strMessages.Add(LocalizeString("Error_MissingDisplayName"))
End If

If oUser.Username = "" Then
lblError.Text += " | password is empty"
strMessages.Add(LocalizeString("Error_MissingPassword1"))
End If

lblError.Text += "</li></ul>"

Exit Sub
End If

'set up profile
oUser.Profile = New UserProfile
oUser.Profile.InitialiseProfile(PortalSettings.PortalId, True)
oUser.Profile.PreferredLocale = PortalSettings.DefaultLanguage
oUser.Profile.PreferredTimeZone = PortalSettings.TimeZone

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


'todo: create account
Dim createStatus As UserCreateStatus = UserController.CreateUser(oUser)

Expand Down Expand Up @@ -501,8 +521,6 @@ Namespace Connect.Modules.UserManagement.AccountRegistration
Exit Sub
End If

Dim propertiesCollection As New ProfilePropertyDefinitionCollection
UpdateProfileProperties(plhRegister, oUser, propertiesCollection, GetPropertiesFromTempate(GetTemplate(ModuleTheme, Constants.TemplateName_Form, CurrentLocale, False)))
oUser = ProfileController.UpdateUserProfile(oUser, propertiesCollection)

If blnUpdateFirstname = True Then
Expand Down

0 comments on commit d8fb658

Please sign in to comment.