vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB5 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=263)
-   -   Custom Form User Registration (https://vborg.vbsupport.ru/showthread.php?t=327469)

doc55 08-17-2019 04:41 PM

Custom Form User Registration
 
I'm trying to create a custom form for user registration and I'm stuck. I appreciate if anyone could help me out a bit. I'm not an expert coder but I try to read and put pieces together.
Here is the code that I have but it is not working. I'm not sure what I'm doing wrong here.

PHP Code:

// Path to vBulletin installation
$vbpath 'forum';

// Start script
require_once($vbpath '/includes/vb5/autoloader.php');
vB5_Autoloader::register($vbpath);

//init the vBulletin system
require_once($vbpath '/core/vb/vb.php');
vB::init();

//get user info
$user ['username'] =  $_POST['username'];
$user ['email'] =  $_POST['email'];

//Create new user
$userApi vB_Api::instance('user');
$userId $userApi->save(0$_POST['password'], $user, array(), array(), array()); 


delicjous 08-19-2019 09:37 AM

Not that easy!

Perhaps you need humanverification .... Look whats your $userId return.

doc55 08-20-2019 04:48 PM

The human verification is disabled in the setting. Now, can someone please look at this and tell my why this is not writing the user to the database? Nothing is being saved to the database.
PHP Code:

<?php
//init the vBulletin system
require_once( '/forum/core/vb/vb.php' );
vB::init();

// Connection
$admin 'superadmin';
$api init_api$admin );

function 
init_api$admin ) {

  
define"CSRF_PROTECTION"false );
  require_once( 
'/forum/includes/vb5/autoloader.php' );
  
vB5_Autoloader::register'/forum' );
  
vB5_Frontend_Application::init'config.php' );
  
vB::getDbAssertor()->delete"session", array( "sessionhash" => vB::getCurrentSession()->get"dbsessionhash" ) ) );

  
$username vB_String::htmlSpecialCharsUni$admin );
  
$userinfo vB::getDbAssertor()->getRow"user", array( "username" => $username ) );
  
$auth array_intersect_key$userinfoarray_flip( [ "userid""secret""lastvisit""lastactivity" ] ) );
  
$loginInfo vB_User::processNewLogin$auth );
  
vB5_Auth::setLoginCookies$loginInfo""false );
  
$api Api_InterfaceAbstract::instance();

  return 
$api;
}

//get user info
$username $_POST'form' ][ 'username' ];
$email $_POST'form' ][ 'email' ];
$password $_POST'form' ][ 'password' ];
$data = array(
  
'userid' => 0,
  
'password' => $password,
  
'user' => array( 'username' => $username'email' => $email ),
  array(),
  array(),
  
'userfield' => false,
  array(),
  
'',
  array( 
'registration' => true )
);

$response $api->callApi'user''save'$datafalsetrue );
?>


Dave 08-20-2019 05:30 PM

If you use var_dump to dump all the variables to the screen, it might show any errors that indicate why it's not working properly.

doc55 08-20-2019 07:00 PM

Quote:

Originally Posted by Dave (Post 2600285)
If you use var_dump to dump all the variables to the screen, it might show any errors that indicate why it's not working properly.

Thank you for your reply. Here is the result for var_dump($data);

PHP Code:

array(9) { ["userid"]=> int(0) ["password"]=> string(9"123456789" ["user"]=> array(2) { ["username"]=> string(7"john123" ["email"]=> string(17"john123@gmail.com" } [0]=> array(0) { } [1]=> array(0) { } ["userfield"]=> bool(false) [2]=> array(0) { } [3]=> string(0"" [4]=> array(1) { ["registration"]=> bool(true) } } string(16

Result of var_dump($response):
PHP Code:

array(2) { ["errors"]=> array(1) { [0]=> array(3) { [0]=> string(38"signing_up_but_currently_logged_in_msg" [1]=> string(16"superadmin" [2]=> string(108"https://mydomain.com/forum/auth/logout?logouthash=1566335006-fc429d00acee1ceab1c9ec1ee196d4569ce5f175" } } ["userid"]=> string(1"1" 


It looks like it is giving an error about the admin being signed in. Not sure how to fix this.
Any thoughts?

Dave 08-20-2019 07:18 PM

Digging into the code, a $canadminusers variable is checked to bypass most of the registration checks. More specifically, this variable holds the return value of the permission check of "canadminusers". So the admin account you're logging in as does not have a true value for the "canadminusers" permission. You should set this to true in the admincp under > Usergroups > Administrator Permissions > Edit Permissions of the admin account > set Can Administer Users to Yes.

doc55 08-20-2019 07:33 PM

Quote:

Originally Posted by Dave (Post 2600287)
Digging into the code, a $canadminusers variable is checked to bypass most of the registration checks. More specifically, this variable holds the return value of the permission check of "canadminusers". So the admin account you're logging in as does not have a true value for the "canadminusers" permission. You should set this to true in the admincp under > Usergroups > Administrator Permissions > Edit Permissions of the admin account > set Can Administer Users to Yes.

Thanks again for your follow up.
I just checked the admincp administration setting for that user and also for the usergroup (administrators) and everything is set to yes.
Specifically the Can Administer Users is already YES.
I actually did set it to No and tested the form and I got the same error message. I set it back to YES again.

Anywhere else that you could think of?

Dave 08-20-2019 07:54 PM

No, based on the code that's the only reason why it could show that error. (canadminusers permission of the user "superadmin" not set to true)

doc55 08-20-2019 07:56 PM

Quote:

Originally Posted by Dave (Post 2600289)
No, based on the code that's the only reason why it could show that error. (canadminusers permission of the user "superadmin" not set to true)

But the error message is actually reading "signing_up_but_currently_logged_in_msg".
I'm not sure where you are seeing the canadminusers error message?

Dave 08-20-2019 07:59 PM

Quote:

Originally Posted by doc55 (Post 2600290)
But the error message is actually reading "signing_up_but_currently_logged_in_msg".
I'm not sure where you are seeing the canadminusers error message?

Check the file /core/vb/api/user.php line 1999, 2069 and 2083 and you'll see what I'm talking about.

There is a check for $canadminusers that allows you to bypass several registration checks. However if $canadminusers is false then it will throw an exception "signing_up_but_currently_logged_in_msg" if the user is already logged in but does not have the canadminusers permission. It's the only line of code in the entire file that throws that specific exception.


All times are GMT. The time now is 07:43 AM.

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.01166 seconds
  • Memory Usage 1,782KB
  • 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
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete