vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB5 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=263)
-   -   External Login Question (https://vborg.vbsupport.ru/showthread.php?t=324208)

sn1p3r001 01-15-2017 02:38 PM

External Login Question
 
Hi there,

I'm new to PHP and modding vb, but I have a page that I want users to be able to log into using their vb5 info. I'm following the instructions in David Grove's guide to set this up.

In his example, he's got a form that displays:
Code:

////////////////////////// display a login form

    $userid = vB5_Cookie::get('userid', vB5_Cookie::TYPE_UINT);
    $hash = vB5_Cookie::get('password', vB5_Cookie::TYPE_STRING);

    if (empty($userid) OR empty($hash))
    {
        ?>
        <form action="vb5_external_login.php" method="post">

            <input type="text" name="username" value="" placeholder="User Name" />
            <input type="password" name="password" value="" placeholder="Password" />
            <label><input type="checkbox" name="remember" /> Stay logged in?</label>
            <input type="submit" value="Log In" />

        </form>

I see the form action is vb5_external_login.php. What is supposed to go in that PHP file?

Sorry if this is a dumb question. Thanks for your help!

noypiscripter 01-15-2017 03:20 PM

In his example, it is the same file where his sample code is. He could have also set the form action to blank and it will also go to the same page when the form is submitted.

sn1p3r001 01-15-2017 03:52 PM

Excellent, thank you. That seems to work fine. Two other questions..

What would I have to add to other pages for it to check to see if a user was logged in and a member of a certain usergroup? I want only members of group xyz to be able to access this page.

And how do I do a log out form?

Thanks!

noypiscripter 01-16-2017 03:14 AM

Is that a vBulletin page or an external page?

To logout, call the logout() method in user API and passing logouthash which you can find in the userinfo of the logged in user.

sn1p3r001 01-16-2017 10:02 AM

Quote:

Originally Posted by noypiscripter (Post 2580917)
Is that a vBulletin page or an external page?

External page. Thanks again.

noypiscripter 01-16-2017 06:01 PM

Call the fetchUserinfo() method of the user API passing the userid of the logged in user.

PHP Code:

$userid 1//hardcoded for demo purposes
$api Api_InterfaceAbstract::instance();
$userInfo $api->callApi('user''fetchUserinfo', array($userid));
var_dump($userInfo); 

From $userInfo, you will find 'usergroupid' and 'logouthash'.


All times are GMT. The time now is 07:12 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01091 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete