示例#1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $queryParameters = array_filter($request->only(['first_name', 'last_name', 'email', 'group']));
     $members = Member::with('externalProfiles');
     if (array_key_exists('group', $queryParameters)) {
         $groupId = $queryParameters['group'];
         unset($queryParameters['group']);
         $members = Member::whereHas('groups', function ($query) use($groupId) {
             $query->where('group_id', $groupId);
         });
     }
     $members->where($queryParameters);
     return response()->json($members->paginate());
 }
示例#2
0
 public function getToken(Request $request)
 {
     $this->validate($request, ['id' => 'required', 'provider' => 'required', 'secret' => 'required']);
     $queryParameters = $request->only(['id', 'provider', 'secret']);
     $id = $queryParameters['id'];
     $provider = $queryParameters['provider'];
     $secret = $queryParameters['secret'];
     if (!in_array($secret, config('auth.secrets'))) {
         return new JsonResponse(['error' => 'invalid secret'], Response::HTTP_FORBIDDEN);
     }
     $member = Member::whereHas('externalProfiles', function ($query) use($id, $provider) {
         $query->where('identifier', $id);
         $query->where('provider', $provider);
     });
     try {
         $member = $member->firstOrFail();
         $token = JWTAuth::fromUser($member, ['level' => config('auth.levels.low'), 'member' => $member]);
         return response()->json(['token' => $token]);
     } catch (ModelNotFoundException $e) {
         return new JsonResponse(['error' => 'not found'], Response::HTTP_NOT_FOUND);
     }
 }