示例#1
0
 /**
  * @NoAdminRequired
  *
  * @param array $crop
  * @return DataResponse
  */
 public function postCroppedAvatar($crop)
 {
     $userId = $this->userSession->getUser()->getUID();
     if (is_null($crop)) {
         return new DataResponse(['data' => ['message' => $this->l->t("No crop data provided")]], Http::STATUS_BAD_REQUEST);
     }
     if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) {
         return new DataResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], Http::STATUS_BAD_REQUEST);
     }
     $tmpAvatar = $this->cache->get('tmpAvatar');
     if (is_null($tmpAvatar)) {
         return new DataResponse(['data' => ['message' => $this->l->t("No temporary profile picture available, try again")]], Http::STATUS_BAD_REQUEST);
     }
     $image = new \OC_Image($tmpAvatar);
     $image->crop($crop['x'], $crop['y'], round($crop['w']), round($crop['h']));
     try {
         $avatar = $this->avatarManager->getAvatar($userId);
         $avatar->set($image);
         // Clean up
         $this->cache->remove('tmpAvatar');
         return new DataResponse(['status' => 'success']);
     } catch (\OC\NotSquareException $e) {
         return new DataResponse(['data' => ['message' => $this->l->t('Crop is not square')]], Http::STATUS_BAD_REQUEST);
     } catch (\Exception $e) {
         return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_BAD_REQUEST);
     }
 }
示例#2
0
 /**
  * Get a value from the user cache
  *
  * @param string $key
  * @return mixed
  */
 public function get($key)
 {
     return $this->userCache->get($key);
 }