vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=327493

Custom Profile Update
by doc55
29 Aug 2019 01:43

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.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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 02 Sep 2019 03:40

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

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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 02 Sep 2019 12:10

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 02 Sep 2019 15:04

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 02 Sep 2019 16:37

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 03 Sep 2019 22:14

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?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I appreciate any feedback.

Dave 03 Sep 2019 22:36

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 03 Sep 2019 23:53

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:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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 04 Sep 2019 00:13

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

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


doc55 04 Sep 2019 00:32

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?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Dave 04 Sep 2019 00:44

It's not needed as far as I can see. Now regarding the username... I'm not entirely sure but it seems that the username is not updated by making use of the save method in the user API. Not sure at the moment how that can be done.

doc55 04 Sep 2019 01:52

Interesting. After you said that, I went back and looked at the default profile edit page. It looks like vB does not give the option to users to change their username either. So, probably that's why we can't use this api to change the user's name. I guess I need to follow the same process and not allow users change their usernames.

So in that case and for my knowledge, why do we need the following line in the save user api?

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Do we really need it? or can I change it to

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

--------------- Added 04 Sep 2019 at 03:07 ---------------

OK, now I think I'm losing my mind. This is crazy. When I tested the script I posted here 10 minutes ago, it was working by updating the user's email and password, and when I was entering a wrong password, it was giving me the error message "badpassword".
Now I went back to test again (without changing anything in the code) and I'm getting the error message "enter_current_password" error message, even when I enter correct current password or wrong currect password and nothing is updating.
How in the world is this possible that I'm getting a different response?

doc55 05 Sep 2019 02:20

Finally, I was able to put everything together and make this thing work. Thank you both for all your help.
Now. I have one issue/question.
The following line is updating the username:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The only issue is that it doesn't check if the username is already in use or not and it allows duplicate usernames. So I need to first check the user table in the database and throw an error if username is duplicate.

Is there any instruction on how to search the vB database to search for data? Can you help?

delicjous 05 Sep 2019 08:19

You should not use "vB::getDbAssertor()->update" because this is a direct database action. There are api-functions for that.

doc55 05 Sep 2019 10:43

Quote:

Originally Posted by delicjous (Post 2600541)
You should not use "vB::getDbAssertor()->update" because this is a direct database action. There are api-functions for that.

Thank you for your reply.
I managed to figure out how to search the database to prevent duplicate username entry by using vB::getDbAssertor()->getRow.

What is the API that I could use instead of vB::getDbAssertor()->update which will be more secure? Can you please advise?

Is it ok to use vB::getDbAssertor()->getRow in an if statement to search for the data?

Thank you again.


All times are GMT. The time now is 09:21.

Powered by vBulletin® Version 3.8.14
Copyright © 2020, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.