예제 #1
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param \Illuminate\Routing\Router $router
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('apikeys', function ($value) {
         return ApiKey::whereId($value)->where('user_id', auth()->id())->firstOrFail();
     });
 }
예제 #2
0
 /**
  * Return User associated with APIKey.
  *
  * @param string $key
  *
  * @return Screeenly\User
  */
 public static function getUserByKey($key)
 {
     // Search for key in ApiKey Model
     $apiKey = ApiKey::whereKey($key)->first();
     if ($apiKey) {
         return $apiKey->user;
     }
 }
예제 #3
0
 /**
  * Migrate Users API Key to it's own model
  *
  * - Create new Model
  * - Delete old value
  *
  * @param  User   $user
  * @return void
  */
 protected function migrateUser(User $user)
 {
     $apiKey = $user->api_key;
     $newKey = new ApiKey();
     $newKey->key = $apiKey;
     $newKey->name = 'Default key';
     $newKey->user_id = $user->id;
     $newKey->save();
     $newKey->user()->associate($user);
     $newKey->save();
     // $newKey = ApiKey::create([
     //     'key'     => $apiKey,
     //     'user_id' => $user->id,
     //     'name'    => 'Default key'
     // ]);
     $user->api_key = "key-deleted-" . str_random(10);
     $user->save();
 }
예제 #4
0
 /**
  * Set Api Key
  * @param mixed (string|null) $key
  */
 public function setKey($key)
 {
     if (!is_null($key)) {
         $key = $this->apiKey->whereKey($key)->first();
         if (!$key) {
             throw new InvalidApiKeyException("The API Key {$key} is invalid.", 401);
         }
     }
     return $this->key = $key;
 }
예제 #5
0
 public static function store(Screenshot $screenshot, User $user)
 {
     $key = \Input::get('key', null);
     $apiKey = ApiKey::whereKey($key)->first();
     $log = new self();
     $log->images = $screenshot->storagePath;
     $log->user()->associate($user);
     if (!is_null($apiKey)) {
         $log->apiKey()->associate($apiKey);
     }
     $log->save();
     return $log;
 }
예제 #6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  ApiKey $apikey
  * @return Response
  */
 public function destroy(ApiKey $apikey)
 {
     $apikey->delete();
     return redirect()->back()->withMessage("API Key deleted");
 }