Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit d410a14

Browse files
committed
Working on tutorials.
1 parent c6467e0 commit d410a14

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

docs/tutorials/users.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# User Tutorials
2+
3+
> **Notice**: These tutorials have been created using ActiveDirectory.
4+
> Some tutorials may not relate to your LDAP distribution.
5+
6+
> **Note**: You cannot create or modify user passwords without
7+
> connecting to your LDAP server via SSL or TLS.
8+
9+
## Creating Users
10+
11+
To begin, creating a user is actually quite simple, as it only requries a Common Name:
12+
13+
```php
14+
$user = Adldap::make()->user([
15+
'cn' => 'John Doe',
16+
]);
17+
18+
$user->save();
19+
```
20+
21+
If you'd like to provide more attributes, simply add more:
22+
23+
```php
24+
$user = Adldap::make()->user([
25+
'cn' => 'John Doe',
26+
'sn' => 'Doe',
27+
'givenname' => 'John',
28+
'department' => 'Accounting'
29+
]);
30+
31+
$user->save();
32+
```
33+
34+
If you don't provide a Distinguished Name to the user during creation, one will be set for you automatically by taking your configured `base_dn` and using the users Common Name you give them:
35+
36+
```php
37+
$user = Adldap::make()->user([
38+
'cn' => 'John Doe',
39+
]);
40+
41+
$user->save(); // Creates a user with the DN: 'cn=John Doe,dc=acme,dc=org'
42+
```
43+
44+
You can provide a `dn` attribute to set the users Distinguished Name you would like to use for creation:
45+
46+
```php
47+
$user = Adldap::make()->user([
48+
'cn' => 'John Doe',
49+
'dn' => 'cn=John Doe,ou=Users,dc=acme,dc=com'
50+
]);
51+
52+
$user->save();
53+
```
54+
55+
All users created in your directory will be disabled by default. How do we enable these users upon creation and set thier password?
56+
57+
What we can use is the `Adldap\Models\Attributes\AccountControl` attribute class and the `userPassword` attribute.
58+
59+
```php
60+
// Encode the users password.
61+
$password = Adldap\Utilies::encodePassword('super-secret');
62+
63+
// Create a new AccountControl object.
64+
$uac = new Adldap\Models\Attributes\AccountControl();
65+
66+
// Set the UAC value to '512'.
67+
$uac->accountIsNormal();
68+
69+
$user = Adldap::make()->user([
70+
'cn' => 'John Doe',
71+
'dn' => 'cn=John Doe,ou=Users,dc=acme,dc=com'
72+
'userPassword' => $password,
73+
'userAccountControl' => $uac->getValue(),
74+
]);
75+
76+
$user->save();
77+
```
78+
79+
You can also fluently create accounts using setter methods if you'd prefer:
80+
81+
> **Note**: There are some conveniences that come with using the setter methods.
82+
> Notice how you don't have to encode the password using the `setPassword()`
83+
> method or call `getValue()` when setting the users account control.
84+
85+
```php
86+
// Create a new AccountControl object.
87+
$uac = new Adldap\Models\Attributes\AccountControl();
88+
89+
$uac->accountIsNormal();
90+
91+
$user = Adldap::make()->user();
92+
93+
$user
94+
->setCommonName('John Doe')
95+
->setDn('cn=John Doe,ou=Users,dc=acme,dc=com')
96+
->setPassword('super-secret')
97+
->setUserAccountControl($uac);
98+
99+
$user->save();
100+
```
101+
102+
## Modifying Users
103+
104+
You can modify users in a variety of ways. Each way will be shown below.
105+
Use whichever ways you prefer readable and most clear to you.
106+
107+
To modify users, you simply modify their attributes using dynamic properties and `save()` them:
108+
109+
```php
110+
$jdoe = Adldap::search()->users()->find('jdoe');
111+
112+
$uac = new Adldap\Models\Attributes\AccountControl();
113+
114+
$uac->accountIsNormal();
115+
116+
$jdoe->deparment = 'Accounting';
117+
$jdoe->telephoneNumber = '555 555-5555';
118+
$jdoe->mobile = '555 444-4444';
119+
$jdoe->userAccountControl = $uac->getValue();
120+
121+
$jdoe->save();
122+
```

0 commit comments

Comments
 (0)