Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. //BACKEND
  2. @CrossOrigin(origins = "http://localhost:4200") //Connects to the frontend
  3. @RestController
  4. public class AccountResource {
  5.  
  6. @Autowired //Autowired automaticaly assigns the variable.
  7. private AccountHardcodedService accountService;
  8.  
  9. @Autowired
  10. private JwtInMemoryUserDetailsService userService;
  11.  
  12.  
  13. //Returns the account with the username and password
  14. //{username} and {password} is passed in using @PathVariable
  15. @GetMapping("/accounts/{username}/account/{password}")
  16. public Account getAccount(@PathVariable String username, @PathVariable String password) {
  17. //The accountservice just returns the account with the username, all backend services should be setup kinda like this.
  18. return accountService.getAccount(username);
  19. }
  20.  
  21. }
  22.  
  23.  
  24. //FRONTEND
  25.  
  26. attemptLogin(username, password) {
  27. //The Axios.get parameter must be the same as the backend @GetMapping.
  28. return axios.get(`${API_URL}/accounts/${username}/login/${password}`);
  29. }
  30. //To access this user you can do this in the frontend:
  31. //accountBalance is a variable in the Account class in the backend.
  32. //To access the firstName of the account class you would do:
  33. //response.data.firstName;
  34.  
  35.  
  36. AccountDataService.getAccount(username)
  37. .then(response =>(
  38. console.log(response.data.accountBalance.toString())
  39. ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement