Skip to Content Skip to Menu

Need advice please.

  • zederis
  • zederis
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 1
6 months 2 weeks ago - 6 months 2 weeks ago #338038 by zederis
Need advice please. was created by zederis
I have game server tables in the same database as joomla tables. I am using joomla user credentials to login ingame, but for that I have to sync joomla username and password to game tables anytime joomla user updates their credentials. I also must encrypt the password using sha1 before storing it. I am using auto actions plugin for that. onNewPassword to update password when user goes Forgot login. onAfterUserUpdate when user changes their password in profile settings. onFirstLogin to store user credentials for the first time. Using auto actions to run queries sounds nice, but then I don’t know how to encrypt the password before storing it. To run php code, I am not sure how to use joomla database inside auto actions plugin. I don’t want to create a new database connection using hostname, database, username and password. I want to use existing joomla DB connection. Please advice 🙂
Last edit: 6 months 2 weeks ago by zederis.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
6 months 2 weeks ago #338046 by krileon
Replied by krileon on topic Need advice please.
You can use Joomla's API directly in your Code action PHP. You don't need to manually establish database connections to Joomla. You can also use CBs API as well. Below is an example of running a query with CBs API.
Code:
global $_CB_database; $password = sha1( '[password]' ); $query = "UPDATE " . $_CB_database->NameQuote( '#__mytable' ) . " SET " . $_CB_database->NameQuote( 'password' ) . " = " . $_CB_database->Quote( $password ) . " WHERE " . $_CB_database->NameQuote( 'user' ) . " = " . $user->getInt( 'id', 0 ); try { $_CB_database->setQuery( $query ); $_CB_database->query(); } catch ( RuntimeException $e ) { // Error Handling Here }

That's all there is to it. Your query will run using Joomla database connection as our API just calls Joomla's own API. If using Joomla API keep in mind this is inline PHP you can't specify "use" statements (unless you opt to just include a php file) so you need to use the full PHP namespace path.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum