a-man
a-man

Reputation: 707

Make Umbraco property hidden

I need to store password reset token for umbraco members(from end members). For now solution I got is to create a property and use it. But the problem is that this token should be hidden from everyone. Is there any clean approach to make property hidden(without adding dependencies on packages)?

So far approach I found looks like this, but I am looking for more easier way to make property hidden:

public class ApplicationHandler : ApplicationEventHandler  
{  
   public ApplicationHandler()  
   {  
       ContentControl.AfterContentControlLoad  = new ContentControl.AfterContentControlLoadEventHandler(ContentControl_AfterContentControlLoad);  
   }  

private void ContentControl_AfterContentControlLoad(ContentControl contentControl, ContentControlLoadEventArgs e)  
   {  
    int docId = 0;  
       int.TryParse(HttpContext.Current.Request["id"], out docId);  
       IContent content = ApplicationContext.Current.Services.ContentService.GetById(docId);  

    Control ctl = umbraco.presentation.LiveEditing.Utility.FindControl<Control>(delegate(Control c)  
          {  
              return c.ClientID.EndsWith("propertyAliasToHide");  
          }, contentControl.Page);  
    HideProperty(ctl);  
}  

private void HideProperty(Control control)  
   {  
       if (control != null)  
       {  
           Control parent = control.Parent;  
           if (parent != null)  
           {  
               if (parent.Parent != null)  
               {  
                   if (parent.Parent.Parent != null)  
                   {  
                       parent.Parent.Parent.Visible = false;  
                   }  
               }  
           }  
       }  
   }  
   }  

Upvotes: 1

Views: 1873

Answers (2)

user3248331
user3248331

Reputation: 105

You can just use the label property editor to achieve this. Simply go to the Member type and add label. You can select the data type, and it also has the option of hiding the value from the user or making it un-editable.

I have used this often to update fields i don't want to be editable or seen from the members profile in the umbraco back office.

Upvotes: 0

Claus
Claus

Reputation: 1985

The easiest way is to simply create a property editor like the label one built into umbraco and then make sure it just doesn't display anything in the UI. Then you can add a custom property to the member using this editor and you will be able to save a value in it by code without having it show up in the backoffice UI.

There's instructions on creating a property editor here. You can skip over most of he parts as you would not need to show or be able to edit the value in the editor via the backoffice - you're simply using it as a sort of data container for your hidden value accessed and modified only by code.

https://our.umbraco.org/documentation/tutorials/Creating-a-Property-Editor/

Upvotes: 3

Related Questions