PHP Classes

File: CreateUser.php

Recommend this page to a friend!
  Classes of Mostafa Abd-El-Hamid   PHP Azure Active Directory   CreateUser.php   Download  
File: CreateUser.php
Role: Example script
Content type: text/plain
Description: Class source
Class: PHP Azure Active Directory
Manage users and groups of Windows Azure
Author: By
Last change:
Date: 8 years ago
Size: 4,095 bytes


Class file image Download
//Include menu options applicable to all pages of the web site

<!DOCTYPE html>
<html lang="en">
            Create User
// 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']);?>">
                <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>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>
} 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"]))) {
'<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"],

$userEntryInput = array(
'displayName'=> $displayName,
'userPrincipalName' => $alias.'@'.Settings::$appTenantDomainName ,
'mailNickname' => $alias,
'passwordProfile' => $passwordProfile,
'accountEnabled' => $accountEnabled
// Create the user and display a message
$user = GraphServiceAccessHelper::addEntryToFeed('users',$userEntryInput);
//Check to see if we got back an error.
$message = $user->{'odata.error'}->{'message'};
'<p>User creation failed. Service returned error:<b>'.$message->{'value'}. '</b> Please go back to <a href="createUser.php">Create User</a></p>');
                else {
'<b>Created User with the following information:</b>');
'<table><tr><td><b>Display Name: </b>' . $user->{'displayName'}. '</td><td><b>User Principal Name: </b>' . $user->{'userPrincipalName'} .'</td></tr></table>');
'<br/> <br/>');
'You can go back to <a href="CreateUser.php">Create User</a> to create more users.');