diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/Claim.java b/Entangle/entangle-android/src/com/megasoft/entangle/Claim.java index 38bf216f..0d7b4038 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/Claim.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/Claim.java @@ -74,7 +74,7 @@ public void sendClaimForm(View view) { mssgBody = ((EditText) findViewById(R.id.mssgText)).getText() .toString(); if (mssgBody.equals("")) { - Toast.makeText(this, "Msssg body missing", Toast.LENGTH_LONG) + Toast.makeText(this, "Message body missing", Toast.LENGTH_LONG) .show(); } else { @@ -102,7 +102,7 @@ protected void onPostExecute(String response) { intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { - Toast.makeText(getBaseContext(), "Something went wrong", + Toast.makeText(getBaseContext(), this.getErrorMessage(), Toast.LENGTH_SHORT).show(); } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/CreateOfferActivity.java b/Entangle/entangle-android/src/com/megasoft/entangle/CreateOfferActivity.java index 3798d513..d223d30f 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/CreateOfferActivity.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/CreateOfferActivity.java @@ -189,7 +189,7 @@ protected void onPostExecute(String response) { } else { Toast.makeText(getApplicationContext(), - "Error, Can not create offer", + this.getErrorMessage(), Toast.LENGTH_SHORT).show(); } } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/CreateRequestActivity.java b/Entangle/entangle-android/src/com/megasoft/entangle/CreateRequestActivity.java index 2bf42d90..4c1b01d8 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/CreateRequestActivity.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/CreateRequestActivity.java @@ -201,7 +201,7 @@ protected void onPostExecute(String response) { finish(); } else { Toast.makeText(getApplicationContext(), - "Error, Can not create request", + this.getErrorMessage(), Toast.LENGTH_SHORT).show(); } } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/CreateTangleActivity.java b/Entangle/entangle-android/src/com/megasoft/entangle/CreateTangleActivity.java index 99e56914..ac9c56d0 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/CreateTangleActivity.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/CreateTangleActivity.java @@ -180,7 +180,7 @@ protected void onPostExecute(String response) { } else { if (!(this.getStatusCode() == 201)) { Toast.makeText(getApplicationContext(), - "Try Again Later"+this.getStatusCode(), Toast.LENGTH_LONG).show(); + this.getErrorMessage(), Toast.LENGTH_LONG).show(); } else { goToHomePage(); } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/DeleteButtonFragment.java b/Entangle/entangle-android/src/com/megasoft/entangle/DeleteButtonFragment.java index 81f09fb5..ef11ab79 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/DeleteButtonFragment.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/DeleteButtonFragment.java @@ -90,7 +90,7 @@ else if(getResourceType().equals(Config.OFFER_TYPE)){ DeleteRequest deleteRequest = new DeleteRequest(url){ protected void onPostExecute(String res) { - String message = "Sorry, there are problems in the delete process. Please, try again later"; + String message = this.getErrorMessage(); if (!this.hasError() && res != null) { message = "Deleted!"; diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/MemberListFragment.java b/Entangle/entangle-android/src/com/megasoft/entangle/MemberListFragment.java index b2ae9d8e..0881849a 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/MemberListFragment.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/MemberListFragment.java @@ -177,10 +177,10 @@ public void onPostExecute(String response) { if (!this.hasError() && this.getStatusCode() == 200) { if (!showData(response)) { - toasterShow("Something went wrong, please try again later"); + toasterShow(this.getErrorMessage()); } } else { - toasterShow("Something went wrong, please try again later"); + toasterShow(this.getErrorMessage()); } } }; diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/OfferActivity.java b/Entangle/entangle-android/src/com/megasoft/entangle/OfferActivity.java index 5f069201..c1557372 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/OfferActivity.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/OfferActivity.java @@ -432,7 +432,7 @@ protected void onPostExecute(String response) { } } else { Toast toast = Toast.makeText(getApplicationContext(), - getString(R.string.toastError), + this.getErrorMessage(), Toast.LENGTH_SHORT); toast.show(); } @@ -467,6 +467,9 @@ public void onClick(View v) { + ACCEPT) { protected void onPostExecute(String response) { status = this.getStatusCode(); + String responseMessage = this.getErrorMessage(); + + String errorMessage = this.getErrorMessage(); if (status == 201) { acceptOffer.setVisibility(View.INVISIBLE); offerStatus.setText("Accepted"); @@ -478,14 +481,13 @@ protected void onPostExecute(String response) { if (status == 405) { Toast toast = Toast .makeText( - getApplicationContext(), - getString(R.string.balanceInsufficient), + getApplicationContext(),this.getErrorMessage(), Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast.makeText( getApplicationContext(), - getString(R.string.toastError), + this.getErrorMessage(), Toast.LENGTH_SHORT); toast.show(); } @@ -555,14 +557,14 @@ public void markAsDone(int Offerid) { protected void onPostExecute(String response) { if (this.getStatusCode() == 201) { Toast success = Toast.makeText(getApplicationContext(), - R.string.mark, Toast.LENGTH_LONG); + this.getErrorMessage(), Toast.LENGTH_LONG); success.show(); markOfferAsDone.setEnabled(false); markOfferAsDone.setVisibility(View.INVISIBLE); offerStatus.setText("Done"); } else { Toast error = Toast.makeText(getApplicationContext(), - R.string.error, Toast.LENGTH_LONG); + this.getErrorMessage(), Toast.LENGTH_LONG); error.show(); } } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/ProfileFragment.java b/Entangle/entangle-android/src/com/megasoft/entangle/ProfileFragment.java index 33bef8ff..02933b0e 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/ProfileFragment.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/ProfileFragment.java @@ -131,7 +131,7 @@ protected void onPostExecute(String response) { } } else { Log.e("test", this.getErrorMessage()); - Toast toast = Toast.makeText(activity.getApplicationContext(),"Some error happened.",Toast.LENGTH_SHORT); + Toast toast = Toast.makeText(activity.getApplicationContext(),this.getErrorMessage(),Toast.LENGTH_SHORT); toast.show(); } } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/RegisterActivity.java b/Entangle/entangle-android/src/com/megasoft/entangle/RegisterActivity.java index d30b8122..d2de8df8 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/RegisterActivity.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/RegisterActivity.java @@ -94,13 +94,13 @@ protected void onPostExecute(String response) { goToLogin(response); } else if(this.getStatusCode() == 401){ Toast.makeText(getApplicationContext(), - "Not unique username", + this.getErrorMessage(), Toast.LENGTH_SHORT).show(); } else if(this.getStatusCode() == 402){ Toast.makeText(getApplicationContext(), - "Not unique email", + this.getErrorMessage(), Toast.LENGTH_SHORT).show(); } diff --git a/Entangle/entangle-android/src/com/megasoft/entangle/Request.java b/Entangle/entangle-android/src/com/megasoft/entangle/Request.java index 22e1f400..52418143 100644 --- a/Entangle/entangle-android/src/com/megasoft/entangle/Request.java +++ b/Entangle/entangle-android/src/com/megasoft/entangle/Request.java @@ -65,7 +65,7 @@ protected void onPostExecute(String response) { Toast.makeText(getBaseContext(), "Loading Claim Form", Toast.LENGTH_SHORT).show(); startActivity(intent); } else { - Toast.makeText(getBaseContext(), "Something went wrong", Toast.LENGTH_SHORT).show(); + Toast.makeText(getBaseContext(), this.getErrorMessage(), Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { diff --git a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/CreateOfferController.php b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/CreateOfferController.php index 667ad97c..3b59fb88 100644 --- a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/CreateOfferController.php +++ b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/CreateOfferController.php @@ -33,14 +33,14 @@ public function createOfferAction(Request $request, $tangleId, $requestId) $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { $response->setStatusCode(400); - $response->setContent("bad request"); + $response->setContent("Please login again"); return $response; } $sessionTable = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionTable->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired() == true) { $response->setStatusCode(401); - $response->setContent("Unauthorized"); + $response->setContent("Please login again"); return $response; } $userTable = $doctrine->getRepository('MegasoftEntangleBundle:User'); @@ -56,7 +56,7 @@ public function createOfferAction(Request $request, $tangleId, $requestId) $previousOffer = $offerTable->findOneBy(array('userId' => $userId, 'requestId' => $theRequestId)); if ($previousOffer != null) { $response->setStatusCode(401); - $response->setContent("Unauthorized"); + $response->setContent("You have already made an offer on this request"); return $response; } $description = $json_array['description']; @@ -113,26 +113,29 @@ public function validate($theRequestId, $tangle, $sessionId, $session, $deadLine { $response = new JsonResponse(); if ($sessionId == null) { + $response->setContent("Please login again"); $response->setStatusCode(400); return $response; } if ($session == null || $session->getExpired() == true) { + $response->setContent("Please login again"); $response->setStatusCode(401); return $response; } if ($tangleRequest == null) { $response->setStatusCode(400); - $response->setContent("no such request"); + $response->setContent("No such request"); return $response; } if ($tangle == null || $user == null) { + $response->setContent("Please choose a tangle, or user Id"); $response->setStatusCode(401); return $response; } if ($tangle->getDeleted() == true) { $response->setStatusCode(401); - $response->setContent("tangle is deleted"); + $response->setContent("Tangle has been deleted"); return $response; } $tangleUsers = $tangle->getUsers(); @@ -147,7 +150,7 @@ public function validate($theRequestId, $tangle, $sessionId, $session, $deadLine } if (!$userIsMember) { $response->setStatusCode(401); - $response->setContent("User is not a member in the tangle"); + $response->setContent("User is not a member of this tangle"); return $response; } $tangleRequests = $tangle->getRequests(); @@ -161,38 +164,38 @@ public function validate($theRequestId, $tangle, $sessionId, $session, $deadLine } if (!$requestBelongToTangle) { $response->setStatusCode(401); - $response->setContent("Request doesn't belong to tangle"); + $response->setContent("This request doesn't belong to this tangle"); return $response; } if ($tangleRequest->getDeleted()) { $response->setStatusCode(400); - $response->setContent("request is deleted"); + $response->setContent("This request has been deleted"); return $response; } if ($tangleRequest->getStatus() == $tangleRequest->CLOSE || $tangleRequest->getStatus() == $tangleRequest->FROZEN) { $response->setStatusCode(400); - $response->setContent("can not create offer on this request"); + $response->setContent("An offer has already been accepted for this request"); return $response; } if ($tangleRequest->getUserId() == $userId) { $response->setStatusCode(400); - $response->setContent("can not create offer on your request"); + $response->setContent("You can not create an offer on your own request"); return $response; } if ($description == null || $date == null || $requestedPrice == null) { $response->setStatusCode(400); - $response->setContent("some data are missing"); + $response->setContent("Please enter all fields"); return $response; } if ($deadLineFormated->format("Y-m-d") < $dateFormated->format("Y-m-d")) { $response->setStatusCode(400); - $response->setContent("deadline has passed!"); + $response->setContent("This deadline has passed, please enter a valid date"); return $response; } if ($requestedPrice < 0) { $response->setStatusCode(400); - $response->setContent("price must be a positive value!"); + $response->setContent("Please enter a postitive value"); return $response; } diff --git a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/OfferController.php b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/OfferController.php index dc789049..d824ee00 100644 --- a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/OfferController.php +++ b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/OfferController.php @@ -57,13 +57,13 @@ public function offerAction (\Symfony\Component\HttpFoundation\Request $req, $offerId) { $sessionId = $req->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $doctrine = $this->getDoctrine(); $sessionTable = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionTable->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $offerTable = $doctrine->getRepository('MegasoftEntangleBundle:Offer'); $offer = $offerTable->findOneBy(array('id' => $offerId)); @@ -162,44 +162,44 @@ public function changeOfferPriceAction(Request $request, $offerid) { $sesionRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Session'); $session = $sesionRepo->findOneBy(array('sessionId' => $sessionId)); if ($sessionId == null) { - return new Response("Bad meh Request", 400); + return new Response("Please login again", 400); } if ($session == null) { - return new Response("Unauthorized", 401); + return new Response("Please login again", 401); } $sessionExpired = $session->getExpired(); if ($sessionExpired) { - return new Response("Session expired", 440); + return new Response("Please login again", 440); } $offerRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Offer'); $requestOffer = $offerRepo->findOneBy(array('id' => $offerid)); $oldPrice = $requestOffer->getRequestedPrice(); if ($requestOffer == null) { - return new Response("Not found", 404); + return new Response("No such offer", 404); } if (($session->getUserId()) != ($requestOffer->getUserId())) { - return new Response("Unauthorized", 401); + return new Response("You are unauthorized to change this offer", 401); } if (($requestOffer->getStatus()) == ($requestOffer->ACCEPTED)) { - return new Response("Offer is already accepted", 403); + return new Response("Offer has already been accepted", 403); } if (($requestOffer->getStatus()) == ($requestOffer->DONE)) { - return new Response("Offer is already done", 403); + return new Response("Offer has already been done", 403); } if (($requestOffer->getStatus()) == ($requestOffer->FAILED)) { - return new Response("Offer is already failed", 403); + return new Response("Offer has already been failed", 403); } if (($requestOffer->getStatus()) == ($requestOffer->REJECTED)) { - return new Response("Offer is already rejected", 403); + return new Response("Offer has already been rejected", 403); } $json = $request->getContent(); $json_array = json_decode($json, true); $newOfferPrice = $json_array['newPrice']; if ($newOfferPrice == null) { - return new Response("Bad Request", 400); + return new Response("Please enter a new price", 400); } if (($requestOffer->getRequestedPrice()) == $newOfferPrice) { - return new Response("Same price, enter a new one", 400); + return new Response("This is the same price, please enter a new price", 400); } $requestOffer->setRequestedPrice($newOfferPrice); @@ -218,7 +218,7 @@ public function changeOfferPriceAction(Request $request, $offerid) { $this->getDoctrine()->getManager()->persist($requestOffer); $this->getDoctrine()->getManager()->flush(); - return new Response('Price changed', 200); + return new Response('Price changed successfully', 200); } /** @@ -232,26 +232,26 @@ public function acceptOfferAction(\Symfony\Component\HttpFoundation\Request $req $json = $request->getContent(); $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return $response = new Response("No Session Id.", 400); + return $response = new Response("Please login again", 400); } $sessionRepo = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null) { - return $response = new Response("Error: Incorrect Session Id.", 400); + return $response = new Response("Please login again", 400); } if ($session->getExpired() == 1) { - return $response = new Response("Error: Session Expired.", 401); + return $response = new Response("Please login again", 401); } $userOfSession = $session->getUserId(); $json_array = json_decode($json, true); $offerId = $json_array['offerId']; if ($offerId == null) { - return $response = new Response("Error: No offer selected.", 400); + return $response = new Response("Please select an offer", 400); } $offerRepo = $doctrine->getRepository('MegasoftEntangleBundle:Offer'); $offer = $offerRepo->findOneBy(array('id' => $offerId)); if ($offer == null) { - return $response = new Response("Error: No such offer.", 404); + return $response = new Response("No such offer exists", 404); } $requestId = $offer->getRequestId(); $requestRepo = $doctrine->getRepository('MegasoftEntangleBundle:Request'); @@ -259,13 +259,13 @@ public function acceptOfferAction(\Symfony\Component\HttpFoundation\Request $req $requesterId = $request->getUserId(); $tangle = $request->getTangleId(); if ($requesterId != $userOfSession) { - return $response = new Response("Error: You are unauthorized to accept this offer.", 409); + return $response = new Response("You are unauthorized to accept this offer", 409); } $verificationMessage = $this->verify($offerId); - if ($verificationMessage == "Offer Accepted.") { + if ($verificationMessage == "Offer Accepted") { $response = new Response($verificationMessage, 201); } else { - if ($verificationMessage == "Error: Not enough balance.") { + if ($verificationMessage == "You do not have enough balance to accept this offer") { $response = new Response($verificationMessage, 405); } else { $response = new Response($verificationMessage, 401); @@ -286,7 +286,7 @@ public function verify($offerId) { $offerRepo = $doctrine->getRepository('MegasoftEntangleBundle:Offer'); $offer = $offerRepo->findOneBy(array('id' => $offerId,)); if (count($offer) <= 0) { - return "Error: No such offer."; + return "No such offer"; } $requestId = $offer->getRequestId(); $requestRepo = $doctrine->getRepository('MegasoftEntangleBundle:Request'); @@ -296,25 +296,25 @@ public function verify($offerId) { $userTangle = $doctrine->getRepository('MegasoftEntangleBundle:UserTangle'); $requester = $userTangle->findOneBy(array('tangleId' => $tangleId, 'userId' => $requesterId,)); if (count($requester) <= 0) { - return "Error: You don't belong to this tangle."; + return "You don't belong to this tangle"; } if ($request->getDeleted() == 1) { - return "Error: Request deleted."; + return "This request has been deleted"; } if ($request->getStatus() == $request->CLOSE) { - return "Error: Request Closed."; + return "This request has been closed"; } if ($request->getStatus() == $request->FROZEN) { - return "Error: Request is Frozen."; + return "This request has been frozen"; } if ($offer->getDeleted() == 1) { - return "Error: Offer deleted."; + return "This offer has been deleted"; } if ($offer->getStatus() == $offer->DONE || $offer->getStatus() == $offer->ACCEPTED) { - return "Error: Offer has already been accepted."; + return "This offer has already been accepted"; } if ($offer->getStatus() == $offer->FAILED || $offer->getStatus() == $offer->REJECTED) { - return "Error: Offer closed."; + return "This offer has been failed or rejected"; } $price = $offer->getRequestedPrice(); $requesterBalance = $requester->getCredit(); @@ -349,7 +349,7 @@ public function withdrawAction(Request $request, $offerId) { $sessionId = $request->headers->get('X-SESSION-ID'); if ($offerId == null || $sessionId == null) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $doctrine = $this->getDoctrine(); @@ -357,7 +357,7 @@ public function withdrawAction(Request $request, $offerId) { $sessionRepo = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $offererId = $session->getUserId(); @@ -365,7 +365,7 @@ public function withdrawAction(Request $request, $offerId) { $offerRepo = $doctrine->getRepository('MegasoftEntangleBundle:Offer'); $offer = $offerRepo->findOneBy(array('id' => $offerId)); if ($offer == null || $offer->getUserId() != $offererId || $offer->getDeleted()) { - return new Response('Unauthorized', 401); + return new Response('You can not delete this offer', 401); } if ($offer->getStatus() == $offer->ACCEPTED) { @@ -422,9 +422,12 @@ private function verifyUser($request, $offerId) { $jsonString = $request->getContent(); $json = json_decode($jsonString, true); + if ($sessionId == null) { + return new Response('Please login again', 400); + } - if ($offerId == null || $sessionId == null || $json['body'] == null) { - return new Response('Bad Request', 400); + if ($offerId == null || $json['body'] == null) { + return new Response('Please select an offer', 400); } $doctrine = $this->getDoctrine(); @@ -432,7 +435,7 @@ private function verifyUser($request, $offerId) { $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $offerRepo = $doctrine->getRepository('MegasoftEntangleBundle:Offer'); @@ -448,7 +451,7 @@ private function verifyUser($request, $offerId) { if ($userTangle == null) { - return new Response('Unauthorized', 401); + return new Response('You do not belong to this tangle', 401); } return null; @@ -505,7 +508,7 @@ public function commentAction(Request $request, $offerId) { public function updateAction($offerid, \Symfony\Component\HttpFoundation\Request $request) { $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $doctrine = $this->getDoctrine(); $requestTable = $doctrine->getRepository('MegasoftEntangleBundle:Request'); @@ -515,41 +518,41 @@ public function updateAction($offerid, \Symfony\Component\HttpFoundation\Request $requestid = $offer->getRequestId(); $testrequest = $requestTable->find($requestid); if ($testrequest == null) { - return new Response('Request does not exist', 401); + return new Response('This request does not exist', 401); } $sessionTable = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionTable->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $userOfSession = $session->getUserId(); if ($testrequest->getDeleted()) { return new Response('This request does not exist anymore', 401); } if ($testrequest->getStatus() == $testrequest->CLOSE) { - return new Response('Request is closed', 401); + return new Response('This request has been closed', 401); } if ($offer == null) { - return new Response('Offer does not exist', 401); + return new Response('This offer does not exist', 401); } if ($testrequest->getId() != $offer->getRequest()->getId()) { - return new Response('Error', 401); + return new Response('You are unauthorized to perform this action', 401); } $status = $offer->DONE; $request = $offer->getRequest(); $requesterId = $request->getUserId(); if ($requesterId != $userOfSession) { - return new Response("Error: You are unauthorized to mark this offer as done.", 409); + return new Response('You are unauthorized to perform this action', 409); } $backendstatus = $offer->getStatus(); if ($backendstatus == $offer->DONE) { - return new JsonResponse("Offer already marked as done", 401); + return new JsonResponse("This offer has already been marked as done", 401); } else if ($backendstatus == $offer->PENDING) { - return new JsonResponse("Offer is not accepted", 401); + return new JsonResponse("This offer was not accepted", 401); } else if ($backendstatus == $offer->FAILED) { return new JsonResponse("This offer has failed", 401); } else if ($backendstatus == $offer->REJECTED) { - return new JsonResponse("This offer is rejected", 401); + return new JsonResponse("This offer has been rejected", 401); } else { $offer->setStatus($status); $this->getDoctrine()->getManager()->persist($offer); diff --git a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/RequestController.php b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/RequestController.php index faa79457..993814e9 100644 --- a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/RequestController.php +++ b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/RequestController.php @@ -52,8 +52,11 @@ public function postIconAction(Request2 $request, $requestId) { $sessionId = $request->headers->get('X-SESSION-ID'); + if ($sessionId == null) { + return new Response('Please login again', 400); + } if ($requestId == null || $sessionId == null) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $doctrine = $this->getDoctrine(); @@ -61,20 +64,20 @@ public function postIconAction(Request2 $request, $requestId) $sessionRepo = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $jsonString = $request->getContent(); if ($jsonString == null) { - return new Response('Bad Request', 400); + return new Response('Please choose an icon', 400); } $json = json_decode($jsonString, true); $iconData = $json['requestIcon']; if ($iconData == null) { - return new Response('Bad Request', 400); + return new Response('Please choose an icon', 400); } $requesterId = $session->getUserId(); @@ -82,7 +85,7 @@ public function postIconAction(Request2 $request, $requestId) $requestRepo = $doctrine->getRepository('MegasoftEntangleBundle:Request'); $request = $requestRepo->findOneBy(array('id' => $requestId)); if ($request == null || $request->getUserId() != $requesterId) { - return new Response('Unauthorized', 401); + return new Response('You are unauthorized to perform this action', 401); } try { @@ -113,19 +116,19 @@ public function reOpenRequestAction(Request2 $request, $requestId) $sesionRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Session'); $session = $sesionRepo->findOneBy(array('sessionId' => $sessionId)); if ($sessionId == null) { - return new Response("Bad Request", 400); + return new Response("Please login again", 400); } if ($session == null) { - return new Response("Unauthorized", 401); + return new Response("Please login again", 401); } $sessionExpired = $session->getExpired(); if ($sessionExpired) { - return new Response("Session expired", 440); + return new Response("Please login again", 440); } $requestRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Request'); $tangleRequest = $requestRepo->findOneBy(array('id' => $requestId)); if ($tangleRequest == null || $tangleRequest->getDeleted()) { - return new Response("Not Found", 404); + return new Response("Tangle not found", 404); } if ($tangleRequest->getStatus() == $tangleRequest->OPEN) { @@ -133,7 +136,7 @@ public function reOpenRequestAction(Request2 $request, $requestId) } if (($session->getUserId()) != ($tangleRequest->getUserId())) { - return new Response("Unauthorized", 401); + return new Response("You are unauthorized to perform this action", 401); } if ($tangleRequest->getStatus() == $tangleRequest->CLOSE) { $tangleRequest->setStatus($tangleRequest->OPEN); @@ -164,19 +167,19 @@ public function viewRequestAction($tangleId, $requestId, Request2 $request) $sessionId = $request->headers->get('X-SESSION-ID'); $response = new JsonResponse(); if ($sessionId == null) { - $response->setData(array('Error' => 'No session Id.')); + $response->setContent('Please Login again'); $response->setStatusCode(400); return $response; } $sessionRepo = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null) { - $response->setData(array('Error' => 'Incorrect Session Id.')); + $response->setContent('Please Login again'); $response->setStatusCode(400); return $response; } if ($session->getExpired() == 1) { - $response->setData(array('Error' => 'Session Expired.')); + $response->setContent('Please Login again'); $response->setStatusCode(400); return $response; } @@ -184,7 +187,7 @@ public function viewRequestAction($tangleId, $requestId, Request2 $request) $userTangle = $doctrine->getRepository('MegasoftEntangleBundle:UserTangle'); $viewer = $userTangle->findOneBy(array('tangleId' => $tangleId, 'userId' => $sessionUserId)); if (count($viewer) <= 0) { - $response->setData(array('Error' => 'You do not belong to this tangle.')); + $response->setContent('You do not belong to this tangle'); $response->setStatusCode(400); return $response; } @@ -192,7 +195,7 @@ public function viewRequestAction($tangleId, $requestId, Request2 $request) $requestDetails = $this->getRequestDetails($requestId, $sessionUserId, $tangleId); if (count($requestDetails) == 0) { - $response->setData(array('Error' => 'No such request.')); + $response->setContent('No such request'); $response->setStatusCode(400); return $response; } @@ -295,12 +298,12 @@ public function validate($sessionId, $session, $deadLineFormated, $dateFormated, $response = new JsonResponse(); if ($sessionId == null) { $response->setStatusCode(400); - $response->setContent("bad request"); + $response->setContent("Please login again"); return $response; } if ($session == null || $session->getExpired() == true) { $response->setStatusCode(401); - $response->setContent("Unauthorized"); + $response->setContent("Please login again"); return $response; } @@ -310,7 +313,7 @@ public function validate($sessionId, $session, $deadLineFormated, $dateFormated, } if ($tangle->getDeleted() == true) { $response->setStatusCode(401); - $response->setContent("tangle is deleted"); + $response->setContent("This tangle has been deleted"); return $response; } $tangleUsers = $tangle->getUsers(); @@ -325,12 +328,12 @@ public function validate($sessionId, $session, $deadLineFormated, $dateFormated, } if (!$userIsMember) { $response->setStatusCode(401); - $response->setContent("User is not a member in the tangle"); + $response->setContent("You do not belong to this tangle"); return $response; } if ($description == null || $date == null) { $response->setStatusCode(400); - $response->setContent("some data are missing"); + $response->setContent("Please enter all fields"); return $response; } if ($deadLineFormated != null) { @@ -342,7 +345,7 @@ public function validate($sessionId, $session, $deadLineFormated, $dateFormated, } if ($requestedPrice < 0) { $response->setStatusCode(400); - $response->setContent("price must be a positive value!"); + $response->setContent("Price must be a postive value"); return $response; } return null; @@ -365,7 +368,7 @@ public function createAction(Request2 $request, $tangleId) $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { $response->setStatusCode(400); - $response->setContent("bad request"); + $response->setContent("Please login again"); return $response; } @@ -375,7 +378,7 @@ public function createAction(Request2 $request, $tangleId) $session = $sessionTable->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired() == true) { $response->setStatusCode(401); - $response->setContent("Unauthorized"); + $response->setContent("Please login again"); return $response; } $userId = $session->getUserId(); @@ -453,7 +456,7 @@ public function deleteAction(Request2 $request, $requestId) $sessionId = $request->headers->get('X-SESSION-ID'); if ($requestId == null || $sessionId == null) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $doctrine = $this->getDoctrine(); @@ -461,7 +464,7 @@ public function deleteAction(Request2 $request, $requestId) $sessionRepo = $doctrine->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $requesterId = $session->getUserId(); @@ -469,7 +472,7 @@ public function deleteAction(Request2 $request, $requestId) $requestRepo = $doctrine->getRepository('MegasoftEntangleBundle:Request'); $request = $requestRepo->findOneBy(array('id' => $requestId)); if ($request == null || $request->getUserId() != $requesterId) { - return new Response('Unauthorized', 401); + return new Response('You are not authorized to delete this request', 401); } // notification diff --git a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/TangleController.php b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/TangleController.php index fb0ec0d5..39796957 100644 --- a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/TangleController.php +++ b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/TangleController.php @@ -28,7 +28,7 @@ private function verifyUser($request, $tangleId) { $sessionId = $request->headers->get('X-SESSION-ID'); if ($tangleId == null || $sessionId == null) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $doctrine = $this->getDoctrine(); @@ -36,7 +36,7 @@ private function verifyUser($request, $tangleId) { $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response('Bad Request', 400); + return new Response('Please login again', 400); } $user = $session->getUser(); @@ -44,7 +44,7 @@ private function verifyUser($request, $tangleId) { $userTangle = $userTangleRepo->findOneBy(array('tangleId' => $tangleId, 'userId' => $user->getId())); if ($userTangle == null) { - return new Response('Unauthorized', 401); + return new Response('You do not belong to this tangle', 401); } return null; @@ -269,7 +269,7 @@ public function inviteAction(Request $request, $tangleId) { $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return new Response("Bad Request", 400); + return new Response("Please login again", 400); } $sesionRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Session'); @@ -277,7 +277,7 @@ public function inviteAction(Request $request, $tangleId) { $session = $sesionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response("Unauthorized", 401); + return new Response("Please login again", 401); } if (!$this->validateTangleId($tangleId)) { @@ -287,7 +287,7 @@ public function inviteAction(Request $request, $tangleId) { $userTangleRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:UserTangle'); if (($userTangle = $userTangleRepo->findOneBy(array('userId' => $session->getUserId(), 'tangleId' => $tangleId))) == null) { - return new Response("You are not a tangle member to invite other members", 401); + return new Response("You are Unauthorized to perform this action", 401); } $jsonString = $request->getContent(); @@ -376,22 +376,26 @@ public function createTangleAction(Request $request) { $sessionRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); - if ($sessionId == null || $tangleIcon == null || $tangleName == null) { - return new Response("Bad Request", 400); + if ($sessionId == null) { + return new Response("Please login again", 400); + } + + if ($tangleIcon == null || $tangleName == null) { + return new Response("Please include all fields", 400); } if ($session == null) { - return new Response("Unauthorized", 401); + return new Response("Please login again", 401); } if (!($this->checkAvailability($tangleName))) { - return new Response("Tangle Already Taken", 200); + return new Response("This name is unavailable, please choose a different name", 200); } $imageData = base64_decode($tangleIcon); $f = finfo_open(); $mimeType = finfo_buffer($f, $imageData, FILEINFO_MIME_TYPE); if ($mimeType == false || $mimeType != 'image/png') { - return new Response("Bad image", 400); + return new Response("Please choose a different image", 400); } $icon = imagecreatefromstring($imageData); $iconName = $this->generateRandomString(50) . '.png'; @@ -454,7 +458,7 @@ public function checkAvailability($tangleName) { */ public function validateIsOwner($sessionId, $tangleId) { if ($sessionId == null) { - return new Response("Bad Request", 400); + return new Response("Please login again", 400); } $sesionRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Session'); @@ -462,14 +466,14 @@ public function validateIsOwner($sessionId, $tangleId) { $session = $sesionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response("Unauthorized", 401); + return new Response("Please login again", 401); } $userTangleRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:UserTangle'); if (($userTangle = $userTangleRepo->findOneBy(array('userId' => $session->getUserId(), 'tangleId' => $tangleId))) == null || !$userTangle->getTangleOwner()) { - return new Response("Unauthorized", 401); + return new Response("Please choose a tangle", 401); } return null; @@ -504,13 +508,13 @@ private function leaveTangleVerification($request, $tangleId) { if (($userTangle = $userTangleRepo ->findOneBy(array('userId' => $userId, 'tangleId' => $tangleId, 'tangleOwner' => true))) != null) { - return new Response("Forbidden", 403); + return new Response("You are unauthorized to perforn this action", 403); } $userTangle = $userTangleRepo ->findOneBy(array('userId' => $userId, 'tangleId' => $tangleId)); if ($userTangle->getLeavingDate() != null) { - return new Response("Unauthorized", 401); + return new Response("You are unauthorized to perform this action", 401); } return null; @@ -766,7 +770,7 @@ public function acceptPendingInvitationAction(Request $request, $pendingInvitati } if ($pendingInvitation->getApproved()) { - return new Response("Bad Request", 400); + return new Response("User has already been approved", 400); } $validation = $this->validateIsOwner($sessionId, $pendingInvitation->getTangleId()); @@ -789,7 +793,7 @@ public function acceptPendingInvitationAction(Request $request, $pendingInvitati } else { $pendingInvitation->setApproved(true); $this->getDoctrine()->getManager()->flush(); - return new Response("Already in the tangle", 200); + return new Response("You are already a member of this tangle", 200); } } @@ -811,7 +815,7 @@ public function rejectPendingInvitationAction(Request $request, $pendingInvitati } if ($pendingInvitation->getApproved()) { - return new Response("Bad Request", 400); + return new Response("Invitation has already been rejected", 400); } $validation = $this->validateIsOwner($sessionId, $pendingInvitation->getTangleId()); @@ -890,7 +894,7 @@ public function getTanglesAction(Request $request) { $doctrine = $this->getDoctrine(); if ($sessionId == null) { - return new Response("Bad Request", 400); + return new Response("Please login again ", 400); } $sesionRepo = $doctrine->getRepository('MegasoftEntangleBundle:Session'); @@ -898,7 +902,7 @@ public function getTanglesAction(Request $request) { $session = $sesionRepo->findOneBy(array('sessionId' => $sessionId)); if ($session == null || $session->getExpired()) { - return new Response("Unauthorized", 401); + return new Response("Please login again", 401); } @@ -962,10 +966,10 @@ public function resetTangleAction(Request $request, $tangleId) { $tangleRepo = $this->getDoctrine()->getRepository("MegasoftEntangleBundle:Tangle"); $tangle = $tangleRepo->findOneBy(array('id' => $tangleId,)); if ($tangle == null) { - return new Response("Tangle doesn't exist", 404); + return new Response("Tangle does not exist", 404); } $verified = $this->validateIsOwner($sessionId, $tangleId); - if ($verified != null) { + if ($verified != null) { return $verified; } $tangleUsers = $tangle->getUsers(); @@ -981,7 +985,7 @@ public function resetTangleAction(Request $request, $tangleId) { } $this->getDoctrine()->getManager()->flush(); - return new Response("Tangle reset", 200); + return new Response("Tangle reseted successfully", 200); } /** diff --git a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/UserController.php b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/UserController.php index ab4ac2a5..ec3d86fa 100755 --- a/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/UserController.php +++ b/Entangle/entangle-symfony/public/src/entangle/src/Megasoft/EntangleBundle/Controller/UserController.php @@ -57,16 +57,16 @@ public function loginAction(\Symfony\Component\HttpFoundation\Request $request) $deviceType = $json_array['deviceType']; if (!$name) { - return new JsonResponse("missing name", 400); + return new JsonResponse("Please enter username", 400); } if (!$password) { - return new JsonResponse("missing password", 400); + return new JsonResponse("Please enter password", 400); } if(!$deviceType){ - return new JsonResponse("missing device type", 400); + return new JsonResponse("Please enter device type", 400); } if (strstr("\"", $name) || strstr("'", $name)) { - return new JsonResponse("the name has special characters", 400); + return new JsonResponse("Username should not contain special characters", 400); } $sessionId = $this->generateSessionId(30); @@ -152,7 +152,7 @@ public function generalProfileAction(\Symfony\Component\HttpFoundation\Request $ $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $doctrine = $this->getDoctrine(); @@ -168,7 +168,7 @@ public function generalProfileAction(\Symfony\Component\HttpFoundation\Request $ $loggedInUser = $session->getUser(); if ($session == null || $session->getExpired() || $loggedInUser != $user) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } return $this->viewProfile($user); @@ -186,7 +186,7 @@ public function profileAction(\Symfony\Component\HttpFoundation\Request $request $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $doctrine = $this->getDoctrine(); @@ -197,7 +197,7 @@ public function profileAction(\Symfony\Component\HttpFoundation\Request $request $loggedInUser = $session->getUser(); if ($session == null || $session->getExpired()) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } if ($user == null) { @@ -257,7 +257,7 @@ public function transactionsAction(\Symfony\Component\HttpFoundation\Request $re $sessionId = $request->headers->get('X-SESSION-ID'); if ($sessionId == null) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $doctrine = $this->getDoctrine(); @@ -267,7 +267,7 @@ public function transactionsAction(\Symfony\Component\HttpFoundation\Request $re $session = $sessionTable->findOneBy(array('sessionId' => $sessionId,)); if ($session == null || $session->getExpired()) { - return new Response('Unauthorized', 401); + return new Response('Please login again', 401); } $loggedInUser = $session->getUser(); @@ -335,10 +335,10 @@ public function logoutAction(\Symfony\Component\HttpFoundation\Request $request) $sessionRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Session'); $session = $sessionRepo->findOneBy(array('sessionId' => $sessionId)); if (!$session) { - return new JsonResponse("the sessionId does not exist", 404); + return new JsonResponse("Please login again",404); } if ($session->getExpired()) { - return new JsonResponse("the sessionId is already expired", 400); + return new JsonResponse("Please login again", 400); } $user = $session->getUser();