HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

cbunting99 starter kit ;)

R_JR_J Ex-FanboyMunich Admin

@cbunting99 said:
Haha.. Vanilla forums is just awesome.. I can't seem to stop trying things out!

I have a simple form on the website that takes a username and password and submits it one time to an MSSQL database. I am just trying to find a way to hide the form inside of the forums for players only.

I really want to replace our small site with running Vanilla

I actually have a register page and I am not sure how to write a plugin for what I need.
This is probably a crappy way of doing things, but it works until I can find a better solution.

I sense a new plugin developer has arrived... :D

Just to get you started, I thought I show you some plugin code that will add two textboxes (one for a player name and one for the password) to the profile page. You wanted to have something that is only reachable for logged in users? I think the profile is a neat place for that. You'll find 4 functions in that plugin:
1. Vanillas user table is extended by two fields so that a Vanilla user could be connected to your "old" user table
2. When a user edits his profile he can input the games credentials
3. When that form input shall be saved, we want to validate the input and give feedback if it wasn't successful
4. Just in case you want to display the player name in the profile, here is how to do that

That code isn't tested but when you are able to put some php code together in order to query a database, you'll be able to read and understand what you find below. Just save it as plugins/YourGameNameConnect/class.yourgamenameconnect.plugin.php and start developing Vanilla plugins!

(You'll have to quote this text in order to see the code below with all HTML tags included)

<?php if (!defined('APPLICATION')) exit();

$PluginInfo['YourGameNameConnect'] = array(
   'Name' => 'YourGameName Connect',
   'Description' => 'Connect account from somewhere other to Vanilla user',
   'Version' => '0.1',
   'Author' => 'Here could be your name!'

class YourGameNameConnectPlugin extends Gdn_Plugin {
   // this function will be executed whenever you enable your plugin
   public function Setup()    {
      // set additional fields in user table for your game login credentials
         ->Column('YourGameNamePlayerName', 'varchar(64)', TRUE)
         ->Column('YourGameNamePassword', 'varchar(64)', TRUE)
         ->Set(FALSE, FALSE);

   // this function is called whenever the user is editing his account
   public function ProfileController_EditMyAccountAfter_Handler($Sender) {
      // display extra input field for player name
      echo '<li>';
      echo $Sender->Form->Label(T('Your player name in my fabulous game'), 'YourGameNamePlayerName');
      echo $Sender->Form->TextBox('YourGameNamePlayerName', array('class' => 'InputBox SmallInput'));
      echo '</li>';
      // display extra input field for player password
      echo '<li>';
      echo $Sender->Form->Label(T('Your password in my fabulous game'), 'YourGameNamePassword');
      echo $Sender->Form->TextBox('YourGameNamePassword', array('class' => 'InputBox SmallInput', 'type' => 'password'));
      echo '</li>';

   // this will be called before the user profiel edits are saved
   public function UserModel_BeforeSaveValidation_Handler($Sender) {
      // we can access all form fields in the array $Sender->EventArguments['FormPostValues']
      $YourGameNamePlayerName = $Sender->EventArguments['FormPostValues']['YourGameNamePlayerName'];
      $YourGameNamePassword = $Sender->EventArguments['FormPostValues']['YourGameNamePassword'];

      // if user hasn't entered game related info, we do not have to do anything
      if ( $YourGameNamePlayerName == '' && $YourGameNamePassword == '') {

// here comes your part: check if $YourGameNamePlayerName and $YourGameNamePassword is a valid combination in your games database. Let's assume it was a wrong entry...

$CredentialsCheck = FALSE;

      // Check has been done and if it failed...
      if (!$CredentialsCheck) {
          // ... we will use Vanillas form validation and simply add a message that one validation has failed
          $Sender->Validation->AddValidationResult('YourGameNamePlayerName', T('YourGameName credentials couldn\'t be validated. Either user is unknown or password is false.'));

   // show extra info in profile (if wanted)
    public function ProfileController_AddProfileTabs_Handler($Sender) {
       $YourGameNamePlayerName = $Sender->User->YourGameNamePlayerName;
       if ($YourGameNamePlayerName != '') {
          $HtmlOut = '<div class="Box YourGameNamePlayerNameBox">';
          $HtmlOut .= '<h4>'.T('Your GameName Player CredentialsName').'</h4>';
          $HtmlOut .= '<li>'.T('YourGameNamePlayerName: ').Gdn_Format::Text($YourGameNamePlayerName).'</li>';
          $HtmlOut .= '</div>';

          $Sender->AddAsset('Panel', $HtmlOut, 'YourGameNamePlayerName');

By the way: I think that the above solution isn't the preferred Vanilla solution. There's jsConnect which is the weapon of choice when you are cross connecting databases.


  • Options
    cbunting99cbunting99 Texas New

    Thanks so much for the code.. I was able to integrate everything with the site.. So now we have the player registration, the one time in-game currency request all hidden behind Vanilla.. The stopforum spam plugin has already blocked a ton of bogus signups so everything is working as it should!.. I even managed to list live rankings of all 6 classes, listing the top 10 players for each class..

    I used to run Zendesk for support, Useresponse for feature requests, and the FluxBB.. But with the awesomeness of Vanilla, I can do it all just from the forums!..

Sign In or Register to comment.