-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaddUserAdmin.php
64 lines (51 loc) · 1.63 KB
/
addUserAdmin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @Author: nguyen
* @Date: 2020-12-29 11:18:57
* @Last Modified by: nguyen
* @Last Modified time: 2020-12-29 13:11:30
*/
//// Setup Base
$folder = ''; //Folder Name
$file = $folder ? "$folder/app/bootstrap.php" : "app/bootstrap.php";
if(!file_exists ($file)) $file = "app/bootstrap.php";
if(file_exists ($file)){
require dirname(__FILE__) .'/' .$file;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
} else {die('Not found bootstrap.php');}
/* For get RoleType and UserType for create Role */;
class createAdmin extends \Magento\Framework\App\Http
implements \Magento\Framework\AppInterface {
/**
* User model factory
*
* @var \Magento\User\Model\UserFactory
*/
protected $_userFactory;
public function launch()
{
$this->_userFactory = $this->_objectManager->get('\Magento\User\Model\UserFactory');
$adminInfo = [
'username' => 'hello',
'firstname' => 'Hello',
'lastname' => 'Mage',
'email' => 'hello@magepow.com',
'password' =>'hello@123',
'interface_locale' => 'en_US',
'is_active' => 1
];
$userModel = $this->_userFactory->create();
$userModel->setData($adminInfo);
$userModel->setRoleId(1);
try{
$userModel->save();
echo 'done';
} catch (\Exception $ex) {
$ex->getMessage();
}
return $this->_response;
}
}
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('createAdmin');
$bootstrap->run($app);