/// <summary> /// Add the custom properties to the Default Member Type /// receiveNotifications /// hasVerifiedAccount /// resetGuid /// joinedDate /// </summary> /// <returns></returns> private void AddMemberProperties() { bool saveMemberContent = false; var _memberTypeService = Current.Services.MemberTypeService; var _dataTypeService = Current.Services.DataTypeService; string groupname = "Forum Settings"; string mType = "Member"; var ds = Current.Services.LocalizationService; var newaccountType = ds.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType"); if (newaccountType != null) { mType = newaccountType.GetDefaultValue(); } IMemberType memberContentType = _memberTypeService.Get(mType); var dataTypeDefinitions = _dataTypeService.GetAll().ToArray(); //.ToArray() because arrays are fast and easy. var truefalse = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.truefalse"); //we want the TrueFalse data type. var textbox = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.textbox"); //we want the TextBox data type. try { if (!memberContentType.PropertyGroups.Contains(groupname)) { memberContentType.AddPropertyGroup(groupname); //add a property group, not needed, but I wanted it saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("receiveNotifications")) { memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Receive Notifications", Alias = "receiveNotifications", Description = "Get an email when someone posts in a topic you are participating.", Mandatory = false }, groupname); saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("hasVerifiedAccount")) { memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Has verified Email", Alias = "hasVerifiedAccount", Description = "User has verified their account.", Mandatory = false }, groupname); saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("resetGuid")) { memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Reset Guid", Alias = "resetGuid", Description = "Guid set when user requests a password reset.", Mandatory = false }, groupname); saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("joinedDate")) { memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Joined date", Alias = "joinedDate", Description = "Date the user joined (validated email).", Mandatory = false }, groupname); saveMemberContent = true; } if (saveMemberContent) { _memberTypeService.Save(memberContentType); //save the content type } } catch (Exception e) { Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().GetType(), e, "Executing ForumInstallHandler:Add member types"); } }
private string AddMemberProperties() { bool saveMemberContent = false; StringBuilder contentStatus = new StringBuilder(); string groupname = "Forum Settings"; string mType = "Member"; contentStatus.Append("<ul>"); var newaccountType = _localizationService.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType"); if (newaccountType != null) { mType = newaccountType.GetDefaultValue(); } IMemberType memberContentType = _memberTypeService.Get(mType); var dataTypeDefinitions = _dataTypeService.GetAll().ToArray(); //.ToArray() because arrays are fast and easy. var truefalse = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.truefalse"); //we want the TrueFalse data type. var textbox = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.textbox"); //we want the TextBox data type. try { if (!memberContentType.PropertyGroups.Contains(groupname)) { memberContentType.AddPropertyGroup(groupname); //add a property group, not needed, but I wanted it saveMemberContent = true; } contentStatus.Append("<li>"); if (!memberContentType.PropertyTypeExists("receiveNotifications")) { contentStatus.Append("Adding property receiveNotifications"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Receive Notifications", Alias = "receiveNotifications", Description = "Get an email when someone posts in a topic you are participating.", Mandatory = false }, groupname); if (saveMemberContent) { memberContentType.SetMemberCanEditProperty("receiveNotifications", true); memberContentType.SetMemberCanViewProperty("receiveNotifications", true); } contentStatus.Append("<strong>done</strong>"); } else { memberContentType.SetMemberCanEditProperty("receiveNotifications", true); memberContentType.SetMemberCanViewProperty("receiveNotifications", true); } contentStatus.Append("</li><li>"); if (!memberContentType.PropertyTypeExists("hasVerifiedAccount")) { contentStatus.Append("Adding property hasVerifiedAccount"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Has verified Email", Alias = "hasVerifiedAccount", Description = "User has verified their account.", Mandatory = false }, groupname); contentStatus.Append("<strong>done</strong>"); } contentStatus.Append("</li><li>"); if (!memberContentType.PropertyTypeExists("resetGuid")) { contentStatus.Append("Adding property resetGuid"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Reset Guid", Alias = "resetGuid", Description = "Guid set when user requests a password reset.", Mandatory = false }, groupname); if (saveMemberContent) { memberContentType.SetIsSensitiveProperty("resetGuid", true); } contentStatus.Append("<strong>done</strong>"); } contentStatus.Append("</li><li>"); if (!memberContentType.PropertyTypeExists("joinedDate")) { contentStatus.Append("Adding property joinedDate"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Joined date", Alias = "joinedDate", Description = "Date the user joined (validated email).", Mandatory = false }, groupname); if (saveMemberContent) { memberContentType.SetMemberCanViewProperty("joinedDate", true); } contentStatus.Append("<strong>done</strong>"); } contentStatus.Append("</li>"); if (saveMemberContent) { _memberTypeService.Save(memberContentType); //save the content type } else { throw new ArgumentException("Unable to add custom Member properties"); } } catch (Exception e) { Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().GetType(), e, "Executing ForumInstallHandler:Add member types"); contentStatus.Append($"<li>Error adding properties: {e.Message}</li>"); } contentStatus.Append("</ul>"); return(contentStatus.ToString()); }