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

Commit e99cf1e

Browse files
committed
Merge pull request #15 from tortuetorche/patch-1
Add syntax highlighting in README.md
2 parents b5b5aa7 + 4040328 commit e99cf1e

File tree

1 file changed

+139
-124
lines changed

1 file changed

+139
-124
lines changed

README.md

Lines changed: 139 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,77 @@
99
## Installation
1010

1111
Insert Adldap2-Laravel into your `composer.json` file:
12-
13-
"adldap2/adldap2-laravel": "1.2.*",
12+
```json
13+
"adldap2/adldap2-laravel": "1.2.*",
14+
```
1415

1516
Then run `composer update`.
1617

1718
Once finished, insert the service provider in your `config/app.php` file:
19+
```php
20+
Adldap\Laravel\AdldapServiceProvider::class,
21+
```
1822

19-
Adldap\Laravel\AdldapServiceProvider::class,
20-
2123
Then insert the facade:
22-
23-
'Adldap' => Adldap\Laravel\Facades\Adldap::class
24+
```php
25+
'Adldap' => Adldap\Laravel\Facades\Adldap::class
26+
```
2427

2528
Publish the configuration file by running:
26-
27-
php artisan vendor:publish
29+
```bash
30+
php artisan vendor:publish
31+
```
2832

2933
Now you're all set!
3034

3135
## Usage
3236

3337
You can perform all methods on Adldap through its facade like so:
38+
```php
39+
$user = Adldap::users()->find('john doe');
3440

35-
$user = Adldap::users()->find('john doe');
36-
37-
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();
38-
39-
40-
if(Adldap::authenticate($username, $password))
41-
{
42-
// Passed!
43-
}
41+
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();
4442

45-
Or you can inject the Adldap contract:
4643

47-
use Adldap\Contracts\Adldap;
44+
if (Adldap::authenticate($username, $password)) {
45+
// Passed!
46+
}
47+
```
48+
49+
Or you can inject the Adldap contract:
50+
```php
51+
use Adldap\Contracts\Adldap;
52+
53+
class UserController extends Controller
54+
{
55+
/**
56+
* @var Adldap
57+
*/
58+
protected $adldap;
59+
60+
/**
61+
* Constructor.
62+
*
63+
* @param Adldap $adldap
64+
*/
65+
public function __construct(Adldap $adldap)
66+
{
67+
$this->adldap = $adldap;
68+
}
4869

49-
class UserController extends Controller
70+
/**
71+
* Displays the all LDAP users.
72+
*
73+
* @return \Illuminate\View\View
74+
*/
75+
public function index()
5076
{
51-
/**
52-
* @var Adldap
53-
*/
54-
protected $adldap;
77+
$users = $this->adldap->users()->all();
5578

56-
/**
57-
* Constructor.
58-
*
59-
* @param Adldap $adldap
60-
*/
61-
public function __construct(Adldap $adldap)
62-
{
63-
$this->adldap = $adldap;
64-
}
65-
66-
/**
67-
* Displays the all LDAP users.
68-
*
69-
* @return \Illuminate\View\View
70-
*/
71-
public function index()
72-
{
73-
$users = $this->adldap->users()->all();
74-
75-
return view('users.index', compact('users'));
76-
}
79+
return view('users.index', compact('users'));
7780
}
81+
}
82+
```
7883

