@@ -21,7 +21,6 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Return a JSON response for error. |
| 23 | 23 | * |
| 24 | - * @param array $data |
|
| 25 | 24 | * @param string $code |
| 26 | 25 | * @return \Illuminate\Http\JsonResponse |
| 27 | 26 | */ |
@@ -33,7 +32,7 @@ discard block |
||
| 33 | 32 | * Check if the user is authorized to perform a given action on a resource. |
| 34 | 33 | * |
| 35 | 34 | * @param \Illuminate\Http\Request $request |
| 36 | - * @param array $resource |
|
| 35 | + * @param string $resource |
|
| 37 | 36 | * @param mixed|array $arguments |
| 38 | 37 | * @return boolean |
| 39 | 38 | * @see https://lumen.laravel.com/docs/authorization |
@@ -67,9 +66,6 @@ discard block |
||
| 67 | 66 | * Get current authorized user id. |
| 68 | 67 | * This method should be called only after validating the access token using OAuthMiddleware Middleware. |
| 69 | 68 | * |
| 70 | - * @param \Illuminate\Http\Request $request |
|
| 71 | - * @param array $resource |
|
| 72 | - * @param array $data |
|
| 73 | 69 | * @return boolean |
| 74 | 70 | * |
| 75 | 71 | * @throws LucaDegasperi\OAuth2Server\Exceptions\NoActiveAccessTokenException |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | * @param string $code |
| 15 | 15 | * @return \Illuminate\Http\JsonResponse |
| 16 | 16 | */ |
| 17 | - public function success($data, $code){ |
|
| 18 | - return response()->json(['data' => $data], $code); |
|
| 19 | - } |
|
| 17 | + public function success($data, $code){ |
|
| 18 | + return response()->json(['data' => $data], $code); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Return a JSON response for error. |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @param string $code |
| 26 | 26 | * @return \Illuminate\Http\JsonResponse |
| 27 | 27 | */ |
| 28 | - public function error($message, $code){ |
|
| 29 | - return response()->json(['message' => $message], $code); |
|
| 30 | - } |
|
| 28 | + public function error($message, $code){ |
|
| 29 | + return response()->json(['message' => $message], $code); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Check if the user is authorized to perform a given action on a resource. |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | protected function authorizeUser(Request $request, $resource, $arguments = []){ |
| 42 | 42 | |
| 43 | - $user = User::find($this->getUserId()); |
|
| 44 | - $action = $this->getAction($request); |
|
| 43 | + $user = User::find($this->getUserId()); |
|
| 44 | + $action = $this->getAction($request); |
|
| 45 | 45 | |
| 46 | 46 | // The ability string must match the string defined in App\Providers\AuthServiceProvider\ability() |
| 47 | 47 | $ability = "{$action}-{$resource}"; |
| 48 | 48 | |
| 49 | - // return $this->authorizeForUser($user, "{$action}-{$resource}", $data); |
|
| 50 | - return Gate::forUser($user)->allows($ability, $arguments); |
|
| 49 | + // return $this->authorizeForUser($user, "{$action}-{$resource}", $data); |
|
| 50 | + return Gate::forUser($user)->allows($ability, $arguments); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @throws LucaDegasperi\OAuth2Server\Exceptions\NoActiveAccessTokenException |
| 76 | 76 | */ |
| 77 | 77 | protected function getUserId(){ |
| 78 | - return \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId(); |
|
| 78 | + return \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId(); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use App\User; |
| 6 | 6 | use Gate; |
| 7 | 7 | |
| 8 | -class Controller extends BaseController{ |
|
| 8 | +class Controller extends BaseController { |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Return a JSON response for success. |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @param string $code |
| 15 | 15 | * @return \Illuminate\Http\JsonResponse |
| 16 | 16 | */ |
| 17 | - public function success($data, $code){ |
|
| 17 | + public function success($data, $code) { |
|
| 18 | 18 | return response()->json(['data' => $data], $code); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param string $code |
| 26 | 26 | * @return \Illuminate\Http\JsonResponse |
| 27 | 27 | */ |
| 28 | - public function error($message, $code){ |
|
| 28 | + public function error($message, $code) { |
|
| 29 | 29 | return response()->json(['message' => $message], $code); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | * @return boolean |
| 39 | 39 | * @see https://lumen.laravel.com/docs/authorization |
| 40 | 40 | */ |
| 41 | - protected function authorizeUser(Request $request, $resource, $arguments = []){ |
|
| 41 | + protected function authorizeUser(Request $request, $resource, $arguments = []) { |
|
| 42 | 42 | |
| 43 | - $user = User::find($this->getUserId()); |
|
| 44 | - $action = $this->getAction($request); |
|
| 43 | + $user = User::find($this->getUserId()); |
|
| 44 | + $action = $this->getAction($request); |
|
| 45 | 45 | |
| 46 | 46 | // The ability string must match the string defined in App\Providers\AuthServiceProvider\ability() |
| 47 | 47 | $ability = "{$action}-{$resource}"; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param \Illuminate\Http\Request $request |
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | - public function isAuthorized(Request $request){ |
|
| 62 | + public function isAuthorized(Request $request) { |
|
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @throws LucaDegasperi\OAuth2Server\Exceptions\NoActiveAccessTokenException |
| 76 | 76 | */ |
| 77 | - protected function getUserId(){ |
|
| 77 | + protected function getUserId() { |
|
| 78 | 78 | return \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId(); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param \Illuminate\Http\Request $request |
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | - protected function getAction(Request $request){ |
|
| 87 | + protected function getAction(Request $request) { |
|
| 88 | 88 | return explode('@', $request->route()[1]["uses"], 2)[1]; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param \Illuminate\Http\Request $request |
| 95 | 95 | * @return array |
| 96 | 96 | */ |
| 97 | - protected function getArgs(Request $request){ |
|
| 97 | + protected function getArgs(Request $request) { |
|
| 98 | 98 | return $request->route()[2]; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -3,8 +3,6 @@ |
||
| 3 | 3 | namespace App\Listeners; |
| 4 | 4 | |
| 5 | 5 | use App\Events\ExampleEvent; |
| 6 | -use Illuminate\Queue\InteractsWithQueue; |
|
| 7 | -use Illuminate\Contracts\Queue\ShouldQueue; |
|
| 8 | 6 | |
| 9 | 7 | class ExampleListener |
| 10 | 8 | { |
@@ -7,7 +7,6 @@ |
||
| 7 | 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | 8 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
| 9 | 9 | use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
| 10 | - |
|
| 11 | 10 | use Illuminate\Support\Facades\Hash; |
| 12 | 11 | |
| 13 | 12 | class User extends Model implements AuthenticatableContract, AuthorizableContract{ |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | * @return int|boolean |
| 41 | 41 | * @see https://github.com/lucadegasperi/oauth2-server-laravel/blob/master/docs/authorization-server/password.md |
| 42 | 42 | */ |
| 43 | - public function verify($email, $password){ |
|
| 43 | + public function verify($email, $password) { |
|
| 44 | 44 | |
| 45 | 45 | $user = User::where('email', $email)->first(); |
| 46 | 46 | |
| 47 | - if($user && Hash::check($password, $user->password)){ |
|
| 47 | + if ($user && Hash::check($password, $user->password)) { |
|
| 48 | 48 | return $user->id; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -9,22 +9,22 @@ |
||
| 9 | 9 | * |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
| 12 | - protected $fillable = ['id', 'post_id', 'user_id', 'content']; |
|
| 12 | + protected $fillable = ['id', 'post_id', 'user_id', 'content']; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * The attributes excluded from the model's JSON form. |
| 16 | 16 | * |
| 17 | 17 | * @var array |
| 18 | 18 | */ |
| 19 | - protected $hidden = ['created_at', 'updated_at']; |
|
| 19 | + protected $hidden = ['created_at', 'updated_at']; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Define an inverse one-to-many relationship with App\Post. |
| 23 | 23 | * |
| 24 | 24 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 25 | 25 | */ |
| 26 | - public function post(){ |
|
| 27 | - return $this->belongsTo('App\Post'); |
|
| 28 | - } |
|
| 26 | + public function post(){ |
|
| 27 | + return $this->belongsTo('App\Post'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | |
| 5 | -class Comment extends Model{ |
|
| 5 | +class Comment extends Model { |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * The attributes that are mass assignable. |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @var array |
| 18 | 18 | */ |
| 19 | - protected $hidden = ['created_at', 'updated_at']; |
|
| 19 | + protected $hidden = ['created_at', 'updated_at']; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Define an inverse one-to-many relationship with App\Post. |
| 23 | 23 | * |
| 24 | 24 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 25 | 25 | */ |
| 26 | - public function post(){ |
|
| 26 | + public function post() { |
|
| 27 | 27 | return $this->belongsTo('App\Post'); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -48,15 +48,15 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | public function render($request, Exception $e) |
| 50 | 50 | { |
| 51 | - if(env('APP_DEBUG')){ |
|
| 51 | + if (env('APP_DEBUG')) { |
|
| 52 | 52 | return parent::render($request, $e); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if($e instanceof NotFoundHttpException){ |
|
| 55 | + if ($e instanceof NotFoundHttpException) { |
|
| 56 | 56 | return response()->json(['message' => 'Bad Request', 'code' => 400], 400); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if($e instanceof MethodNotAllowedHttpException){ |
|
| 59 | + if ($e instanceof MethodNotAllowedHttpException) { |
|
| 60 | 60 | return response()->json(['message' => 'Not Found', 'code' => 404], 404); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -7,7 +7,6 @@ |
||
| 7 | 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | 8 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
| 9 | 9 | use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
| 10 | - |
|
| 11 | 10 | use Illuminate\Support\Facades\Hash; |
| 12 | 11 | |
| 13 | 12 | class User extends Model implements AuthenticatableContract, AuthorizableContract{ |
@@ -9,22 +9,22 @@ |
||
| 9 | 9 | * |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
| 12 | - protected $fillable = ['id', 'user_id', 'title', 'content']; |
|
| 12 | + protected $fillable = ['id', 'user_id', 'title', 'content']; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * The attributes excluded from the model's JSON form. |
| 16 | 16 | * |
| 17 | 17 | * @var array |
| 18 | 18 | */ |
| 19 | - protected $hidden = ['created_at', 'updated_at']; |
|
| 19 | + protected $hidden = ['created_at', 'updated_at']; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Define a one-to-many relationship with App\Comment |
| 23 | 23 | * |
| 24 | 24 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 25 | 25 | */ |
| 26 | - public function comments(){ |
|
| 27 | - return $this->hasMany('App\Comment'); |
|
| 28 | - } |
|
| 26 | + public function comments(){ |
|
| 27 | + return $this->hasMany('App\Comment'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | |
| 5 | -class Post extends Model{ |
|
| 5 | +class Post extends Model { |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * The attributes that are mass assignable. |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @var array |
| 18 | 18 | */ |
| 19 | - protected $hidden = ['created_at', 'updated_at']; |
|
| 19 | + protected $hidden = ['created_at', 'updated_at']; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Define a one-to-many relationship with App\Comment |
| 23 | 23 | * |
| 24 | 24 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 25 | 25 | */ |
| 26 | - public function comments(){ |
|
| 26 | + public function comments() { |
|
| 27 | 27 | return $this->hasMany('App\Comment'); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param array $arguments |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - private function isOwner($arguments = []){ |
|
| 59 | + private function isOwner($arguments = []) { |
|
| 60 | 60 | |
| 61 | 61 | foreach ($arguments as $resource => $actions) { |
| 62 | 62 | foreach ($actions as $action) { |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | // } |
| 68 | 68 | // }); |
| 69 | 69 | |
| 70 | - Gate::define($this->ability($action, $resource), function ($user, $arg) { |
|
| 70 | + Gate::define($this->ability($action, $resource), function($user, $arg) { |
|
| 71 | 71 | |
| 72 | - if(is_null($arg)) { return false; } |
|
| 72 | + if (is_null($arg)) { return false; } |
|
| 73 | 73 | |
| 74 | 74 | return $arg->user_id === $user->id || $user->is_admin; |
| 75 | 75 | }); |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | * @param array $arguments |
| 84 | 84 | * @return boolean |
| 85 | 85 | */ |
| 86 | - private function isAdmin($arguments){ |
|
| 86 | + private function isAdmin($arguments) { |
|
| 87 | 87 | |
| 88 | 88 | foreach ($arguments as $resource => $actions) { |
| 89 | 89 | foreach ($actions as $action) { |
| 90 | - Gate::define($this->ability($action, $resource), function ($user) { |
|
| 90 | + Gate::define($this->ability($action, $resource), function($user) { |
|
| 91 | 91 | return $user->is_admin; |
| 92 | 92 | }); |
| 93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param string $resource |
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | - private function ability($action, $resource){ |
|
| 104 | + private function ability($action, $resource) { |
|
| 105 | 105 | return "{$action}-{$resource}"; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -11,11 +11,11 @@ |
||
| 11 | 11 | * @param \Closure $next |
| 12 | 12 | * @return mixed |
| 13 | 13 | */ |
| 14 | - public function handle($request, Closure $next, $controller){ |
|
| 14 | + public function handle($request, Closure $next, $controller) { |
|
| 15 | 15 | |
| 16 | 16 | $controller = new $controller(); |
| 17 | 17 | |
| 18 | - if(!$controller->isAuthorized($request)){ |
|
| 18 | + if (!$controller->isAuthorized($request)) { |
|
| 19 | 19 | return $controller->error("You aren't allowed to perform the requested action", 403); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -4,20 +4,20 @@ |
||
| 4 | 4 | |
| 5 | 5 | class CommentController extends Controller{ |
| 6 | 6 | |
| 7 | - public function index(){ |
|
| 7 | + public function index(){ |
|
| 8 | 8 | |
| 9 | - $comments = Comment::all(); |
|
| 10 | - return $this->success($comments, 200); |
|
| 11 | - } |
|
| 9 | + $comments = Comment::all(); |
|
| 10 | + return $this->success($comments, 200); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function show($id){ |
|
| 13 | + public function show($id){ |
|
| 14 | 14 | |
| 15 | - $comment = Comment::find($id); |
|
| 15 | + $comment = Comment::find($id); |
|
| 16 | 16 | |
| 17 | - if(!$comment){ |
|
| 18 | - return $this->error("The comment with {$id} doesn't exist", 404); |
|
| 19 | - } |
|
| 17 | + if(!$comment){ |
|
| 18 | + return $this->error("The comment with {$id} doesn't exist", 404); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - return $this->success($comment, 200); |
|
| 22 | - } |
|
| 21 | + return $this->success($comment, 200); |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -2,19 +2,19 @@ |
||
| 2 | 2 | |
| 3 | 3 | use App\Comment; |
| 4 | 4 | |
| 5 | -class CommentController extends Controller{ |
|
| 5 | +class CommentController extends Controller { |
|
| 6 | 6 | |
| 7 | - public function index(){ |
|
| 7 | + public function index() { |
|
| 8 | 8 | |
| 9 | 9 | $comments = Comment::all(); |
| 10 | 10 | return $this->success($comments, 200); |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - public function show($id){ |
|
| 13 | + public function show($id) { |
|
| 14 | 14 | |
| 15 | 15 | $comment = Comment::find($id); |
| 16 | 16 | |
| 17 | - if(!$comment){ |
|
| 17 | + if (!$comment) { |
|
| 18 | 18 | return $this->error("The comment with {$id} doesn't exist", 404); |
| 19 | 19 | } |
| 20 | 20 | |