I want to create an admin user programmatically , from the frontend controller my frontend code is:
<?php
namespace Learning\HelloPage\Controller\Account;
use Magento\Framework\App\Action\Context;
class Add extends \Magento\Backend\App\Action
{
protected $_userFactory;
public function __construct(
\Magento\User\Model\UserFactory $userFactory
)
{
$this->_userFactory = $userFactory;
}
public function execute(){
$adminInfo = [
'username' => 'killer',
'firstname' => 'admin',
'lastname' => 'admin',
'email' => '[email protected]',
'password' =>'hello@123',
'interface_locale' => 'en_US',
'is_active' => 1
];
$userModel = $this->_userFactory->create();
$userModel->setData($adminInfo);
$userModel->setRoleId(7);
try{
$userModel->save();
echo 'saved';
} catch (\Exception $ex) {
$ex->getMessage();
}
}
}