7984
To see more usage in detail, please visit the [Adldap2 Repository](http://github.com/Adldap2/Adldap2);
8085

@@ -87,29 +92,33 @@ to the users as you would a regular laravel application.
8792
### Installation
8893

8994
Insert the `AdldapAuthServiceProvider` into your `config/app.php` file:
95+
```php
96+
Adldap\Laravel\AdldapAuthServiceProvider::class,
97+
```
9098

91-
Adldap\Laravel\AdldapAuthServiceProvider::class,
92-
9399
Publish the auth configuration:
94100

95-
php artisan vendor:publish
96-
97-
Change the auth driver in `config/auth.php` to `adldap`:
101+
```bash
102+
php artisan vendor:publish
103+
```
98104

99-
/*
100-
|--------------------------------------------------------------------------
101-
| Default Authentication Driver
102-
|--------------------------------------------------------------------------
103-
|
104-
| This option controls the authentication driver that will be utilized.
105-
| This driver manages the retrieval and authentication of the users
106-
| attempting to get access to protected areas of your application.
107-
|
108-
| Supported: "database", "eloquent"
109-
|
110-
*/
111-
112-
'driver' => 'adldap',
105+
Change the auth driver in `config/auth.php` to `adldap`:
106+
```php
107+
/*
108+
|--------------------------------------------------------------------------
109+
| Default Authentication Driver
110+
|--------------------------------------------------------------------------
111+
|
112+
| This option controls the authentication driver that will be utilized.
113+
| This driver manages the retrieval and authentication of the users
114+
| attempting to get access to protected areas of your application.
115+
|
116+
| Supported: "database", "eloquent"
117+
|
118+
*/
119+
120+
'driver' => 'adldap',
121+
```
113122

114123
### Usage
115124

@@ -123,27 +132,31 @@ This option just allows you to set your input name to however you see fit, and a
123132
In your login form, change the username form input name to your configured input name.
124133

125134
By default this is set to `email`:
135+
```html
136+
<input type="text" name="email" />
126137

127-
<input type="text" name="email" />
128-
129-
<input type="password" name="password" />
130-
131-
You'll also need to add the following to your AuthController if you're not overriding the default postLogin method.
138+
<input type="password" name="password" />
139+
```
132140

133-
protected $username = 'email';
141+
You'll also need to add the following to your AuthController if you're not overriding the default postLogin method.
142+
```php
143+
protected $username = 'email';
144+
```
134145

135146
If you'd like to use the users `samaccountname` to login instead, just change your input name and auth configuration:
147+
```html
148+
<input type="text" name="username" />
136149

137-
<input type="text" name="username" />
138-
139-
<input type="password" name="password" />
150+
<input type="password" name="password" />
151+
```
140152

141153
> **Note**: If you're using the `username` input field, make sure you have the `username` field inside your users database
142154
table as well. By default, laravel's migrations use the `email` field.
143155

144156
Inside `config/adldap_auth.php`
145-
146-
'username_attribute' => ['username' => 'samaccountname'],
157+
```php
158+
'username_attribute' => ['username' => 'samaccountname'],
159+
```
147160

148161
> **Note** The actual authentication is done with the `login_attribute` inside your `config/adldap_auth.php` file.
149162
@@ -171,57 +184,59 @@ attributes here, however be sure that your database table contains the key you'v
171184

172185
Inside your `config/adldap_auth.php` file there is a configuration option named `bind_user_to_model`. Setting this to
173186
true sets the `adldapUser` property on your configured auth User model to the Adldap User model. For example:
187+
```php
188+
if (Auth::attempt($credentials)) {
189+
$user = Auth::user();
174190

175-
if(Auth::attempt($credentials))
176-
{
177-
$user = Auth::user();
178-
179-
var_dump($user); // Returns instance of App\User;
180-
181-
var_dump($user->adldapUser); // Returns instance of Adldap\Models\User;
182-
183-
// Retrieving the authenticated LDAP users groups
184-
$groups = $user->adldapUser->getGroups();
185-
}
191+
var_dump($user); // Returns instance of App\User;
192+
193+
var_dump($user->adldapUser); // Returns instance of Adldap\Models\User;
186194

195+
// Retrieving the authenticated LDAP users groups
196+
$groups = $user->adldapUser->getGroups();
197+
}
198+
```
199+
187200
You **must** insert the trait `Adldap\Laravel\Traits\AdldapUserModelTrait` onto your configured auth User model, **OR**
188201
Add the public property `adldapUser` to your model.
189202

190-
// app/User.php
191-
192-
<?php
193-
194-
namespace App;
195-
196-
use Adldap\Laravel\Traits\AdldapUserModelTrait;
197-
use Illuminate\Auth\Authenticatable;
198-
use Illuminate\Database\Eloquent\Model;
199-
use Illuminate\Auth\Passwords\CanResetPassword;
200-
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
201-
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
202-
203-
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
204-
{
205-
use Authenticatable, CanResetPassword, AdldapUserModelTrait; // Insert trait here
206-
207-
/**
208-
* The database table used by the model.
209-
*
210-
* @var string
211-
*/
212-
protected $table = 'users';
213-
214-
/**
215-
* The attributes that are mass assignable.
216-
*
217-
* @var array
218-
*/
219-
protected $fillable = ['name', 'email', 'password'];
220-
221-
/**
222-
* The attributes excluded from the model's JSON form.
223-
*
224-
* @var array
225-
*/
226-
protected $hidden = ['password', 'remember_token'];
227-
}
203+
```php
204+
// app/User.php
205+
206+
<?php
207+
208+
namespace App;
209+
210+
use Adldap\Laravel\Traits\AdldapUserModelTrait;
211+
use Illuminate\Auth\Authenticatable;
212+
use Illuminate\Database\Eloquent\Model;
213+
use Illuminate\Auth\Passwords\CanResetPassword;
214+
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
215+
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
216+
217+
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
218+
{
219+
use Authenticatable, CanResetPassword, AdldapUserModelTrait; // Insert trait here
220+
221+
/**
222+
* The database table used by the model.
223+
*
224+
* @var string
225+
*/
226+
protected $table = 'users';
227+
228+
/**
229+
* The attributes that are mass assignable.
230+
*
231+
* @var array
232+
*/
233+
protected $fillable = ['name', 'email', 'password'];
234+
235+
/**
236+
* The attributes excluded from the model's JSON form.
237+
*
238+
* @var array
239+
*/
240+
protected $hidden = ['password', 'remember_token'];
241+
}
242+
```

0 commit comments

Comments
 (0)