tozaz2 Posted July 7, 2016 Share Posted July 7, 2016 Hi, I need to create a random username when create module function is called. I use this module server https://github.com/secondimpression/whmcs-freeradius So I created a hooks.php file in modules/servers/freeradius with the as content below require_once('/home/www/whmcs/init.php'); use Illuminate\Database\Capsule\Manager as Capsule; add_hook('PreModuleCreate', 1, function ($vars) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $username .= $characters[rand(0, $charactersLength - 1)]; for ($i = 0; $i < 10; $i++) { $username .= $characters[rand(0, $charactersLength - 1)]; } $serviceid = $vars['serviceid']; Capsule::table('tblhosting') ->where('id', '$serviceid') ->update( [ 'username' => '$username', ] ); }); My issue is username is still the emailadress and not the random username i set in my hook. The freeradius module is working well, my only issue is the hook. Thanks to help. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted July 12, 2016 Share Posted July 12, 2016 For starters, you shouldn't need the require line. Hook files in module directories should autmatically be included. Unless that's just addon modules, but I've never actually had to use that line. They just work. This may very well be causing the problem while not familiar directly with the specific hook, that code looks solid enough to work. What I'd do at this point is hook in something like chromephp or even use logactivity to verify your hook is being called, and go from there 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted July 13, 2016 Share Posted July 13, 2016 there is already ActionHook point for this specific need, try the following code instead of yours <?php add_hook('OverrideModuleUsernameGeneration', 1, function($vars) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $username = ""; for ($i = 0; $i < 10; $i++) { $username .= $characters[rand(0, $charactersLength - 1)]; } return $username; }); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.