Forum Discussion

RogersRoland's avatar
8 years ago

Textkey/Tag for Email Address

Currently we have IP address showing in our Profilecards using this code

<#if isAdmin>
<li>
<#assign userIP = rest("/users/id/"+user_id+"/settings/name/user.last_visit_ipaddress?restapi.response_style=view").value />
<span class="label">IP Address:</span> <span class="value">${userIP}</span>
</li>
</#if>

I'm looking to add a possible option to display the Email Address as well if Admin.  What would be the coding I would need to add in, and/or what is the textkey for user Email address?

 

Thanks!

10 Replies

  • RogersRoland-

     

    <#if isAdmin>
    <li>
     <#assign qry = "select email from users where id = '${user_id}'" />
     <#assign email = rest(apiVersion, "/search?q=" + qry?url + "&restapi.response_style=view").data.items[0].email /> <span class="label">Email:</span> <span class="value">${email}</span> </li> </#if>

     Give kudos if you find my posts helpful or mark solution if it answers your query

  • RogersRoland's avatar
    RogersRoland
    Expert
    8 years ago

    TariqHussain,  I've attempted to use your code but it results in an error.

    keshavkelkar, When i use yours, it doesn't give me an error but in turn also doesn't show anything.

     

    I feel like i'm missing something.

     

     

  • VarunGrazitti's avatar
    VarunGrazitti
    Boss
    8 years ago

    keshavkelkar - The reason TariqHussain code is showing error is because:

     

    isAdmin is not defined

    apiVersion is not defined, should be 2.0

     

    So, the working code would require you to define these variable before using. Once done, it'd work fine.

     

    Try this for e.g.

     

    <li>
    <#assign qry = "select email from users where id = '${user.id}'" />
    <#assign email = rest("2.0", "/search?q=" + qry?url + "&restapi.response_style=view").data.items[0].email />
    <span class="label">Email:</span> <span class="value">${email}</span>
    </li>

     

    I hope this helps.

  • keshavkelkar's avatar
    keshavkelkar
    Ace
    8 years ago

    RogersRoland  Have you used respected user_id ????

     

    <#assign emailAdd = rest ("users/id/"+user_id+"/email")>

     

    for example 

    <#assign emailAdd = rest ("users/id/12345/email")>

  • RogersRoland's avatar
    RogersRoland
    Expert
    8 years ago

    VarunGrazitti wrote:

    @keshavkelkar - The reason @tariq_grazitti code is showing error is because:

     

    isAdmin is not defined

    apiVersion is not defined, should be 2.0

     

    So, the working code would require you to define these variable before using. Once done, it'd work fine.

     

    Try this for e.g.

     

    <li>
    <#assign qry = "select email from users where id = '${user.id}'" />
    <#assign email = rest("2.0", "/search?q=" + qry?url + "&restapi.response_style=view").data.items[0].email />
    <span class="label">Email:</span> <span class="value">${email}</span>
    </li>

     

    I hope this helps.

    VarunGrazitti keshavkelkar TariqHussain

     

     

    I was able to get it to work using this method. 

     

    Question #2

    I want to have the email visible for Moderators and not just those with Admin status.

     

    How can I change the settings to reflect this?

  • VarunGrazitti's avatar
    VarunGrazitti
    Boss
    8 years ago
    RogersRoland - You need to create a macro where you define all the roles which are allowed to see this like admin, moderator or xyz. Then, instead of isAdmin, may be create a variable called accessHolders to make it more obvious.
  • RogersRoland's avatar
    RogersRoland
    Expert
    8 years ago

    VarunGrazitti

     

    So i was able to resolve the role issue but changing from administrator to moderator instead. It worked better for our Community setup.

     

    I did however encounter an error now that I pushed the update live.

     

    I am currently running 

     

    <#assign qry = "select email from users where id = '${user.id}'" />
    <#assign email = rest("2.0", "/search?q=" + qry?url + "&restapi.response_style=view").data.items[0].email />
    <span class="label">Email:</span> <span class="value">${email}</span>

    However the result for email result is my own. Did i input something wrong?

  • VarunGrazitti's avatar
    VarunGrazitti
    Boss
    8 years ago
    RogersRoland - You are using the context object ${user.id} which brings your own ID. You need to pass the ID of the user for whom you want to fetch the email.