Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 10:14
    Fuji Kusaka
    0

    Display Member Name

    Hi,

    Can someone point out how to i get to display another field from the members area. 

    Like for example if i have a field like First Name, Details or Company Name...

    I have the following code working but only displaying Login and UserName and Email

    @using umbraco.cms.businesslogic.member
    @using System.Web  
    @using System.Web.Security

    @helper Message(string message)
    {
     <p>@message</p>
    }

    @
      var currentUser Membership.GetUser();
     
      if (currentUser!=null)
       {    
            @Message(currentUser.UserName)
       }
      
      }

     

    //fuji

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 09, 2012 @ 11:29
    Jeroen Breuer
    1

    Here is how you can do it in C#: http://our.umbraco.org/forum/developers/extending-umbraco/27626-Accessing-Member-Information?p=0. So you could also do this with a helper or function in Razor.

    Jeroen

  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 13:08
    Fuji Kusaka
    0

    I tried this to get the Current Node Name which is actually the First Name of Member

      var userNames Member.GetCurrentMember().Text;
    @userNames 
  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 13:36
    Fuji Kusaka
    0

    Hi Jeroen,

    I tried something like to 

     @currentUser.GetProperty("fullName").Value.ToString();

    but getting an error on saving .


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 09, 2012 @ 14:40
    Jeroen Breuer
    2

    Using the member api can be slow, but if you really want to use that this might work:

    @currentUser.getProperty("fullName").Value.ToString();

    Jeroen

  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 15:01
    Fuji Kusaka
    0

    Getting an error CS1061 while saving the cshtml

    @helper Message(string message)
    {
     <p>@message </p>
    }

    @
      var currentUser Membership.GetUser();
         var userName Member.GetCurrentMember().Text;
      
      
      if (currentUser!=null)
       {    
             <p><strong@userName</strong&nbsp</p>
              <p>@currentUser.getProperty("fullName").Value.ToString();</p>      
        
       }
      
      <p>Name:  @Member.GetCurrentMember().Email;</p>    
      }

    //fuji

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 09, 2012 @ 15:20
    Tom Fulton
    2

    For this method you probably want to replace var currentUser with

    var currentUser = Member.GetCurrentMember();

    with your original code you're getting the .NET Member object which won't have the methods you're trying to access - you want the Umbraco Member object

     

    @{ 
      var currentUser = Member.GetCurrentMember();

      if (currentUser!=null)
       {    
    var userName = currentUser.Text;    
    <p><strong> @userName</strong> &nbsp; </p>
    <p>@currentUser.getProperty("fullName").Value.ToString();</p>      
    <p>Name:  @currentUser.Email;</p>     
       }
      }

    -Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 15:20
    Fuji Kusaka
    0

    HI Jeroen,

    This works for me instead

    @Member.GetCurrentMember().getProperty("fullName").Value.ToString();
    @currentUser.getProperty("fullName").Value.ToString() // cant save file when using @currentUser

     

    //fuji



  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 15:25
    Fuji Kusaka
    0

    Hi Tom,

    Thanks for the reply, i guess i foound it as same. Same Same but in a different way of proceeding. But thanks to both of you for the help.

    @
         var currentUser Membership.GetUser();
         var userTitle Member.GetCurrentMember().Email;
          var userNames Member.GetCurrentMember().Text;
      
      
      if (currentUser!=null)
       {    
             <p>Login as<strong@userNames</strong&nbsp</p>
             <p>Full Name :  @Member.GetCurrentMember().getProperty("fullName").Value.ToString()</p>
               
       }
      
      }

    //fuji

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 09, 2012 @ 15:28
    Tom Fulton
    0

    Yep, BTW save yourself some duplication and performance by storing the current member in a variable and accessing that for the properties you need (Name, email, etc) instead of calling Member.GetCurrentMember() several times :)

  • Fuji Kusaka 2203 posts 4220 karma points
    May 09, 2012 @ 15:48
    Fuji Kusaka
    0

    Totally agree....

  • Daniel Larsen 116 posts 381 karma points
    Feb 28, 2013 @ 16:07
    Daniel Larsen
    0

    Hi, I was just wondering how you get the member types? 

    Standard users should only be able to see some information and admins other informations. That is what i want to achive.

    Thanks :-) 

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 03, 2013 @ 04:22
    Tom Fulton
    1

    Hi Daniel,

    You could use this to get the alias of the current member's type:

    @umbraco.cms.businesslogic.member.Member.GetCurrentMember().ContentType.Alias

    This probably isn't cached, though FYI

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft