Advertisement
unixfox

Untitled

May 12th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.08 KB | None | 0 0
  1. <?php if (!defined('APPLICATION')) exit();
  2.  
  3. $PluginInfo['AddRegistrationQuestion'] = array(
  4.     'Name' => 'Minecraft Premium Register verify',
  5.     'Description' => 'Verify if user register has a premium Minecraft account.',
  6.     'Version' => '0.1',
  7.     'Author' => "unixfox",
  8.     'MobileFriendly' => TRUE,
  9.     'SettingsUrl' => '/dashboard/settings/addregistrationquestion',
  10. );
  11.  
  12. class AddRegistrationQuestion extends Gdn_Plugin {
  13.  
  14.     public function EntryController_RegisterFormBeforeTerms_Handler($Sender) {
  15.         $this->h1ValidateAccount($Sender);
  16.         $this->ChoiceValidation($Sender);
  17.         $this->LoginMinecraft($Sender);
  18.         $this->ValidateServer($Sender);
  19.     }
  20.  
  21.     public function EntryController_RegisterBeforeTerms_Handler($Sender) {
  22.         $this->h1ValidateAccount($Sender);
  23.         $this->ChoiceValidation($Sender);
  24.         $this->LoginMinecraft($Sender);
  25.         $this->ValidateServer($Sender);
  26.     }
  27.  
  28.     public function h1ValidateAccount($Sender)
  29.     {
  30.         echo "<h1>Validate your account</h1>";
  31.         echo "<hr>";
  32.     }
  33.  
  34.     public function ChoiceValidation($Sender)
  35.     {
  36.         $Sender->ChoiceValidate = array(
  37.             'l' => T('Login with your Minecraft account.'),
  38.             'c' => T('Connect on a server to verify your account.'),
  39.         );
  40.         echo "<li>";
  41.         echo $Sender->Form->Label('Validate on');
  42.         echo $Sender->Form->RadioList('ChoiceValidate', $Sender->ChoiceValidate, array('default' => 'l'));
  43.         echo "</li>";
  44.     }
  45.  
  46.     public function LoginMinecraft($Sender)
  47.     {
  48.         echo "<li>";
  49.         echo $Sender->Form->Label('Email login Minecraft');
  50.         echo $Sender->Form->TextBox('McEmail');
  51.         echo "</li>";
  52.  
  53.         echo "<li>";
  54.         echo $Sender->Form->Label('Minecraft Password');
  55.         echo $Sender->Form->Input('McPassword', 'password');
  56.         echo "</li>";
  57.  
  58.     }
  59.  
  60.     public function ValidateServer($Sender)
  61.     {
  62.         echo '<li>';
  63.         echo $Sender->Form->Label('Enter your secret code');
  64.         echo $Sender->Form->TextBox('SecretCode');
  65.         echo '</li>';
  66.     }
  67.  
  68.     public function AddQuestion($Sender) {
  69.         echo '<li>';
  70.         echo $Sender->Form->Label(C('Plugins.AddRegistrationQuestion.Label','Enter your secret code'), 'SecretCode');
  71.         echo $Sender->Form->TextBox('SecretCode');
  72.         echo '</li>';
  73.         if ($correctanswer == 'N') {
  74.             $Sender->Validation->AddValidationResult('Secretcode', T('Please re-read all questions again and answer again'));
  75.             $Sender->EventArguments['Valid'] = FALSE;
  76.         }
  77.     }
  78.  
  79.     public function EntryController_Register_Handler($Sender) {
  80.       $this->_AddResources($Sender);
  81.     }
  82.     public function EntryController_RegisterValidation_Handler($Sender) {
  83.         include("MCAuth.class.php");
  84.         $FormValues = $Sender->Form->FormValues();
  85.         $UserCode = $FormValues['SecretCode'];
  86.         $DefaultSecretCode = 'Abc123';
  87.         $SecretCode = (C('Plugins.AddRegistrationQuestion.SecretCode', $DefaultSecretCode));
  88.         $MCAuth = new MCAuth();
  89.         if ($MCAuth->authenticate($FormValues['McEmail'], $FormValues['McPassword']) == FALSE)
  90.         {
  91.             $Sender->Form->AddError('Incorrect authenfication Minecraft account.');
  92.         }
  93.         else
  94.         {
  95.             if ($MCAuth->account['username'] != $FormValues['Name'])
  96.             {
  97.                 $Sender->Form->AddError('Your Username is different as your Minecraft account.');
  98.             }
  99.         }
  100.         if (strtolower($UserCode) != strtolower($SecretCode)) {
  101.             $Sender->Form->AddError('Please enter Correct Code.');
  102.             $Sender->Render();
  103.             exit();
  104.         }
  105.     }
  106.     public function SettingsController_AddRegistrationQuestion_Create($Sender) {
  107.         $Sender->Permission('Garden.Settings.Manage');
  108.         $Sender->Form = new Gdn_Form();
  109.         $Validation = new Gdn_Validation();
  110.         $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
  111.         $ConfigurationModel->SetField(array(
  112.             'Plugins.AddRegistrationQuestion.SecretCode',
  113.             'Plugins.AddRegistrationQuestion.Label'
  114.         ));
  115.         $Sender->Form->SetModel($ConfigurationModel);
  116.         $Sender->Title('Add Registration Question Plugin Settings');
  117.         $Sender->AddSideMenu('settings/AddRegistrationQuestion');
  118.         if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
  119.             $Sender->Form->SetData($ConfigurationModel->Data);
  120.         } else {
  121.             $Data = $Sender->Form->FormValues();
  122.             if ($Sender->Form->Save() !== FALSE) {
  123.                 $Sender->StatusMessage = T('Your settings have been saved.');
  124.             }
  125.         }
  126.         $Sender->Render($this->GetView('arq-settings.php'));
  127.     }
  128.     public function Setup() {
  129.         SaveToConfig('Plugins.AddRegistrationQuestion.SecretCode', 'PeregrineWasHere123');
  130.         SaveToConfig('Plugins.AddRegistrationQuestion.Label', 'Enter Your code');
  131.     }
  132.     private function _AddResources($Sender) {
  133.         $Sender->AddJsFile($this->GetResource('js/switch.js', FALSE, FALSE));
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement