Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2019, 04:41 PM
doc55 doc55 is offline
 
Join Date: Aug 2019
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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()); 
Reply With Quote
  #2  
Old 08-19-2019, 09:37 AM
delicjous's Avatar
delicjous delicjous is offline
 
Join Date: Nov 2014
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not that easy!

Perhaps you need humanverification .... Look whats your $userId return.
Reply With Quote
  #3  
Old 08-20-2019, 04:48 PM
doc55 doc55 is offline
 
Join Date: Aug 2019
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 );
?>
Reply With Quote
  #4  
Old 08-20-2019, 05:30 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 08-20-2019, 07:00 PM
doc55 doc55 is offline
 
Join Date: Aug 2019
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
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?
Reply With Quote
  #6  
Old 08-20-2019, 07:18 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 08-20-2019, 07:33 PM
doc55 doc55 is offline
 
Join Date: Aug 2019
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
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?
Reply With Quote
  #8  
Old 08-20-2019, 07:54 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #9  
Old 08-20-2019, 07:56 PM
doc55 doc55 is offline
 
Join Date: Aug 2019
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
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?
Reply With Quote
  #10  
Old 08-20-2019, 07:59 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by doc55 View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:22 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07633 seconds
  • Memory Usage 2,293KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete