More in this section

Forums / General Discussions / Permissions on Profile Widget

Permissions on Profile Widget

4 posts, 1 answered
  1. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    12 Aug 2011
    Link to this post
    I'm currently working on a project where I need to display single user profiles on a couple of public pages. I've dropped a Profile widget on a page and customized the widget to my needs by setting it to Read mode only and setting it to display a single user. 

    It works perfectly when I'm logged in, but when not logged in, it just displays the text: "You are not logged in.". I thought this would be pretty easy to fix by altering the permissions, but I just can't seem to figure out how make the widget visible to anonymous users. Is this by design and do I need to create my own custom widget?

    Thanks in advance for your replies!
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    15 Aug 2011
    Link to this post
    Hello Rein,

    Anonymous users can't view profiles by implementation. However, there is a workaround that you can use. For this, you will have to:
     1)Create a C# Library Project in the Solution of your Project solution (I named it ProfileWidgetOR)
     2) Add references to the following assemblies:
    System.Web
    System.Web.Extensions
    Telerik.Sitefinity
    Telerik.Sitefinity.Resources
    Telerik.Sitefinity.Model
    Telerik.Sitefinity.Utilities
    Telerik.Sitefinity.MigrationContracts
    Telerik.Web.Design
    Telerik.Web.UI
    3)Create a Class (mine is name Class1.cs for simplicity) and paste this code into it and Build:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Microsoft.Practices.EnterpriseLibrary.Logging;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Forms.Model;
    using Telerik.Sitefinity.Modules.Forms;
    using Telerik.Sitefinity.Modules.Forms.Web.UI;
    using Telerik.Sitefinity.Modules.Forms.Web.UI.Fields;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Web.UI.Fields;
    using Telerik.Sitefinity.Security.Web.UI;
    using Telerik.Sitefinity.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    using Telerik.Sitefinity.Modules.UserProfiles.Web.UI;
    using Telerik.Sitefinity.Web.UI.ContentUI.Contracts;
     
    namespace ProfileWidgetOR
    {
         
        public class Class1 : UserProfileDetailReadView
        {
            public override string LayoutTemplatePath
            {
                get
                {
                    var userProfileViewHost = (UserProfileView)this.Host;
                    if (this.IsUserAuthenticated() || (userProfileViewHost.DisplayCurrentUser.HasValue))
                    {
                        string templatePath = null;
                        if (this.Definition != null)
                            templatePath = this.Definition.TemplatePath;
     
                        if (string.IsNullOrEmpty(templatePath))
                        {
                            return this.DefaultLayoutTemplatePath;
                        }
     
                        return templatePath;
                    }
                    else
                    {
                        if (this.ProfileViewDefinition == null || String.IsNullOrEmpty(this.ProfileViewDefinition.NoUserTemplatePath))
                        {
     
                            return UserProfileDetailReadView.noUserLayoutTemplatePath;
                        }
                        else
                        {
                            return this.ProfileViewDefinition.NoUserTemplatePath;
                        }
                    }
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
     
            public override string TemplateKey
            {
                get
                {
                    var userProfileViewHost = (UserProfileView)this.Host;
                    if (this.IsUserAuthenticated() || (userProfileViewHost.DisplayCurrentUser.HasValue))
                    {
                        string templateKey = null;
                        if (this.Definition != null)
                            templateKey = this.Definition.TemplateKey;
     
                        return templateKey;
                    }
                    else
                    {
                        return this.NotLoggedTemplateKey;
                    }
                }
                set
                {
                    base.TemplateKey = value;
                }
            }
        }
    }

    4) Add Reference to the previously created project from your SitefinityWebApp
    5) Go to Sitefinity Backend, then go to
    Administration >> Settings >> Advanced >> ContentView >> Controls >>FrontendSingleProfile >> Views >> UserProfilesFrontendRead and set ViewType with this value:
    ProfileWidgetOR.Class1 (this is Namespace.Class of the project you have created in the first 3 steps)
    6)Put your UserProfile widget (in ReadOnly mode, displaying SelectedUser)

    Now anonymous users will be able to see the widget.
    Hope that helps.

    Greetings,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Rein
    Rein avatar
    22 posts
    Registered:
    07 Oct 2008
    13 Sep 2011
    Link to this post
    Hi Svetoslav,

    Thank you for your answer. I have one more question though.

    I need to override the settings of the auto-generated details page, so that also anonymous users can view the profile details. How can I achieve the same functionality as your solution above for the details page of the profile?

    Thanks in advance for your help!

    Rein
  4. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    14 Sep 2011
    Link to this post
    Hi Rein,

     The ProfileList widget uses the same DetailsView that is used by the SingleUser Widget. This means that you can use the same class and it will work perfectly for the details page of your ProfileList widget. Just go to 
    Administration >> Settings >> Advanced >> ContentView >> Controls >>FrontendSingleProfile >> Views >> FrontendUsersList >> UserProfilesFrontendDetailsRead and set the ViewType property to be have the same value as the previous one (ProfileWidgetOR.Class1).

    Best wishes,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 1 answered