-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_admin.php
60 lines (58 loc) · 1.44 KB
/
create_admin.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
<?php
require_once './db_auth.php';
require_once './auth/vendor/autoload.php';
$auth = new \Delight\Auth\Auth($pda);
/* First time create admin user
Caution : Email validation is hard,, eg : "root@localhost' is not a valid email.
*/
$email = 'jpprr@jppozzi.dyndns.org';
$usern = 'admin';
$passw = 'Admin1234';
$MSG = "??????????";
$ERR = 0;
try {
$userId = $auth->admin()->createUser($email, $passw, $usern);
// we have signed up a new user with the ID `$userId`
$MSG = 'All is OK, user created';
} catch (\Delight\Auth\InvalidEmailException $e) {
// invalid email address
$MSG = 'Invalid email';
$ERR = 1;
} catch (\Delight\Auth\InvalidPasswordException $e) {
// invalid password
$MSG = 'Invalid password';
$ERR = 2;
} catch (\Delight\Auth\UserAlreadyExistsException $e) {
// user already exists
$MSG = 'User already exists';
$ERR = 3;
}
$MSG2 = "";
if ( $ERR == 0 )
{
try {
$auth->admin()->addRoleForUserByUsername($usern, \Delight\Auth\Role::ADMIN);
$MSG2 = " Assigned to role ADMIN";
} catch (\Delight\Auth\UnknownUsernameException $e) {
// unknown username
$MSG2 = "Can't assign user to role ADMIN, unknown user";
$ERR = 4;
} catch (\Delight\Auth\AmbiguousUsernameException $e) {
// ambiguous username
$MSG2 = "Ambiguous username";
$ERR = 5;
}
}
/* */
?>
<html>
<head>
<title>Init AUTH</title>
</head>
<body>
Login
<?php
print('<br>MSG=' . $ERR . " : " . $MSG . " " . $MSG2 . '<br>');
?>
</body>
</html>