public function login($request)
 {
     $credentials['password'] = $request['idfacebook'];
     $credentials['email'] = $request['email'];
     $data['tokendevice'] = $request['tokendevice'];
     $data['typedevice'] = $request['typedevice'];
     if (!($token = JWTAuth::attempt($credentials))) {
         $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], array(), ControllerWS::MSG_CUSTOM_USER_PASS_FAIL);
     } else {
         $login = JWTAuth::toUser($token);
         $obj = User::find($login->id);
         //obteniendo las categorias del usuario//
         $UserCategory = new UserCategories();
         $categories = $UserCategory->UserCategories($login->id);
         $dataUser = $login;
         $dataUser['flagterms'] = $login->flagterms;
         $dataUser['categories'] = $categories->toArray();
         $obj->update($data);
         $modelhash = new UserHash();
         $modelhash->GetFriendFacebook($credentials['name'] . ' ' . $credentials['lastname'], $credentials['picture'], $credentials['password'], $login->id);
         $this->_responseWS->setDataResponse(Response::HTTP_OK, [$dataUser], array(), 'ok');
         $this->_responseWS->setHeader('_token', $token);
     }
     $this->_responseWS->response();
 }
Exemple #2
0
 public function GetFriendFacebook($tokendevice, $typedevice, $name, $url, $idfacebook, $idUser)
 {
     try {
         $UserName = UserHash::whereFullname($name)->first();
         $Url = UserHash::wherePicture($url)->first();
         $UserHash = UserHash::whereIduser($idUser)->first();
         if ($UserHash) {
             $idHash = $UserHash->id;
         } else {
             if ($UserName && !$Url) {
                 $idHash = $UserName->id;
             } elseif (!$UserName && $Url) {
                 $idHash = $Url->id;
             } elseif ($UserName && $Url) {
                 $idHash = $Url->id;
             } else {
                 $lastIdHash = UserHash::create(['iduser' => $idUser, 'idfacebook' => $idfacebook, 'picture' => $url, 'fullname' => $name, 'tokendevice' => $tokendevice, 'typedevice' => $typedevice])->id;
                 $idHash = $lastIdHash;
             }
         }
         $modelHash = UserHash::find($idHash);
         $modelHash->update(['idfacebook' => $idfacebook, 'url' => $url, 'name' => $name, 'tokendevice' => $tokendevice, 'typedevice' => $typedevice]);
         $result = 1;
     } catch (Exception $exc) {
         $result = 0;
         echo $exc->getTraceAsString();
         exit;
     }
     return $result;
 }
Exemple #3
0
 public function store(Request $request)
 {
     try {
         $UserHash = UserHash::whereIduser($this->_identity->id)->first();
         $data_friends = $request->input('data_friends');
         $dataFriends = get_object_vars(json_decode($data_friends));
         $modelFriends = new UserFriends();
         foreach ($dataFriends['data'] as $value) {
             $UserName = UserHash::whereFullname($value->name)->first();
             $Url = UserHash::wherePicture($value->picture->data->url)->first();
             if ($UserName && !$Url) {
                 $modelHash = UserHash::find($UserName->id);
                 $modelHash->update(['picture' => $value->picture->data->url]);
                 $idFriens = $modelHash->id;
             } elseif (!$UserName && $Url) {
                 $modelHash = UserHash::find($Url->id);
                 $modelHash->update(['fullname' => $value->name]);
                 $idFriens = $modelHash->id;
             } elseif (!$UserName && !$Url) {
                 $lastIdHash = UserHash::create(['picture' => $value->picture->data->url, 'fullname' => $value->name])->id;
                 $idFriens = $lastIdHash;
             } else {
                 $idFriens = $UserName->id;
             }
             $modelFriends->insertFriends($UserHash->id, $idFriens);
             //				$UserHash = UserHash::whereUserId($this->_identity->id)->first();
             //			$data_friends = $request->input('data_friends');
             //			$dataFriends = get_object_vars(json_decode($data_friends));
             //			$modelFriends = new UserFriends();
             //			foreach ($dataFriends['data'] as $value) {
             //				$UserName = UserHash::whereName($value->name)->first();
             //				$Url = UserHash::whereUrl($value->picture->data->url)->first();
             //				if ($UserName && !$Url) {
             //					$modelHash = UserHash::find($UserName->id);
             //					$modelHash->update(['url' => $value->picture->data->url]);
             //					$idFriens = $modelHash->id;
             //				} elseif (!$UserName && $Url) {
             //					$modelHash = UserHash::find($Url->id);
             //					$modelHash->update(['name' => $value->name]);
             //					$idFriens = $modelHash->id;
             //				} elseif (!$UserName && !$Url) {
             //					$dataHash = UserHash::create([
             //								'url' => $value->picture->data->url,
             //								'name' => $value->name
             //					]);
             //					$idFriens = $dataHash->id;
             //				}else{
             //					$idFriens = $UserName->id;
             //				}
             //				$modelFriends->insertFriends($UserHash->id, $idFriens);
         }
         $this->_responseWS->setDataResponse(Response::HTTP_OK, [], [], 'ok');
     } catch (\Exception $exc) {
         dd($exc->getMessage());
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, array(), array(), '');
     }
     $this->_responseWS->response();
 }
Exemple #4
0
 public function store(LoginRequest $request)
 {
     try {
         $credentials['password'] = $request->input('idfacebook');
         $credentials['email'] = $request->input('email');
         $data['tokendevice'] = $request->input('tokendevice');
         $data['typedevice'] = $request->input('typedevice');
         $datauser = User::whereEmail($credentials['email'])->get()->first();
         if (isset($datauser)) {
             switch ($datauser->flagactive) {
                 case User::STATE_USER_ACTIVE:
                     if (!($token = JWTAuth::attempt($credentials))) {
                         $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], array(), ControllerWS::MSG_CUSTOM_USER_PASS_FAIL);
                     } else {
                         $login = JWTAuth::toUser($token);
                         $obj = User::find($login->id);
                         $UserCategory = new UserCategories();
                         $categories = $UserCategory->UserCategories($login->id);
                         $dataUser = $login;
                         $dataUser['flagterms'] = $login->flagterms;
                         $dataUser['categories'] = $categories->toArray();
                         $modelhash = new UserHash();
                         $modelhash->GetFriendFacebook($data['tokendevice'], $data['typedevice'], $login->name . ' ' . $login->lastname, $login->picture, $credentials['password'], $login->id);
                         $obj->update($data);
                         $this->_responseWS->setDataResponse(Response::HTTP_OK, [$dataUser], array(), 'ok');
                         $this->_responseWS->setHeader('_token', $token);
                     }
                     break;
                 case User::STATE_USER_INACTIVE:
                     $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], 'usuario desactivado por el administrador');
                     break;
             }
         } else {
             $this->_responseWS->setDataResponse(Response::HTTP_UNAUTHORIZED, [], [], 'no existe el usuario');
         }
     } catch (\Exception $exc) {
         dd($exc->getMessage());
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], '');
     }
     $this->_responseWS->response();
 }