From d8fb6586383a0f4f50812b5e8233e7264c4f9295 Mon Sep 17 00:00:00 2001 From: vmasanas Date: Fri, 4 Jul 2014 00:01:50 +0200 Subject: [PATCH] Add support for "pre" registration validation Refactor --- App_LocalResources/View.ascx.resx | 3 + View.ascx.vb | 96 ++++++++++++++++++------------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/App_LocalResources/View.ascx.resx b/App_LocalResources/View.ascx.resx index 5f9de73..5a4d290 100644 --- a/App_LocalResources/View.ascx.resx +++ b/App_LocalResources/View.ascx.resx @@ -321,4 +321,7 @@ + + The data you provided is not valid. Please review and try again + \ No newline at end of file diff --git a/View.ascx.vb b/View.ascx.vb index 4c70527..fd98883 100644 --- a/View.ascx.vb +++ b/View.ascx.vb @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) @@ -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) @@ -302,17 +302,6 @@ Namespace Connect.Modules.UserManagement.AccountRegistration End Try Next - If strMessages.Count > 0 Then - Me.pnlError.Visible = True - Me.lblError.Text = "" - Exit Sub - End If - - Dim oUser As UserInfo = New UserInfo 'approve membership if applicable @@ -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 = "" - Exit Sub + strMessages.Add(String.Format(Localization.GetString("InvalidPassword", LocalResourceFile), strPolicy)) End If Else - Me.pnlError.Visible = True - Me.lblError.Text = "" - Exit Sub + strMessages.Add(Localization.GetString("PasswordsDontMatch.Text", LocalResourceFile)) End If Else 'auto-generate password @@ -435,28 +420,24 @@ 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 = "" - - Exit Sub End If 'set up profile @@ -464,6 +445,45 @@ Namespace Connect.Modules.UserManagement.AccountRegistration 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 = "" + Exit Sub + End If + + 'todo: create account Dim createStatus As UserCreateStatus = UserController.CreateUser(oUser) @@ -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