vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB5 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=263)
-   -   Custom Profile Update (https://vborg.vbsupport.ru/showthread.php?t=327493)

doc55 08-28-2019 11:43 PM

Custom Profile Update
 
Hi,
I'm trying to make a custom form for users to update their profile. I have the following code, which I thought it should work.
PHP Code:

//init the vBulletin system
require_once( '/forum/includes/vb5/autoloader.php' );
vB5_Autoloader::register'/forum' );
vB5_Frontend_Application::init'config.php' );

// Get logged in user ID
$vb_userid=vB::getUserContext()->fetchUserId();

//get user info
$username $this->data['username'];
$email $this->data['email'];
$password $this->data['new_password'];
$data = array(
  
'userid' => $vb_userid,
  
'password' => $password,
  
'user' => array( 'username' => $username'email' => $email ),
  array(),
  array(),
  
'userfield' => false,
  array(),
  
'',
  array()
);
$response $api->callApi'user''save'$datafalsetrue); 

But I'm getting the following error message:
Your submission could not be processed because a security token was missing.
If this occurred unexpectedly, please inform the administrator and describe the action you performed before you received this error.


And I see the following error at the top of the page:
Notice: Undefined index: usefiles in /home/myserver/mysite.com/forum/includes/vb5/template/stylesheet.php on line 70 Notice: Undefined index: usefiles in /home/myserver/mysite.com/forum/includes/vb5/template/stylesheet.php on line 70

I appreciate if someone could help me with fixing this code.
Thanks

doc55 09-02-2019 01:40 AM

I made some progress, but the code is still not working correctly.
Here is what I have:
PHP Code:

// Check vBulletin user ID to make sure they are logged in and it exists. 
$user_id = isset( $_COOKIE'bbuserid' ] ) ? ( int )$_COOKIE'bbuserid' ] : null;
if ( 
$user_id === null ) {
  throw new 
Exception'Unable to find user id from vBulletin.' );
}

//init the vBulletin system
require_once( '/forum/core/vb/vb.php' );
vB::init();
define"CSRF_PROTECTION"false );
require_once( 
'/forum/includes/vb5/autoloader.php' );
vB5_Autoloader::register'/forum' );
vB5_Frontend_Application::init'config.php' );

//get user info
$current_password $_POST'form' ][ 'current_password' ];
$new_password $_POST'form' ][ 'new_password' ];
$email $_POST'form' ][ 'email' ];
$username $_POST'form' ][ 'username' ];

//Update user information
$api Api_InterfaceAbstract::instance();
$response $api->callApi'user''save', array(
  
'userid' => $user_id,
  
'password' => '',
  
'user' => array( 'email' => $email'username' => $username ),
  
'options' => array(),
  
'adminoptions' => array(),
  
'userfield' => array(),
  
'notificationOptions' => array(),
  
'hvinput' => array(),
  
'extra' => array(
    
'password' => $current_password,
    
'newpass' => $new_password,
    
'email' => $email
    
'username' => $username
  
),
) );
vB::getDbAssertor()->update'user', array( 'username' => $username ), array( "userid" => $user_id ) ); 

Couple issues with this code are:
1- It is not updating the email address
2- You can enter wrong current password and it still runs without throwing an error.
3- Can I update the user email, password and username without the need to enter the current user?

I appreciate anyone that could help with this.

Dave 09-02-2019 10:10 AM

You must pass 'acnt_settings' => true to the 'extra' array. Based on the code that allows you to edit the email/password as a regular user and also includes current password verification.

You need to extract the userid from the current session returned by vBulletin and not from a cookie because I can just simply use a cookie editor to edit my bbuserid cookie to the userid of an administrator and then hijack the account.

In Omnibus 09-02-2019 01:04 PM

Quote:

Originally Posted by Dave (Post 2600488)
You must pass 'acnt_settings' => true to the 'extra' array. Based on the code that allows you to edit the email/password as a regular user and also includes current password verification.

