[Code coverage details](http://coverage.buckhill.com.hr/authstack/authprofile/coverage)

[Treemap of code coverage](http://coverage.buckhill.com.hr/authstack/authprofile/treemap)

# Authentication profiles for AuthStack

Authentication profile is authentication information saved into session, which is used to apply preferences and look up authentication information about a user.

Authentication profiles are exposed as collection of `AuthProfile` objects which is used for easier manipulation and data retrieval.

## Installation

`composer require "authstack/authprofile: ~2"`

## Adding service provider
   
   Open `config/app.php` and add the following to `providers` array:
   
```
'providers' => array(

   AuthStack\AuthProfile\Provider\ProfileManagerProvider::class
);

```

## Usage

#### Check if user is authenticated


```
<?php

use AuthStack\AuthProfile\Facade\ProfileManager;

$authenticated = ProfileManager::isAuthenticated();

```

#### Retrieve active profile (if authenticated only)

```
<?php

use AuthStack\AuthProfile\Facade\ProfileManager;

/** @var $profile \AuthStack\AuthProfile\Model\AuthProfile */
$profile = ProfileManager::getActiveProfile()

```

#### Check if entry exists in the array with profiles

```
<?php

use AuthStack\AuthProfile\Facade\ProfileManager;

/** @var $profiles Illuminate\Support\Collection */
$profiles = ProfileManager::getCollection();

$contains = $profiles->where('session_id', '12456');

$exists = (bool)$contains->count();

```

#### Mark another profile as active one (only if there are multiple profiles in the session)

This method might set a non-existent profile as active one.
It's advisable that you check whether the profile exists first before setting it as active or use `setActiveProfileIfExists` method.

```
<?php

use AuthStack\AuthProfile\Facade\ProfileManager;

$session_id = $request->input('session_id');

ProfileManager::setActiveProfile($session_id);

```