Skip to content

Commit

Permalink
Add polices
Browse files Browse the repository at this point in the history
  • Loading branch information
angelkurten committed Nov 3, 2015
1 parent 9d1e20b commit fe154a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
5 changes: 1 addition & 4 deletions Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, SluggableInterface
{
use SluggableTrait;
use Authenticatable, CanResetPassword;
use EntrustUserTrait;

use SluggableTrait, Authenticatable, CanResetPassword, EntrustUserTrait;

protected $table = 'users';

Expand Down
13 changes: 10 additions & 3 deletions Http/Controllers/Learning/UserController.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
<?php namespace Modules\User\Http\Controllers\Learning;

use Modules\Course\Entities\Module;
use Modules\User\Repositories\UserRepository;
use Pingpong\Modules\Routing\Controller;
use Modules\User\Polices\Learning\UserPolice;

class UserController extends Controller {

/**
* @var UserRepository
*/
private $user;
/**
* @var UserPolice
*/
private $userPolice;

function __construct(UserRepository $user)
function __construct(UserRepository $user, UserPolice $userPolice)
{

$this->user = $user;
$this->userPolice = $userPolice;
}


public function getProfile($slugOrId)
{
$profile = $this->user->findBySlugOrIdOrFail($slugOrId);

return theme('user.learning.profile', compact('profile'));
$updatePolice = $this->userPolice->update($profile);
return theme('user.learning.profile', compact('profile', 'updatePolice'));
}

public function getPublicProfile($slugOrId)
Expand Down
23 changes: 23 additions & 0 deletions Polices/Learning/UserPolice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Modules\User\Polices\Learning;


use Illuminate\Auth\Guard;

class UserPolice
{

public function __construct(Guard $auth)
{
$this->user = $auth->user();
}

public function update($user, $auth = null)
{
if($auth==null)
$auth = $this->user;

return $user->id == $auth->id;
}
}

0 comments on commit fe154a6

Please sign in to comment.