Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IEnumerator CallLogin(string Username, string Password) {
- UnityWebRequest www =
- UnityWebRequest.Post("http://localhost:8080/unity/login", new
- User(Username, Password).ToJson());
- www.uploadHandler.contentType = "application/json";
- yield return www.Send();
- if (www.error != null)
- {
- Debug.Log("Error " + www.error);
- }
- else {
- Debug.Log("Response " + www.downloadHandler.text);
- }
- }
- @ResponseBody
- @RequestMapping(value = "/login", method = RequestMethod.POST,
- produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<UserModel> Login(@RequestBody User user){
- // check if the username and password provided matches a user in the database.
- String verifiedResponse = this.defaultUserDAOService.verification(user);
- UserModel userModel = new UserModel();
- if(verifiedResponse.equalsIgnoreCase("Verified")){ // if the user was verified successfully (Found in the database)
- userModel.setUser(defaultUserDAOService.getByUsername(user.getUserName()))
- .setSuccessful(true)
- .setResponseMessage("Successful");
- return new ResponseEntity<>(userModel, HttpStatus.OK); // return response to client.
- }else{
- userModel.setUser(new User())
- .setSuccessful(false)
- .setResponseMessage("Username or Password is incorrect");
- return new ResponseEntity<>(userModel, HttpStatus.NOT_FOUND); // return response to client.
- }
- }
- public User(string userName, string password)
- {
- this.userName = userName;
- this.password = password;
- }
- public string userName;
- public string password;
- public string ToJson()
- {
- return JsonUtility.ToJson(this);
- }
Add Comment
Please, Sign In to add comment