See also: LucaDegasperi\OAuth2Server\Authorizer
Author: Luca Degasperi (packages@lucadegasperi.com)
Inheritance: extends Illuminate\Support\Facades\Facade
コード例 #1
0
ファイル: UserService.php プロジェクト: jaysongyn/dmed
 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);
 }
コード例 #5
0
 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;
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
 public function createToken(Request $request)
 {
     $json = $request->json()->all();
     $request = new Request();
     $request->request->replace($json);
     Authorizer::setRequest($request);
     return $this->respond(Authorizer::issueAccessToken());
 }
コード例 #9
0
 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
ファイル: EmpresaService.php プロジェクト: jaysongyn/dmed
 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);
 }
コード例 #13
0
 /**
  * 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);
 }
コード例 #14
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 ['success' => false, 'userId' => 'Forbidden'];
     }
     return $next($request);
 }
コード例 #15
0
 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'];
 }
コード例 #17
0
 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;
 }
コード例 #18
0
 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);
 }
コード例 #19
0
 /**
  * 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
ファイル: CheckProjectOwner.php プロジェクト: mvnp/Projeto
 /**
  * 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);
 }
コード例 #22
0
 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;
 }
コード例 #24
0
 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
ファイル: CRMController.php プロジェクト: ThunderID/SHOP-API
 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'];
 }
コード例 #26
0
 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);
 }
コード例 #27
0
 /**
  * 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);
 }
コード例 #28
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->projects;
     if (!$this->repository->isOwner($projectId, $userId)) {
         return ['error' => 'Access forbidden'];
     }
     return $next($request);
 }
コード例 #29
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);
     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);
 }