+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / How to set avatar in user profile?

How to set avatar in user profile?

15 posts, 0 answered
  1. Raihan
    Raihan avatar
    17 posts
    Registered:
    25 Mar 2011
    22 Apr 2011
    Link to this post
    Hi,

    I'm using the new Sitefinity 4.1 API to create user profile. I was able to set the FirstName and LastName but I would like to know how to set the Avatar field and what is the type of that field.

    var profileManager = UserProfileManager.GetManager();
    var profile = profileManager.CreateProfile(newUser, typeof(SitefinityProfile).FullName);
    Telerik.Sitefinity.Model.DataExtensions.SetValue(profile, "FirstName", txtFirstName.Text);
    Telerik.Sitefinity.Model.DataExtensions.SetValue(profile, "LastName", txtLastName.Text);
    Telerik.Sitefinity.Model.DataExtensions.SetValue(profile, "Avatar", ???);

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    22 Apr 2011
    Link to this post
    Hi Raihan,

    SitefinityProfile has a property Avatar that you can use directly. The filedName is "Avatar".
    As a value you can pass Telerik.Sitefinity.Libraries.Model.Image - MediaUrl + .tmb

    Regards,
    Ivan Dimitrov
    the Telerik team

  3. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    22 Apr 2011
    Link to this post
    Hi Ivan,

    I have another question. How to retrieve an URL for avatar? I've implemented the following code:

    protected void Page_Load(object sender, EventArgs e)
    {
        UserManager userManager = UserManager.GetManager();
        User user = userManager.GetUser("admin");
        UserProfileManager userProfileManager = UserProfileManager.GetManager();
        UserProfile profile = userProfileManager.GetUserProfile(user.Id, typeof(SitefinityProfile).FullName);
        ContentLink v = Telerik.Sitefinity.Model.DataExtensions.GetValue(profile, "Avatar") as ContentLink;
         
    }

    It returns the object of Telerik.Sitefinity.Model.ContentLinks.ContentLink type. How to get an image URL from it?

    Thank in advance,
    Anton.
  4. Raihan
    Raihan avatar
    17 posts
    Registered:
    25 Mar 2011
    23 Apr 2011
    Link to this post
    Can you please elaborate your code?

    Telerik.Sitefinity.Libraries.Model.Image - MediaUrl + .tmb

    Why the minus "-" sign?? And what is .tmb?

    Please can you provide a complete code sample or a link to a tutorial?

    Thanks
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Apr 2011
    Link to this post
    Hi,

    In my code I am referring to a thumbnail of an images, because this is more convenient than scaling the image again. You can check the media modules API

    Kind regards,
    Ivan Dimitrov
    the Telerik team

  6. j8
    j8 avatar
    20 posts
    Registered:
    30 Oct 2007
    28 Apr 2011
    Link to this post

    @Anton

    Hi,

    I had the same problem, this worked for me;

    Regards,

      Peter

    ContentLink v = p1.GetValue("Avatar"as ContentLink;
    var images = App.WorkWith().Images().Where(w => w.Id == v.ChildItemId).Get();
    Telerik.Sitefinity.Libraries.Model.Image img = images.FirstOrDefault();
    if (img != null) {
      imgAvatar.ImageUrl = img.MediaUrl;
    }



  7. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    03 May 2011
    Link to this post
    imgAvatar.ImageUrl = img.MediaUrl + ".tmb";

    will get you the default thumbnail size of 120width
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 May 2011
    Link to this post
    Hello Kristian,

    This should return you the image in the same size which will be generated when you type

    http://host/images/default-album/myimage.png.tmb

    All the best,
    Ivan Dimitrov
    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
  9. raj
    raj avatar
    9 posts
    Registered:
    27 Jun 2012
    27 Jun 2012
    Link to this post
    Dear Community,

    We have frontend users where they can update their profile Avatar along with their profile data. For this we have created a custom user control where users edit their profile data along with Avatar. Since users are not backend user and do not have enough rights, we are facing problems in updating this data. 

    However we are able  to update user & profile data by setting SuppressSecurityChecks to true. Similarly we are also able to upload Avatar Image to a Album by setting SuppressSecurityChecks to true for librariesManager.Provider.

    However when trying to publish this image using WorkflowManager.MessageWorkflow we are getting persmission issues. We are unable to suppress this security check. Kindly advise how can we resolve this issue.

    Here is the code that we are using:
    01.protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    02.        {
    03. 
    04.            var manager = UserManager.GetManager();
    05.            var user = manager.GetUser(HttpContext.Current.User.Identity.Name);
    06.            Guid masterImageId = Guid.NewGuid();
    07.            if (user != null)
    08.            {
    09.                var profilemanager = UserProfileManager.GetManager();
    10.                var uProfile = profilemanager.GetUserProfile(user,typeof(SitefinityProfile).FullName) as SitefinityProfile;
    11.                if (uProfile != null)
    12.                {
    13.                    var pAvatar = uProfile.Avatar;
    14.                    if(pAvatar != null)
    15.                        masterImageId = pAvatar.ChildItemId;
    16. 
    17.                    LibrariesManager librariesManager = LibrariesManager.GetManager();
    18.                    Telerik.Sitefinity.Libraries.Model.Image temp = null;
    19.                    Telerik.Sitefinity.Libraries.Model.Image master = librariesManager.GetImages().Where(i => i.Id == masterImageId).FirstOrDefault();
    20. 
    21.                    librariesManager.Provider.WithSuppressedSecurityChecks(() =>
    22.                        {
    23.                            if (master != null)
    24.                                temp = librariesManager.Lifecycle.CheckOut(master) asTelerik.Sitefinity.Libraries.Model.Image;
    25.                            else
    26.                            {
    27.                                temp = librariesManager.CreateImage(masterImageId);
    28.                                temp.DateCreated = DateTime.UtcNow;
    29.                                temp.PublicationDate = DateTime.UtcNow;
    30.                            }
    31.                            Album album = librariesManager.GetAlbums().Where(i => i.Title == "UserProfile").SingleOrDefault();
    32.                            temp.Parent = album;
    33.                            temp.Title = user.UserName;
    34.                            temp.LastModified = DateTime.UtcNow;
    35.                            temp.UrlName = Regex.Replace(temp.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+""-");
    36. 
    37.                            //Upload the image file.
    38.                            librariesManager.Upload(temp, e.File.InputStream, e.File.GetExtension());
    39. 
    40.                            if (master != null)
    41.                                master = librariesManager.Lifecycle.CheckIn(temp) asTelerik.Sitefinity.Libraries.Model.Image;
    42.                            librariesManager.SaveChanges();
    43. 
    44.                            var bag = new Dictionary<stringstring>();
    45.                            bag.Add("ContentType",typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName);
    46.                            WorkflowManager.MessageWorkflow(masterImageId,typeof(Telerik.Sitefinity.Libraries.Model.Image), null"Publish"false, bag);
    47. 
    48.                            if (pAvatar == null)
    49.                            {
    50.                                ContentLink avatarLink = ContentLinksExtensions.CreateContentLink(uProfile, temp);
    51.                                uProfile.Avatar = avatarLink;
    52.                                profilemanager.SaveChanges();
    53.                            }
    54.                            Thumbnail.ImageUrl = common.GetImageUrl(masterImageId,true);
    55.                        });
    56.                }
    57.            }
    58.        }

    Following is the area which causes this error
    1.var bag = new Dictionary<stringstring>();
    2.                           bag.Add("ContentType",typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName);
    3.                           WorkflowManager.MessageWorkflow(masterImageId,typeof(Telerik.Sitefinity.Libraries.Model.Image), null"Publish"false, bag);

    Error is as follows:
    You are not authorized to 'Modify library and manage images' ('Image').  

    Thanks in advance.

    Regards,
    Raj
  10. raj
    raj avatar
    9 posts
    Registered:
    27 Jun 2012
    27 Jun 2012
    Link to this post
    Dear Community,

    We have frontend users where they can update their profile Avatar along with their profile data. For this we have created a custom user control where users edit their profile data along with Avatar. Since users are not backend user and do not have enough rights, we are facing problems in updating this data. 

    However we are able  to update user & profile data by setting SuppressSecurityChecks to true. Similarly we are also able to upload Avatar Image to a Album by setting SuppressSecurityChecks to true for librariesManager.Provider.

    However when trying to publish this image using WorkflowManager.MessageWorkflow we are getting persmission issues. We are unable to suppress this security check. Kindly advise how can we resolve this issue.

    Here is the code that we are using:
    01.protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    02.        {
    03. 
    04.            var manager = UserManager.GetManager();
    05.            var user = manager.GetUser(HttpContext.Current.User.Identity.Name);
    06.            Guid masterImageId = Guid.NewGuid();
    07.            if (user != null)
    08.            {
    09.                var profilemanager = UserProfileManager.GetManager();
    10.                var uProfile = profilemanager.GetUserProfile(user,typeof(SitefinityProfile).FullName) as SitefinityProfile;
    11.                if (uProfile != null)
    12.                {
    13.                    var pAvatar = uProfile.Avatar;
    14.                    if(pAvatar != null)
    15.                        masterImageId = pAvatar.ChildItemId;
    16. 
    17.                    LibrariesManager librariesManager = LibrariesManager.GetManager();
    18.                    Telerik.Sitefinity.Libraries.Model.Image temp = null;
    19.                    Telerik.Sitefinity.Libraries.Model.Image master = librariesManager.GetImages().Where(i => i.Id == masterImageId).FirstOrDefault();
    20. 
    21.                    librariesManager.Provider.WithSuppressedSecurityChecks(() =>
    22.                        {
    23.                            if (master != null)
    24.                                temp = librariesManager.Lifecycle.CheckOut(master) asTelerik.Sitefinity.Libraries.Model.Image;
    25.                            else
    26.                            {
    27.                                temp = librariesManager.CreateImage(masterImageId);
    28.                                temp.DateCreated = DateTime.UtcNow;
    29.                                temp.PublicationDate = DateTime.UtcNow;
    30.                            }
    31.                            Album album = librariesManager.GetAlbums().Where(i => i.Title == "UserProfile").SingleOrDefault();
    32.                            temp.Parent = album;
    33.                            temp.Title = user.UserName;
    34.                            temp.LastModified = DateTime.UtcNow;
    35.                            temp.UrlName = Regex.Replace(temp.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+""-");
    36. 
    37.                            //Upload the image file.
    38.                            librariesManager.Upload(temp, e.File.InputStream, e.File.GetExtension());
    39. 
    40.                            if (master != null)
    41.                                master = librariesManager.Lifecycle.CheckIn(temp) asTelerik.Sitefinity.Libraries.Model.Image;
    42.                            librariesManager.SaveChanges();
    43. 
    44.                            var bag = new Dictionary<stringstring>();
    45.                            bag.Add("ContentType",typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName);
    46.                            WorkflowManager.MessageWorkflow(masterImageId,typeof(Telerik.Sitefinity.Libraries.Model.Image), null"Publish"false, bag);
    47. 
    48.                            if (pAvatar == null)
    49.                            {
    50.                                ContentLink avatarLink = ContentLinksExtensions.CreateContentLink(uProfile, temp);
    51.                                uProfile.Avatar = avatarLink;
    52.                                profilemanager.SaveChanges();
    53.                            }
    54.                            Thumbnail.ImageUrl = common.GetImageUrl(masterImageId,true);
    55.                        });
    56.                }
    57.            }
    58.        }

    Following is the area which causes this error
    1.var bag = new Dictionary<stringstring>();
    2.                           bag.Add("ContentType",typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName);
    3.                           WorkflowManager.MessageWorkflow(masterImageId,typeof(Telerik.Sitefinity.Libraries.Model.Image), null"Publish"false, bag);

    Error is as follows:
    You are not authorized to 'Modify library and manage images' ('Image').  

    Thanks in advance.

    Regards,
    Raj
  11. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    27 Jun 2012
    Link to this post
    Hmm, i don't see any reason why you can't use the default profile widget Sitefinity provides (Users > Profile). Then just edit the template to the fields you want to display/edit. Also the avatars are stored in the Default Image library. You should set permissions to that library to allow modifications by authenticated users. I just dedicated that library for user profiles and make another one for images I want to use elsewhere.
  12. raj
    raj avatar
    9 posts
    Registered:
    27 Jun 2012
    27 Jun 2012
    Link to this post
    Hi Kristian,
    Thanks for replying back. We have certain custom logic to be applied and requires us to use custom control and not profile widget provided by Sitefinity.

    We have a separate role created for the frontend site users and have given rights to modify images to that role for that library but while publishing using WorkflowManager it still gives the authorization error.

    Do you have any idea to suppress security checks for publishing images just like we do using SuppressSecurityChecks for usermanager, profilemanager & Librarymanager.

    Thanks for all your help. Really appreciate it.

    Regards,
    Raj
  13. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    27 Jun 2012
    Link to this post
    Have you tried suppressing security checks on the workflowmanager?
  14. raj
    raj avatar
    9 posts
    Registered:
    27 Jun 2012
    27 Jun 2012
    Link to this post
    Yes tried that as well. Does not work.
  15. Khai
    Khai avatar
    10 posts
    Registered:
    08 Jan 2013
    12 Mar 2013
    Link to this post
    anyone has an update to this? I'm running into the same problem.
15 posts, 0 answered