또한 보기: LucaDegasperi\OAuth2Server\Authorizer
저자: Luca Degasperi (packages@lucadegasperi.com)
상속: extends Illuminate\Support\Facades\Facade
예제 #1
0
 public function store(array $data)
 {
     try {
         $userId = Authorizer::getResourceOwnerId();
         $this->user = $this->repository->find($userId);
         $data['cliente_id'] = $this->user->cliente_id;
         //$this->validator->with($data)->passesOrFail();
         //Verificando se email existeformlogin
         $usuario = $this->repository->findWhere(['cliente_id' => $data['cliente_id'], 'email' => $data['email']]);
         if ($usuario->count()) {
             return ['warning' => true, 'message' => 'Email já cadastrado!'];
         }
         $data['token_senha'] = str_random(60);
         $this->repository->create($data);
         $data['link'] = 'www.teste.proload.com.br/#/acesso/' . $data['token_senha'];
         Mail::send('email.bemvindo', ['dado' => $data], function ($m) use($data) {
             $m->to($data['email'], $data['name'])->subject('Bem vindo ao ProDmed');
         });
         return ['success' => true, 'message' => 'Usuário cadastrado com sucesso!'];
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     } catch (QueryException $e) {
         return ['error' => true, 'message' => $e->getMessage()];
     }
 }
예제 #2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     #Precisa desse validate para funcionar
     $validado = Authorizer::validateAccessToken();
     /*dd(Authorizer::validateAccessToken(),
       Authorizer::getResourceOwnerId(),
       Authorizer::getResourceOwnerType(),
       Authorizer::getAccessToken()->getId(),
       Authorizer::getAccessToken());*/
     /*$token = Authorizer::getAccessToken()->getId();
             $id_cliente = Authorizer::getResourceOwnerId();
     
             $token_db = DB::table('oauth_access_tokens')
                 ->where('id', $token)
                 ->where('grant_type', 'cliente')->first();
     
             #dd($token_db);
     
             if($validado && $token_db){
     
             }*/
     $checker = Authorizer::getChecker();
     $accessToken = $checker->getAccessToken();
     #dd($checker);
     #dd($accessToken);
     $accessTokenEntity = DB::table('oauth_access_tokens')->where('id', $accessToken)->first();
     #dd($accessTokenEntity);
     $grantType = $accessTokenEntity->grant_type ? $accessTokenEntity->grant_type : null;
     #dd($grantType);
     if ($grantType != 'cliente') {
         abort(403, 'Access forbidden');
     }
     return $next($request);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $deliverymanId = Authorizer::getResourceOwnerId();
     if ($order = $this->orderService->updateStatus($id, $deliverymanId, $request->get('status'))) {
         return $order;
     }
     abort(400, 'Pedido não encontrado');
 }
예제 #4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $project_id = $request->project;
     if ($this->repository->isOwner($project_id, Authorizer::getResourceOwnerId()) == false) {
         return ['error' => 'Access forbidden'];
     }
     return $next($request);
 }
 public function store(CheckoutRequest $request)
 {
     $data = $request->all();
     $client = $this->userRepository->find(Authorizer::getResourceOwnerId())->client->id;
     $data['client_id'] = $client;
     $order = $this->orderService->create($data);
     return $this->orderRepository->skipPresenter(false)->with($this->with)->find($order->id);
 }
예제 #6
0
 public function index()
 {
     #$rtrn = $this->user_repository->skipPresenter()->find(Authorizer::getResourceOwnerId())->projects()->with(['client', 'tasks', 'notes', 'members', 'owner'])->get();
     $rtrn = $this->repository->findWithOwnerAndMember(Authorizer::getResourceOwnerId());
     #$rtrn = $this->user_repository->find(Authorizer::getResourceOwnerId())->projects()->with(['client', 'tasks', 'notes', 'members', 'owner'])->get();
     #return $this->user_repository->find(Authorizer::getResourceOwnerId())->projects()->with(['client', 'tasks', 'notes', 'members'])->get();
     return $rtrn;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $user = $this->userRepository->skipPresenter()->find(Authorizer::getResourceOwnerId());
     if ($user->role != $role) {
         abort(403, 'Access forbidden');
     }
     return $next($request);
 }
 public function createToken(Request $request)
 {
     $json = $request->json()->all();
     $request = new Request();
     $request->request->replace($json);
     Authorizer::setRequest($request);
     return $this->respond(Authorizer::issueAccessToken());
 }
 public function all($id = null, $limit = 6)
 {
     $this->setPresenter();
     if (!is_null($id)) {
         return $this->repository->findWhere(['project_id' => $id]);
     }
     return $this->repository->recentTasks(Authorizer::getResourceOwnerId(), $limit);
 }
예제 #10
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $id = $request->id;
     if (!$this->repository->isOwner($id, Authorizer::getResourceOwnerId())) {
         return response()->json(['error' => true, 'message' => ['owner' => 'You are not an authorized user in this project']], 403);
     }
     return $next($request);
 }
예제 #11
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $userId = Authorizer::getResourceOwnerId();
     $cursoId = $request->curso;
     if ($this->repository->isOwner($cursoId, $userId) == false) {
         return ['error' => 'Access forbidden'];
     }
     return $next($request);
 }
