Remove username field from basic registration and post username from a plugin
Hello everyone !
I am currently working on a Minecraft forum and I got an issue while editing the registration page.
I would like to remove the username field from registerbasic.php in order to send the username from a plugin.
How could I do this please ?
Emilien
Best Answer
-
R_J Admin
I think you should really clean up the code. I have made some small changes, so that it is no longer called like another plugin, but syntax is still not Vanilla conform:
<?php if (!defined('APPLICATION')) exit(); $PluginInfo['MinecraftPremiumRegisterVerify'] = array( 'Name' => 'Minecraft Premium Register verify', 'Description' => 'Verify if user register has a premium Minecraft account.', 'Version' => '0.1', 'Author' => "unixfox", 'MobileFriendly' => TRUE, 'SettingsUrl' => '/dashboard/settings/minecraftpremiumregisterverify', ); class MinecraftPremiumRegisterVerifyQuestion extends Gdn_Plugin { public function EntryController_RegisterFormBeforeTerms_Handler($Sender) { $this->h1ValidateAccount($Sender); $this->ChoiceValidation($Sender); $this->LoginMinecraft($Sender); $this->ValidateServer($Sender); } public function EntryController_RegisterBeforeTerms_Handler($Sender) { $this->h1ValidateAccount($Sender); $this->ChoiceValidation($Sender); $this->LoginMinecraft($Sender); $this->ValidateServer($Sender); } public function h1ValidateAccount($Sender) { echo "<h1>Validate your account</h1>"; echo "<hr>"; } public function ChoiceValidation($Sender) { $Sender->ChoiceValidate = array( 'l' => T('Login with your Minecraft account.'), 'c' => T('Connect on a server to verify your account.'), ); echo "<li>"; echo $Sender->Form->Label('Validate on'); echo $Sender->Form->RadioList('ChoiceValidate', $Sender->ChoiceValidate, array('default' => 'l')); echo "</li>"; } public function LoginMinecraft($Sender) { echo "<li>"; echo $Sender->Form->Label('Email login Minecraft'); echo $Sender->Form->TextBox('McEmail'); echo "</li>"; echo "<li>"; echo $Sender->Form->Label('Minecraft Password'); echo $Sender->Form->Input('McPassword', 'password'); echo "</li>"; } public function ValidateServer($Sender) { echo '<li>'; echo $Sender->Form->Label('Enter your secret code'); echo $Sender->Form->TextBox('SecretCode'); echo '</li>'; } public function EntryController_Register_Handler($Sender) { $this->_AddResources($Sender); } public function EntryController_RegisterValidation_Handler($Sender) { include("MCAuth.class.php"); $FormValues = $Sender->Form->FormValues(); $UserCode = $FormValues['SecretCode']; $DefaultSecretCode = 'Abc123'; $SecretCode = (C('MinecraftPremiumRegisterVerify.SecretCode', $DefaultSecretCode)); $MCAuth = new MCAuth(); if ($MCAuth->authenticate($FormValues['McEmail'], $FormValues['McPassword']) == FALSE) { $Sender->Form->AddError('Incorrect authenfication Minecraft account.'); } else { if ($MCAuth->account['username'] != $FormValues['Name']) { $Sender->Form->AddError('Your Username is different as your Minecraft account.'); } } if (strtolower($UserCode) != strtolower($SecretCode)) { $Sender->Form->AddError('Please enter Correct Code.'); $Sender->Render(); exit(); // I guess that is not needed } } public function SettingsController_MinecraftPremiumRegisterVerify_Create($Sender) { $Sender->Permission('Garden.Settings.Manage'); $Sender->Form = new Gdn_Form(); $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array( 'MinecraftPremiumRegisterVerify.SecretCode', 'MinecraftPremiumRegisterVerify.Label' )); $Sender->Form->SetModel($ConfigurationModel); $Sender->Title('Minecraft Premium Register Verify Plugin Settings'); $Sender->AddSideMenu('settings/MinecraftPremiumRegisterVerify'); if ($Sender->Form->AuthenticatedPostBack() === FALSE) { $Sender->Form->SetData($ConfigurationModel->Data); } else { $Data = $Sender->Form->FormValues(); if ($Sender->Form->Save() !== FALSE) { $Sender->StatusMessage = T('Your settings have been saved.'); } } $Sender->Render($this->GetView('arq-settings.php')); } public function Setup() { SaveToConfig('MinecraftPremiumRegisterVerify.SecretCode', 'WhereIsPeregrine?'); SaveToConfig('MinecraftPremiumRegisterVerify.Label', 'Enter Your code'); } private function _AddResources($Sender) { $Sender->AddJsFile($this->GetResource('js/switch.js', FALSE, FALSE)); } }
Based from what I see, you do not allow the user to specify a Vanilla user name and you do not set it for him. So that's why he (correctly) is told that there is no user name.
Look at that:
if ($MCAuth->authenticate($FormValues['McEmail'], $FormValues['McPassword']) == FALSE) { $Sender->Form->AddError('Incorrect authenfication Minecraft account.'); } else { if ($MCAuth->account['username'] != $FormValues['Name']) { $Sender->Form->AddError('Your Username is different as your Minecraft account.'); } }
If the user is not allowed to specify a name it is unfair to tell him that his username is different from his Minecraft user name
You
have to set the username to the Minecraft user. Something like that
$Sender->Form->Username = $MCAuth->account['username'] ;` (not sure about the way to reference the username) instead of comparing the empty formvalue username with the account name5
Answers
Just a little correction of my question :
Anyone has a solution ? I found JsConnect but it's stupid to use this if there are easier.
It was not very clear to me what you are trying to achieve, since you mentioned jsConnect.
Maybe you have to elaborate some more on this. Are you looking for a single sign on solution?
Do you already have a user base?
Do they come from any known software? Maybe someone has connected them before.
In my registration page, I'd like to remove the username field. Instead, I'd send the username information using a plugin.
In this page, the username field is removed. However, if I sign up, there is an error : "Name is required" so I want to send an username value to the form using a plugin, in this case from this API : https://github.com/mattiabasone/MCAuth. The value is from
$MCAuth->account['username']
.There is my plugin : http://pastebin.com/yMh4gNEp.
PS : Sorry for my bad english, I am French.
It would be easier to read if you clean up the code from peregrines AddRegistrationQuestion plugin first!
Without looking deeper into the code and just judging from the description: could that be of any use for you? http://vanillaforums.org/addon/verifymcuser-plugin
I use this plugin (http://vanillaforums.org/addon/verifymcuser-plugin) but I would like that the user can not specify the username but his username is defined by a plugin.
The username value is sent to the registration form via a plugin.
There is the clean code : http://pastebin.com/yMh4gNEp.
I think you should really clean up the code. I have made some small changes, so that it is no longer called like another plugin, but syntax is still not Vanilla conform:
Based from what I see, you do not allow the user to specify a Vanilla user name and you do not set it for him. So that's why he (correctly) is told that there is no user name.
Look at that:
If the user is not allowed to specify a name it is unfair to tell him that his username is different from his Minecraft user name
You
have to set the username to the Minecraft user. Something like that
$Sender->Form->Username = $MCAuth->account['username'] ;` (not sure about the way to reference the username) instead of comparing the empty formvalue username with the account name@R_J
Thank you, thank you very much! I'll try that.
This is a terrible idea from a design perspective. You are asking a user to give you their minecraft.net account information to register on your site. What is stopping you from immediately hijacking someone's account?
You should create a plugin like the facebook or google plugins that wraps the mojang api (details here: http://wiki.vg/Authentication). Then a user connects their account to your system and you only store a foreign key. The user never gives you their credentials and you are assured that they are who they say the are.
This is actually a really good idea for a plugin.
EDIT - I just noticed that their API still requires you to supply the password. WTH Mojang?!?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@R_J
$Sender->Form->Username = $MCAuth->account['username']
is to set username field but I would like to send username field and not set it.User can also connect to a server Minecraft to receive a secret code to validate is account. Don't worry the community is based on oc.tc but for French players and the forum will be represented by a member of staff oc.tc.
I do not store the IDs of Minecraft account, they are only useful for validation.
I did not mean to imply you would. I only mean that it would be trivial to do so.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.