/**
  * Function to create other avatar for user
  * @param  Request $request
  * @return $user
  */
 public function postAvatar(Request $request)
 {
     //Rules for server sides validations
     $rules = ['avatar' => ['required']];
     $data = $request->all();
     $validator = app('validator')->make($data, $rules);
     if ($validator->fails()) {
         throw new DingoException\StoreResourceFailedException('Could not Update user', $validator->errors());
     }
     //Check if token is valid
     $user = JWTAuth::parseToken()->authenticate();
     if (!$user) {
         throw new Exceptions\AccessDeniedHttpException('Invalid Credentials');
     }
     $avatars = MyImage::uploadAvatarBase64();
     MyImage::deleteAvatar($user->avatar_standar);
     MyImage::deleteAvatar($user->avatar_thumbnail);
     $user->avatar_standar = $avatars['avatar_standar'];
     $user->avatar_thumbnail = $avatars['avatar_thumbnail'];
     $user->save();
     $token = JWTAuth::fromUser($user);
     $user = $user->toArray();
     $user['token'] = $token;
     return $user;
 }
 /**
  * Function to add avatar to user
  * @param  RequestHttp $request
  * @return array
  */
 public function postAvatar(RequestHttp $request)
 {
     // Rules for server side validations
     $this->validate($request, ['avatar' => 'required|image|mimes:jpeg,png,gif']);
     $user = User::where('id', '=', Auth::user()->id)->first();
     if (!$user) {
         return response()->json(['error' => ['message' => 'User Not Found']], 404);
     }
     $avatars = MyImage::uploadAvatar();
     MyImage::deleteAvatar($user->avatar_standar);
     MyImage::deleteAvatar($user->avatar_thumbnail);
     $user->avatar_standar = $avatars['avatar_standar'];
     $user->avatar_thumbnail = $avatars['avatar_thumbnail'];
     $user->save();
     return response()->json(['success' => ['response' => $avatars]], 200);
 }
 public function checkIfUserNeedsUpdatingFromApp($userData, $user)
 {
     $dbData = ['provider_id' => $user->provider_id, 'avatar_standar' => $user->avatar_standar, 'avatar_thumbnail' => $user->avatar_thumbnail, 'email' => $user->email, 'first_name' => $user->first_name, 'last_name' => $user->last_name];
     if (!empty(array_diff($userData, $dbData))) {
         MyImage::deleteAvatar($user->avatar_standar);
         MyImage::deleteAvatar($user->avatar_thumbnail);
         $user->avatar_standar = $userData['avatar_standar'];
         $user->avatar_thumbnail = $userData['avatar_thumbnail'];
         $user->email = $userData['email'];
         $user->first_name = $userData['first_name'];
         $user->last_name = $userData['last_name'];
         $user->is_verify = 1;
         $user->verified_code = null;
         $user->provider_id = $userData['provider_id'];
         $user->save();
     }
 }
Beispiel #4
0
 public static function uploadAvatarBase64()
 {
     $tmp_archivo = file_get_contents(Request::input('avatar'));
     $lienzo_ancho = 150;
     $lienzo_alto = 150;
     $info_imagen = getimagesizefromstring($tmp_archivo);
     $imagen_ancho = $info_imagen[0];
     $imagen_alto = $info_imagen[1];
     $imagen = imagecreatefromstring($tmp_archivo);
     $lienzo = imagecreatetruecolor($lienzo_ancho, $lienzo_alto);
     $blanco = imagecolorallocate($lienzo, 155, 155, 155);
     imagefill($lienzo, 0, 0, $blanco);
     if ($imagen_ancho >= $imagen_alto) {
         //imagen horizontal
         $imagen_inicio_ancho = $imagen_ancho / 2 - $imagen_alto / 2;
         $imagen_inicio_alto = 0;
         $imagen_nuevo_ancho = $imagen_alto;
         $imagen_nuevo_alto = $imagen_alto;
     } else {
         //imagen vertical
         $imagen_inicio_ancho = 0;
         $imagen_inicio_alto = $imagen_alto / 2 - $imagen_ancho / 2;
         $imagen_nuevo_ancho = $imagen_ancho;
         $imagen_nuevo_alto = $imagen_ancho;
     }
     imagecopyresampled($lienzo, $imagen, 0, 0, $imagen_inicio_ancho, $imagen_inicio_alto, $lienzo_ancho, $lienzo_alto, $imagen_nuevo_ancho, $imagen_nuevo_alto);
     $imageName = MyImage::tempnamSfx(sys_get_temp_dir(), "jpg");
     imagejpeg($lienzo, $imageName, 100);
     MyImage::createThumb($imageName);
     /*$nameThumb = MyImage::nameThumb($imageName);
             $handle = fopen($imageName, "r");
             $data = fread($handle, filesize($imageName));
             $headers = array('Authorization: Client-ID ' . env('IMGUR_CLIENT_ID'));
             $postFields = array('image' => base64_encode($data));
     
             $dataImage = MyCurl::sendPost(env('IMGUR_UPLOAD_IMAGE_ENDPOINT'), $postFields, $headers);
     
             $handle = fopen($nameThumb, "r");
             $data = fread($handle, filesize($nameThumb));
             $headers = array('Authorization: Client-ID ' . env('IMGUR_CLIENT_ID'));
             $postFields = array('image' => base64_encode($data));
     
             $dataThumb = MyCurl::sendPost(env('IMGUR_URL_UPLOAD_IMAGE'), $postFields, $headers);*/
     return MyImage::moveAvatars($imageName);
 }