Skip to content

Copied orm docs from docs repository into this one #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions docs/auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Authentication

## Configuration

### Implementing Authenticatable

First you must extend Laravel's authentication contract on the entity you wish to use with authentication.

```
class User implements \Illuminate\Contracts\Auth\Authenticatable
{

/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;

public function getAuthIdentifierName()
{
return 'id';
}

public function getAuthIdentifier()
{
return $this->id;
}

public function getPassword()
{
return $this->password;
}
}
```

You may also use the provided trait `LaravelDoctrine\ORM\Auth\Authenticatable` in your entity and override where necessary.


```
class User implements \Illuminate\Contracts\Auth\Authenticatable
{
use \LaravelDoctrine\ORM\Auth\Authenticatable;

/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $userId;

public function getAuthIdentifierName()
{
return 'userId';
}
}
```

### Configuring Laravel

Edit Laravel's Auth configuration (`/config/auth.php`) to set up use with Doctrine.

```
return [

/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
|
*/

'driver' => 'doctrine',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| This is the entity that has implemented Authenticatable
|
*/

'model' => App\Entities\User::class,


/*
|--------------------------------------------------------------------------
| Password Reset Settings
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You can also set the name of the
| table that maintains all of the reset tokens for your application.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/

'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],

];
```

## Password hashing
Password hashing must be handled by your application; Laravel's authentication
and LaravelDoctrine will treat passwords as nothing more than strings. We would
recommend decoupling the operation of hashing of the password (and any other
procedures, like validating strength) from its storage by implementing a separate
service to handle any password-related actions.

```
use \Illuminate\Contracts\Hashing\Hasher;

class PasswordService
{
private $hasher;
private $passwordStrengthValidator;

/**
* @param Hasher $hasher
* @param MyPasswordStrengthValidator $passwordStrength
*/
public function __construct(
Hasher $hasher,
MyPasswordStrengthValidator $passwordStrength
) {
$this->hasher = $hasher;
$this->passwordStrengthValidator = $passwordStrength
}

/**
* Validate and change the given users password
*
* @param User $user
* @param string $password
* @throws PasswordTooWeakException
* @return void
*/
public function changePassword(User $user, $password)
{
if ($this->passwordStrengthValidator->isStrongEnough($password)) {
$user->setPassword($this->hasher->make($password))
} else {
throw new PasswordTooWeakException();
}
}
}
```

## Using Authentication

Authentication usage is covered by [Laravel's Documentation.](https://laravel.com/docs/authentication)
25 changes: 25 additions & 0 deletions docs/caching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Caching

This package supports these caching systems out of the box:

* redis
* memcached
* file
* apc
* array

## Extending or Adding Cache Drivers

Drivers can be replaced or added using `LaravelDoctrine\ORM\Configuration\Cache\CacheManager`. The return should implement `Doctrine\Common\Cache\Cache` or extend `Doctrine\Common\Cache\CacheProvider`

```php
public function register()
{
$this->app->resolving(CacheManager::class, function (CacheManager $cache){
$cache->extend('memcache', function(array $settings, Application $app) {
$memcache = new \Memcache;
return new MemcacheCache($memcache);
});
});
}
```
Loading
Loading