Guest User

Untitled

a guest
Mar 16th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. public IEnumerator CallLogin(string Username, string Password) {
  2.  
  3.  
  4. UnityWebRequest www =
  5. UnityWebRequest.Post("http://localhost:8080/unity/login", new
  6. User(Username, Password).ToJson());
  7.  
  8. www.uploadHandler.contentType = "application/json";
  9.  
  10. yield return www.Send();
  11.  
  12. if (www.error != null)
  13. {
  14.  
  15. Debug.Log("Error " + www.error);
  16.  
  17. }
  18. else {
  19.  
  20. Debug.Log("Response " + www.downloadHandler.text);
  21.  
  22. }
  23.  
  24. }
  25.  
  26. @ResponseBody
  27. @RequestMapping(value = "/login", method = RequestMethod.POST,
  28. produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
  29. public ResponseEntity<UserModel> Login(@RequestBody User user){
  30.  
  31. // check if the username and password provided matches a user in the database.
  32. String verifiedResponse = this.defaultUserDAOService.verification(user);
  33.  
  34. UserModel userModel = new UserModel();
  35.  
  36. if(verifiedResponse.equalsIgnoreCase("Verified")){ // if the user was verified successfully (Found in the database)
  37.  
  38. userModel.setUser(defaultUserDAOService.getByUsername(user.getUserName()))
  39. .setSuccessful(true)
  40. .setResponseMessage("Successful");
  41.  
  42.  
  43. return new ResponseEntity<>(userModel, HttpStatus.OK); // return response to client.
  44.  
  45.  
  46. }else{
  47.  
  48. userModel.setUser(new User())
  49. .setSuccessful(false)
  50. .setResponseMessage("Username or Password is incorrect");
  51.  
  52. return new ResponseEntity<>(userModel, HttpStatus.NOT_FOUND); // return response to client.
  53.  
  54. }
  55.  
  56.  
  57. }
  58.  
  59. public User(string userName, string password)
  60. {
  61. this.userName = userName;
  62.  
  63. this.password = password;
  64. }
  65.  
  66. public string userName;
  67.  
  68. public string password;
  69.  
  70.  
  71. public string ToJson()
  72. {
  73. return JsonUtility.ToJson(this);
  74. }
Add Comment
Please, Sign In to add comment