-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateUser.php
73 lines (71 loc) · 3.78 KB
/
CreateUser.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
65
66
67
68
69
70
71
72
73
<?php
//Include menu options applicable to all pages of the web site
include("PhpSampleTemplate.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Create User
</title>
</head>
<body>
<?php
// If this was not a post back show the create user form
if (!isset($_POST['submit'])) {
?>
<form method="post" action="<?php echo($_SERVER['PHP_SELF']);?>">
<table>
<tr><td><b>Display Name:</b></td><td><input type="text" size="20" maxlength="100" name="dname"></td></tr>
<tr><td><b>Mail alias:</b></td><td><input type="text" size="20" maxlength="15" name="alias"></td></tr>
<tr><td><b>Title:</b></td><td><input type="text" size="20" maxlength="15" name="jobTitle"></td></tr>
<tr><td><b>Password:</b></td><td><input type="password" size="20" maxlength="15" name="password"></td></tr>
<tr><td><b>Force Password Change on Next Login:</b></td></tr>
<tr><td><b>True:</b></td><td><input type="radio" value="True" name="forcePasswordChangeOnNextLogin" checked></td></tr>
<tr><td><b>False:</b></td><td><input type="radio" value="False" name="forcePasswordChangeOnNextLogin"></td></tr>
<tr><td><b>Account Enabled:</b></td></tr>
<tr><td><b>True:</b></td><td><input type="radio" value="True" name="accountenabled" checked></td></tr>
<tr><td><b>False:</b></td><td><input type="radio" value="False" name="accountenabled"></td></tr>
<tr><td><input type="submit" value="submit" name="submit"></td></tr>
</table>
</form>
<?php
} else {
// Validate that the inputs are non-empty.
if((empty($_POST["dname"])) or (empty($_POST["alias"])) or (empty($_POST["accountenabled"])) or (empty($_POST["forcePasswordChangeOnNextLogin"])) or (empty($_POST["password"]))) {
echo('<p>One of the required fields is empty. Please go back to <a href="CreateUser.php">Create User</a></p>');
}
else {
//collect the form parameters which will be set in the case this was a post back.
$displayName = $_POST["dname"];
$alias = $_POST["alias"];
$accountEnabled = $_POST["accountenabled"];
$passwordProfile = array(
'password' => $_POST["password"],
'forceChangePasswordNextLogin' => $_POST["forcePasswordChangeOnNextLogin"],
);
$jobTitle = $_POST["jobTitle"];
$userEntryInput = array(
'displayName'=> $displayName,
'userPrincipalName' => $alias.'@'.Settings::$appTenantDomainName ,
'mailNickname' => $alias,
'passwordProfile' => $passwordProfile,
'accountEnabled' => $accountEnabled,
'jobTitle' => $jobTitle
);
// Create the user and display a message
$user = GraphServiceAccessHelper::addEntryToFeed('users',$userEntryInput);
//Check to see if we got back an error.
if(!empty($user->{'odata.error'}))
{
$message = $user->{'odata.error'}->{'message'};
echo('<p>User creation failed. Service returned error:<b>'.$message->{'value'}. '</b> Please go back to <a href="createUser.php">Create User</a></p>');
}
else {
header('Location: DisplayUsers.php');
}
}
}
?>
</body>
</html>