2
I’m doing a project, where I have a login. Front-end use in Reactjs, and backend in Java. But I don’t know how to make a java JWT token so that the front end can be successfully logged in.
I read this tutorial https://developer.okta.com/blog/2018/10/31/jwts-with-java, I downloaded it and read it. But I’m still struggling to understand how to adapt to my code!
Here is my code that returns the login (company, user and password)
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String Login(@ModelAttribute("empresa") String empresa,
@ModelAttribute("usuario") String usuario,
@ModelAttribute("senha") String senha,ModelMap map) throws SQLException {
ArrayList<String> list = new ArrayList<>();
System.out.println("PRINTAR O USUARIO >>>"+usuario);
System.out.println(senha);
if (usuario.equals("veronica") && senha.equals("123456")) {
list.add("Sucesso" + usuario);
} else if (usuario.equals("camila") && senha.equals("123456")) {
list.add("Sucesso" + usuario);
} else if (usuario.equals("jose") && senha.equals("123456")) {
list.add("Sucesso" + usuario);
} else {
list.add("Falha no login para a empresa " + empresa + " (usuario ou senha não conferem)");
}
Gson gson = new Gson();
String jsonArray = gson.toJson(list);
map.addAttribute("lists", jsonArray);
return "main";
}