You need to extract the userid from the current session returned by vBulletin and not from a cookie because I can just simply use a cookie editor to edit my bbuserid cookie to the userid of an administrator and then hijack the account.

I'd like and quote this a million times if I could. There seems to be a growing trend of vBulletin customers hacking their software without any regard for security.

doc55 09-02-2019 02:37 PM

Thank you both for your valuable feedback. I'm not a programmer and I had someone do this for me. That's why I shared it here to make sure we are doing things correctly and improve it.

I really appreciate your advice.

doc55 09-03-2019 08:14 PM

After reading the vB API documentation, it looks like the acnt_setting should be set to 1.
So, I changed the code as you advised and I'm getting the userid from vB fetchUserinfo instead of cookies.

However, my code still not working. It is not updating the username. Also it is not verifying the current password.
What am I missing?

PHP Code:

//init the vBulletin system
require_once( '/forum/core/vb/vb.php' );
vB::init();
define"CSRF_PROTECTION"false );
require_once( 
'/forum/includes/vb5/autoloader.php' );
vB5_Autoloader::register'/forum' );
vB5_Frontend_Application::init'config.php' );
$vb_userInfo vB_Api::instance'user' )->fetchUserinfo();

//get user info
$vb_userid $vb_userInfo'userid' ];
$current_password $_POST'form' ][ 'current_password' ];
$new_password $_POST'form' ][ 'new_password' ];
$email $_POST'form' ][ 'email' ];
$username $_POST'form' ][ 'username' ];

//Update user information
$api Api_InterfaceAbstract::instance();
$response $api->callApi'user''save', array(
  
'userid' => $vb_userid,
  
'password' => '',
  
'user' => array( 'email' => $email'username' => $username ),
  
'options' => array(),
  
'adminoptions' => array(),
  
'userfield' => array(),
  
'notificationOptions' => array(),
  
'hvinput' => array(),
  
'extra' => array(
    
'password' => $current_password,
    
'newpass' => $new_password,
    
'email' => $email
    
'username' => $username,
    
'acnt_setting' => 1
  
),
) );
vB::getDbAssertor()->update'user', array( 'username' => $username ), array( "userid" => $vb_userid ) ); 

I appreciate any feedback.

Dave 09-03-2019 08:36 PM

var_dump($response); to see what that is showing. If nothing happens, dump the variables one by one to make sure everything is still working as expected.

doc55 09-03-2019 09:53 PM

Thank you Dave.
It appeared that actually my code worked (partially).
When I enter the wrong current password, it doesn't update anything, appropriately. But It is not showing any errors to the user.
the var_dump($response); showed the following:
PHP Code:

array(2) { ["errors"]=> array(1) { [0]=> array(2) { [0]=> string(11"badpassword" [1]=> string(40"https://mydomain.com/forum/lostpw" } } ["userid"]=> string(2"19" 

I know this is the error message, but I'm not sure how can I write the if statement that if there is an error, then show a message. Meaning, how can I capture this error in the php script?

The other problem is that even when I enter the correct current password, it only updates the email and password and DOES NOT update the username. I'm not sure why.

Dave 09-03-2019 10:13 PM

Does the new password save properly? You might have to set the 'password' key to the new password in the array.

As for showing errors, just iterate over the errors array if it's set.
Something like
PHP Code:

if(isset($response['errors'])){
   foreach(
$response['errors'] as $key=>$error){
      echo 
$error[0] . '<br>';
   }



doc55 09-03-2019 10:32 PM

Dave,
Thanks again for your reply.
That took care of the error message. Great.
The password is updating appropriately.
However, the username is still not saving at all. Any idea why?
Also, I noticed just now that the last line is actually not needed. I ran the code without the vB::getDbAssertor and it is working exactly the same. Do you know if I need this line?

PHP Code:

vB::getDbAssertor()->update'user', array( 'username' => $username ), array( "userid" => $vb_userid ) ); 



All times are GMT. The time now is 04:01 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.01199 seconds
  • Memory Usage 1,791KB
  • 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
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)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