예제 #12
0
 public function __construct(EmpresaRepository $repository, EmpresaValidator $validator, PrefeituraGoiania $prefeitura, UserRepository $userRepository)
 {
     $this->repository = $repository;
     $this->validator = $validator;
     $this->prefeitura = $prefeitura;
     $this->userRepository = $userRepository;
     $userId = Authorizer::getResourceOwnerId();
     $this->user = $this->userRepository->find($userId);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, ...$params)
 {
     $id = Authorizer::getResourceOwnerId();
     $user = $this->userRepository->find($id);
     if (!in_array($user->role, $params)) {
         abort(403, 'Access Forbidden');
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $userId = Authorizer::getResourceOwnerId();
     $projectId = $request->project;
     if ($this->repository->isOwner($projectId, $userId) == false) {
         return ['success' => false, 'userId' => 'Forbidden'];
     }
     return $next($request);
 }
 public function store(Request $request)
 {
     $id = Authorizer::getResourceOwnerId();
     $dados = $request->all();
     $cliente = $this->userRepository->find($id)->cliente->id;
     $dados['cliente_id'] = $cliente;
     $pedido = $this->pedidoService->criar($dados);
     return $this->repository->with('items')->find($pedido->id);
 }
예제 #16
0
 /**
  * @param VendasRepository $repository
  * @param VendasService $service
  */
 public function __construct(VendasRepository $repository, VendasService $service, RevendedoresRepository $revendedoresRepository)
 {
     $this->repository = $repository;
     $this->service = $service;
     $this->revendedoresRepository = $revendedoresRepository;
     $userId = Authorizer::getResourceOwnerId();
     $revendedor = $this->revendedoresRepository->findWhere(['id_usuario' => $userId]);
     $this->id_revendedor = $revendedor[0]['id'];
 }
 public function checkPermissions($projectId)
 {
     $owner = $this->project->find($projectId)->owner_id;
     $userId = Authorizer::getResourceOwnerId();
     if ($owner != $userId and !$this->hasMember($projectId)) {
         throw new \Exception('Access Denied');
     }
     return true;
 }
 public function store(CheckoutRequest $request)
 {
     $id = Authorizer::getResourceOwnerID();
     $data = $request->all();
     $clientId = $this->userRepository->find($id)->client->id;
     $data['client_id'] = $clientId;
     $order = $this->orderService->create($data);
     return $this->repository->with($this->with)->find($order->id);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $clientId = $this->userRepository->find(Authorizer::getResourceOwnerId())->client->id;
     $data['client_id'] = $clientId;
     $order = $this->orderService->create($data);
     $order = $this->orderRepository->with('items')->find($order->id);
     return $order;
 }
예제 #20
0
 public function handle($request, Closure $next, $role)
 {
     $id = Authorizer::getResourceOwnerID();
     $user = $this->userRepository->find($id);
     if ($user->role != $role) {
         abort('403', 'Access Forbidden');
     }
     return $next($request);
 }
예제 #21
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $userId = Authorizer::getResourceOwnerId();
     $projectId = $request->project;
     if ($this->repository->isOwner($projectId, $userId) == false) {
         return ['error' => "Acesso negado."];
     }
     return $next($request);
 }
 public function updateStatus(Request $request, $id)
 {
     $idDeliveryman = Authorizer::getResourceOwnerId();
     $order = $this->service->updateStatus($id, $idDeliveryman, $request->get('status'));
     if ($order) {
         return $this->repository->find($order->id);
     }
     abort(400, "Order not found!");
 }
 public function geo(Request $request, Geo $geo, $id)
 {
     $idDeliveryman = Authorizer::getResourceOwnerId();
     $order = $this->orderRepository->getByIdAndDeliveryman($id, $idDeliveryman);
     $geo->lat = $request->get('lat');
     $geo->long = $request->get('long');
     event(new GetLocationDeliveryMan($geo, $order));
     return $geo;
 }
 public function updatStatus(Request $request, $id)
 {
     $idDeliveryman = Authorizer::getResourceOwnerId();
     $order = $this->orderService->updateStatus($id, $idDeliveryman, $request->get('status'));
     if ($order) {
         return $this->orderRepository->find($order->id);
     }
     abort(400, 'order não encontrada');
 }
예제 #25
0
 function __construct()
 {
     $this->clientId = \LucaDegasperi\OAuth2Server\Facades\Authorizer::getClientId();
     $template = \App\Models\ClientTemplate::clientid($this->clientId)->first();
     if (!$template) {
         \App::abort(404);
     }
     $this->template = $template['located'];
 }
 public function store(Requests\CheckoutRequest $request)
 {
     $data = $request->all();
     $id = Authorizer::getResourceOwnerId();
     $clientId = $this->userRepository->find($id)->client->id;
     $data['client_id'] = $clientId;
     $o = $this->service->create($data);
     return $this->repository->skipPresenter(false)->with($this->with)->find($o->id);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $idUser = Authorizer::getResourceOwnerId();
     $idProject = $request->project;
     if ($this->repository->isOwner($idProject, $idUser) == false) {
         return ['success' => false];
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $userId = Authorizer::getResourceOwnerId();
     $projectId = $request->projects;
     if (!$this->repository->isOwner($projectId, $userId)) {
         return ['error' => 'Access forbidden'];
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $id = Authorizer::getResourceOwnerId();
     $user = $this->userRepository->find($id);
     if ($user->role != $role) {
         //se a role do usuário autenticado bate com a $role que passamos
         abort(403, 'Acesso Negado!');
     }
     return $next($request);
 }
예제 #30
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $id = Authorizer::getResourceOwnerId();
     $user = $this->userRepository->find($id);
     // dd($user->role.$role);
     if ($user->role != $role) {
         return abort(403, 'Acesso Negado! ');
     }
     return $next($request);
 }