Skip to content
This repository has been archived by the owner on Jul 26, 2019. It is now read-only.

Commit

Permalink
Use custom sentry user model
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrkv committed Aug 21, 2015
1 parent 959db7e commit b379448
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 20 deletions.
56 changes: 39 additions & 17 deletions codeigniter/application/config/caramel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,57 @@
* @package Caramel
*/

$config['twig'] = [
$config = [

/**
*---------------------------------------------------------------
* Templates pathes
* Array
* Twig templates config
*---------------------------------------------------------------
*/
'twig' => [
/**
*---------------------------------------------------------------
* Templates pathes
* Array
*---------------------------------------------------------------
*/

'template_paths' =>
[
APPPATH . 'views/'
],
'template_paths' =>
[
APPPATH . 'views/'
],

/**
*---------------------------------------------------------------
* Template cache
* bool OR string APPPATH . 'cache/twig'
*---------------------------------------------------------------
*/
/**
*---------------------------------------------------------------
* Template cache
* bool OR string APPPATH . 'cache/twig'
*---------------------------------------------------------------
*/

'cache' => FALSE,

/**
*---------------------------------------------------------------
* CI output cache time in seconds;
* Integer
*---------------------------------------------------------------
*/

'cache' => FALSE,
'cache_time' => 10,
],

/**
*---------------------------------------------------------------
* CI output cache time in seconds;
* Integer
* Sentry config
*---------------------------------------------------------------
*/
'sentry' => [
/**
*---------------------------------------------------------------
* Sentry user model
*---------------------------------------------------------------
*/
'model' => 'App\Models\User'
]

'cache_time' => 10,
];
49 changes: 46 additions & 3 deletions src/Caramel/Caserne/Garde/Sentry.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php namespace Smartcat\Caramel\Caserne\Garde;

use Cartalyst\Sentry\Facades\CI\Sentry as SentryFacade;
use Cartalyst\Sentry\Cookies\CICookie;
use Cartalyst\Sentry\Hashing\NativeHasher;
use Cartalyst\Sentry\Sessions\CISession;
use Smartcat\Caramel\Caserne\Sentry\CaramelFacade as SentryFacade;
use Cartalyst\Sentry\Sentry as BaseSentry;
use Cartalyst\Sentry\Throttling\Eloquent\Provider as ThrottleProvider;
use Cartalyst\Sentry\Users\Eloquent\Provider as UserProvider;
use Cartalyst\Sentry\Groups\Eloquent\Provider as GroupProvider;

/**
* Class Garde
Expand All @@ -9,13 +16,49 @@
class Sentry extends AbstractGarde
{
/**
* Sentry gardians constructor
* Sentry garde constructor
*/
public function __construct()
{
parent::__construct();

$this->garnison = SentryFacade::createSentry();
$sentry_config = config_item('sentry');

$user_model = $sentry_config['model'];

$user_provider = $this->makeUserProvider($user_model);
$ip_address = $this->ci->input->ip_address();
$group_provider = new GroupProvider;
$throttle_provider = new ThrottleProvider($user_provider);
$ci_session = new CISession($this->ci->session);
$ci_cookie = new CICookie($this->ci->input);

$sentry = new BaseSentry(
$user_provider,
$group_provider,
$throttle_provider,
$ci_session,
$ci_cookie,
$ip_address
);

$this->garnison = $sentry;
}

/**
* Make user provider
*
* @param string $user_model
* @return UserProvider
*
*/
private function makeUserProvider($user_model)
{
if (class_exists($user_model)) {
return new UserProvider(new NativeHasher(), $user_model);
}

return new UserProvider(new NativeHasher());
}

/**
Expand Down

0 comments on commit b379448

Please sign in to comment.