Redirections added (leave-session template not necessary)

This commit is contained in:
pabloFuente 2017-06-15 15:44:45 +02:00
parent f16bb2b6e3
commit eb2a958bac
6 changed files with 23 additions and 64 deletions

View File

@ -4,11 +4,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class, args);
}
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

View File

@ -37,6 +37,16 @@ public class LoginController {
users.put("subscriber", new MyUser("subscriber", "pass", OpenViduRole.SUBSCRIBER));
}
@RequestMapping(value = "/")
public String logout(HttpSession httpSession) {
if (checkUserLogged(httpSession)) {
return "redirect:/dashboard";
} else {
httpSession.invalidate();
return "index";
}
}
@RequestMapping(value = "/dashboard", method = { RequestMethod.GET, RequestMethod.POST })
public String login(@RequestParam(name = "user", required = false) String user,
@RequestParam(name = "pass", required = false) String pass, Model model, HttpSession httpSession) {
@ -53,33 +63,18 @@ public class LoginController {
model.addAttribute("username", user);
return "dashboard";
} else {
return "index";
return "redirect:/";
}
}
@RequestMapping(value = "/", method = RequestMethod.GET)
@RequestMapping(value = "/logout", method = RequestMethod.POST)
public String logout(Model model, HttpSession httpSession) {
if (checkUserLogged(httpSession)) {
model.addAttribute("username", httpSession.getAttribute("loggedUser"));
return "dashboard";
}
httpSession.invalidate();
return "index";
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public String logout(@RequestParam(name = "islogout", required = false) String islogout, HttpSession httpSession) {
if (checkUserLogged(httpSession) && islogout.equals("true")){
System.out.println("'" + httpSession.getAttribute("loggedUser") + "' has logged out");
httpSession.invalidate();
}
return "index";
return "redirect:/";
}
private boolean login(String user, String pass) {
return (user != null &&
pass != null &&
users.containsKey(user) && users.get(user).pass.equals(pass));
return (user != null && pass != null && users.containsKey(user) && users.get(user).pass.equals(pass));
}
private boolean checkUserLogged(HttpSession httpSession) {

View File

@ -1,15 +0,0 @@
package io.openvidu.mvc.java;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MainController {
@RequestMapping(value = "/")
public String index(Model model) {
return "index";
}
}

View File

@ -118,18 +118,18 @@ public class SessionController {
System.out.println(sessionName + " empty!");
}
model.addAttribute("sessionId", sessionId);
return "leave-session";
return "redirect:/dashboard";
} else {
System.out.println("Problems in the app server: the TOKEN wasn't valid");
return "leave-session";
return "redirect:/dashboard";
}
} else {
System.out.println("Problems in the app server: the SESSIONID wasn't valid");
return "leave-session";
return "redirect:/dashboard";
}
} else {
System.out.println("Problems in the app server: the SESSION does not exist");
return "leave-session";
return "redirect:/dashboard";
}
}

View File

@ -23,8 +23,7 @@
</p>
</form>
<p>
<form action="/" method="post">
<input type="hidden" name="islogout" value="true"></input>
<form action="/logout" method="post">
<button type="submit">Log out</button>
</form>
</p>

View File

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"></meta>
<title>OpenVidu Demo Java MVC Secure</title>
</head>
<body>Leaving session...
</body>
<script src="OpenVidu.js"></script>
<script>
window.location.href = '/dashboard';
</script>
</html>