forked from kpeiruza/docker-hashtopolis-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
adduser.php
38 lines (30 loc) · 1.28 KB
/
adduser.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
<?php
require_once(dirname(__FILE__) . "/../inc/conf.php");
use DBA\AccessGroupUser;
use DBA\Config;
use DBA\QueryFilter;
use DBA\RightGroup;
use DBA\User;
use DBA\Factory;
require_once(dirname(__FILE__) . "/../inc/load.php");
$username = "H8_USER";
$password = "H8_PASS";
$email = "H8_EMAIL";
if (Factory::getUserFactory()->getDB(true) === null) {
//connection not valid
printf ( "Unable to connect to the Database\n" );
exit;
}
Factory::getAgentFactory()->getDB()->beginTransaction();
$qF = new QueryFilter(RightGroup::GROUP_NAME, "Administrator", "=");
$group = Factory::getRightGroupFactory()->filter(array(Factory::FILTER => array($qF)));
$group = $group[0];
$newSalt = Util::randomString(20);
// $newHash = Encryption::passwordHash($password, $newSalt);
$user = new User(0, $username, $email, Encryption::passwordHash($password, $newSalt), $newSalt, 1, 1, 0, time(), 3600, $group->getId(), 0, "", "", "", "");
Factory::getUserFactory()->save($user);
// create default group
$group = AccessUtils::getOrCreateDefaultAccessGroup();
$groupUser = new AccessGroupUser(0, $group->getId(), $user->getId());
Factory::getAccessGroupUserFactory()->save($groupUser);
Factory::getAgentFactory()->getDB()->commit();