- Posts: 72
- Thank you received: 0
Database validation on user registration
11 years 5 months ago #198651
by mymall
Database validation on user registration was created by mymall
-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5.12
Dear Sir
I have a requirement that I need to add a custom filed for user table called phone number, now I need to validate this filed to be unique in database, its the same way it validate the email address and user id
can you point me to the right place to add such validation
thanks
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5.12
Dear Sir
I have a requirement that I need to add a custom filed for user table called phone number, now I need to validate this filed to be unique in database, its the same way it validate the email address and user id
can you point me to the right place to add such validation
thanks
Please Log in or Create an account to join the conversation.
11 years 5 months ago #198692
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Replied by Jerome on topic Database validation on user registration
Hi,
I will recommend you to use a little custom plugin with the trigger "onBeforeUserCreate" where you will have access to the user custom fields and where you will be able to check and validate the content :
www.hikashop.com/support/support/documen...umentation.html#user
You can also use the trigger "onBeforeUserUpdate" for cases where the user want to update his account (and change his phone number).
Regards,
I will recommend you to use a little custom plugin with the trigger "onBeforeUserCreate" where you will have access to the user custom fields and where you will be able to check and validate the content :
www.hikashop.com/support/support/documen...umentation.html#user
You can also use the trigger "onBeforeUserUpdate" for cases where the user want to update his account (and change his phone number).
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206479
by mymall
Replied by mymall on topic Database validation on user registration
Dear SIr
I tried to implement the plugin onBeforeUserCreate and it work, however (hikashop gives error that the mobile already exist) and the user is not created in hikashop_user table, however, joomla created the user in users table
Please advice how I can prevent joomla from creating the user
thanks
I tried to implement the plugin onBeforeUserCreate and it work, however (hikashop gives error that the mobile already exist) and the user is not created in hikashop_user table, however, joomla created the user in users table
Please advice how I can prevent joomla from creating the user
thanks
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206573
by nicolas
Replied by nicolas on topic Database validation on user registration
Hi,
You'll want to implement the onUserBeforeSave trigger (it's a Joomla trigger) in a Joomla user plugin and refuse the Joomla user account account creation by checking with the data in the $_POST.
You'll want to implement the onUserBeforeSave trigger (it's a Joomla trigger) in a Joomla user plugin and refuse the Joomla user account account creation by checking with the data in the $_POST.
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206651
by mymall
Replied by mymall on topic Database validation on user registration
thanks
am not php expert however, I can mange to write some basic codes, here what I did to stop hikashop from creating the user,
function onBeforeUserCreate(&$element,&$do) {
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = "SELECT `user_telephone` FROM `#__hikashop_user` WHERE `user_telephone` = '" . $element->user_telephone . "'";
$db->setQuery($query);
$user_telephone = $db->loadResult('user_telephone');
if ($user_telephone == $element->user_telephone ) {
$app->enqueueMessage(JText::_('USER_TELEPHONE_ALREADY_USED'));
$do = false;
return false;
}
}
Please advice where I need to add onUserBeforeSave
thanks
am not php expert however, I can mange to write some basic codes, here what I did to stop hikashop from creating the user,
function onBeforeUserCreate(&$element,&$do) {
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = "SELECT `user_telephone` FROM `#__hikashop_user` WHERE `user_telephone` = '" . $element->user_telephone . "'";
$db->setQuery($query);
$user_telephone = $db->loadResult('user_telephone');
if ($user_telephone == $element->user_telephone ) {
$app->enqueueMessage(JText::_('USER_TELEPHONE_ALREADY_USED'));
$do = false;
return false;
}
}
Please advice where I need to add onUserBeforeSave
thanks
Please Log in or Create an account to join the conversation.
11 years 3 months ago #206655
by nicolas
Replied by nicolas on topic Database validation on user registration
Hi,
As I said, you need to check the data in the POST.
$element contains the data that will be saved in the Joomla user table and thus doesn't contain the telephone of the user which is a HikaShop field.
So you need to look into $_POST (do a var_dump in the plugin) in order to get the exact variable name you can use to access the value entered by the customer.
Then, you can do your MySQL query for the check.
Also, the way you wrote your query, it is vulnerable to MySQL injections attacks. It should be written like that for security reasons:
$query = "SELECT `user_telephone` FROM `#__hikashop_user` WHERE `user_telephone` = " . $db->Quote($element->user_telephone);
As I said, you need to check the data in the POST.
$element contains the data that will be saved in the Joomla user table and thus doesn't contain the telephone of the user which is a HikaShop field.
So you need to look into $_POST (do a var_dump in the plugin) in order to get the exact variable name you can use to access the value entered by the customer.
Then, you can do your MySQL query for the check.
Also, the way you wrote your query, it is vulnerable to MySQL injections attacks. It should be written like that for security reasons:
$query = "SELECT `user_telephone` FROM `#__hikashop_user` WHERE `user_telephone` = " . $db->Quote($element->user_telephone);
Please Log in or Create an account to join the conversation.
Time to create page: 0.192 seconds