The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting Logged in users details (UID)

Discussion in 'cPanel Developers' started by Megan Davidson, Mar 31, 2015.

  1. Megan Davidson

    Megan Davidson Registered

    Joined:
    Mar 31, 2015
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Hi,

    I'm currently converting an x3 theme over to the Paper Lantern theme, the current x3 theme uses PHP and session variables to store some user information (uid, email), this is retrieved from doing api calls to '"127.0.0.1:2087/json-api/nvget?key=".$current_user_uid.":useremail"', then stores the results in a PHP session that the x3 theme can easily use when the php renders the front end. This plugin was originally created by a 3rd party company, so I'm now having to learn CPanel and understand the 3rd parties code.

    Because we have to use the new Template Toolkit with Paper Lantern, I have no way of getting the PHP session variables across to the template file for the UI.

    So from looking at the other template (*.tt) files it would seem I have to do the following call in my template file:

    [% data = execute( 'NVdata', 'get', { names => 'megan'} ); %]

    Where 'megan' is the current logged in username, and I hope from that I can get the (uid, email)

    But I'm getting the following error:

    Code:
    [B]Can't locate Cpanel/API/NVdata.pm in @INC (@INC contains: /usr/local/cpanel/Cpanel/CPAN/overload/__Digest /usr/local/cpanel/Cpanel/CPAN/overload/__Time /usr/local/cpanel /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/5.14.4/x86_64-linux-64int /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/5.14.4 /usr/local/cpanel /opt/cpanel/perl5/514/site_lib/x86_64-linux-64int /opt/cpanel/perl5/514/site_lib) at (eval 19) line 1.
    at (eval 19) line 1.
        Cpanel::LoadModule::BEGIN() called at (eval 19) line 1
        eval {...} called at (eval 19) line 1
        eval ' use Cpanel::API::NVdata; Cpanel::API::NVdata::API::NVdata_init() if "Cpanel::API::NVdata"->can("API::NVdata_init"); 
    ;' called at /usr/local/cpanel/Cpanel/LoadModule.pm line 135
        Cpanel::LoadModule::_modloader("API::NVdata") called at /usr/local/cpanel/Cpanel/LoadModule.pm line 67
        Cpanel::LoadModule::loadmodule("API::NVdata") called at /usr/local/cpanel/Cpanel/API.pm line 142
        Cpanel::API::_init_execute("NVdata", "get") called at /usr/local/cpanel/Cpanel/API.pm line 58
        Cpanel::API::execute("NVdata", "get", HASH(0x55306b8)) called at /usr/local/cpanel/base/frontend/paper_lantern/basekit/activation.html.tt line 2
        eval {...} called at /usr/local/cpanel/base/frontend/paper_lantern/basekit/activation.html.tt line 2
        eval {...} called at /usr/local/cpanel/base/frontend/paper_lantern/basekit/activation.html.tt line 7
        Template::Document::__ANON__(Template::Context=HASH(0x552b288)) called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template/Document.pm line 163
        eval {...} called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template/Document.pm line 161
        Template::Document::process(Template::Document=HASH(0x5558780), Template::Context=HASH(0x552b288)) called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template/Context.pm line 347
        eval {...} called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template/Context.pm line 321
        Template::Context::process(Template::Context=HASH(0x552b288), Template::Document=HASH(0x5558780)) called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template/Service.pm line 94
        eval {...} called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template/Service.pm line 91
        Template::Service::process(Template::Service=HASH(0x552ae38), "/usr/local/cpanel/base/frontend/paper_lantern/basekit/activat"..., HASH(0x559bb58)) called at /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib/x86_64-linux-64int/Template.pm line 66
        Template::process(Template=HASH(0x5557f58), "/usr/local/cpanel/base/frontend/paper_lantern/basekit/activat"..., HASH(0x559bb58), SCALAR(0x3c171f8)) called at /usr/local/cpanel/Cpanel/Template.pm line 461
        Cpanel::Template::process_template("cpanel", HASH(0x559bb58), HASH(0x55bdfc8)) called at cpanel.pl line 1139
        main::cptt_exectag("/usr/local/cpanel/base/frontend/paper_lantern/basekit/activat"...) called at cpanel.pl line 5543
        main::_parse_auto_template("/usr/local/cpanel/base/frontend/paper_lantern/basekit/activat"...) called at cpanel.pl line 5388
        main::run_standard_mode() called at cpanel.pl line 831[/B]
    
    Can anyone possibly give me any clues on what could be causing this and if I'm going about this the correct way?
     
    #1 Megan Davidson, Mar 31, 2015
    Last edited by a moderator: Mar 31, 2015
  2. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Here is the docs on NVData::Get
    http://documentation.cpanel.net/display/SDK/cPanel+API+2+Functions+-+NVData::get

    By default what it returns will only be what it set; and from a quick glance at some accounts on my box we don't have any where we set the UUID. You may want to investigate where the code you have might be getting and setting that value.


    Edit:

    Here is an example of where we make the NVData::Get call successfully. You are likely just missing the Use statement in your code.

    Code:
    [%-
    USE Api2;
    
    SET mainGroupsOrder = execute( 'NVData', 'get', { 'names' => 'xmaingroupsorder' } );
    %]
    
     
  3. Megan Davidson

    Megan Davidson Registered

    Joined:
    Mar 31, 2015
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Thanks for the quick reply.

    I'm just basing my idea's on what was in the original php plugin code:

    // LOAD CP MODULE TO GET CONFIG DATA
    //================================================================
    <cpanel PHP="loadvars()">
    <cpanel PHP="loadparkeddomains()">
    <cpanel PHP="loadsubdomains()">
    <cpanel PHP="loaddocroots()">

    $current_user_uid = $_CPANEL['USERDATA']['uid'];

    It's getting the $_CPANEL from the 'loadvars' internal call, I'm not sure how to emulate this in a Template Toolkit.
     
    #3 Megan Davidson, Mar 31, 2015
    Last edited: Mar 31, 2015
  4. Megan Davidson

    Megan Davidson Registered

    Joined:
    Mar 31, 2015
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    It seems I was missing 'USE Api 2;', so adding that has fixed the errors now.

    I've gone through the docs and cannot find any equivalent call in the Template Toolkit to load the same values as 'loadvars' from the '<cpanel PHP="loadvars()">' php example.

    This will give me the details I need.
     
Loading...

Share This Page