import com.device.corporation.datebase.DateBase;
import com.device.corporation.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
@SessionAttributes("user")
@RequestMapping("/")
public class ControllerChat {
private boolean isLogin = false;
private boolean isAdmin = false;
@Autowired
private DateBase dateBase;
@Autowired
private UserService userService;
@RequestMapping(method = RequestMethod.GET)
public String index(){
return "index";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(){
if (isLogin){
return "profile";
}else return "login";
}
@RequestMapping(value = "/profile", method = RequestMethod.GET)
public String profile(@PathVariable(value = "name") String name, Model model){
model.addAttribute("user", userService.getUser(name, dateBase));
return "profile";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login_form(@RequestParam String name, @RequestParam String password, Model model) {
if (userService.isLogged(name, password, dateBase)) {
isLogin = true;
if (name.equals("admin")){
isAdmin = true;
}
return profile(name, model);
}else{
model.addAttribute("message", "Неправильный логин или пароль");
return "login_error";
}
}
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(Model moodel){
return "register";
}
}
Вот мой контроллер, как сделать нормальное url, чтобы когда нажимать на войти было /profile, а не /login?
И как передать объект профилю?
login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<jsp:include page="/WEB-INF/pages/incudes.jsp" />
<head>
<title>Вход | Live Chat</title>
</head>
<body>
<div id="customer-chat-widget" class="customer-chat customer-chat-login customer-chat-widget login-form">
<div class="customer-chat-header">
<div class="customer-chat-header-title">Вход</div>
</div>
<div id="customer-chat-content-login-form" class="customer-chat-content">
<div class="customer-chat-content-info">
Пожалуйста, введите логин и пароль
</div>
<form action="/login" method="GET">
<div class="customer-chat-content-message-input">
<input id="name" type="text" name="name" class="customer-chat-content-message-input-field" placeholder="Ваш логин" />
</div>
<div class="customer-chat-content-message-input">
<input type="password" name="password" class="customer-chat-content-message-input-field" placeholder="Ваш пароль" />
</div>
<div class="customer-chat-content-row">
<button type="submit" id="customer-chat-login-start" class="customer-chat-content-button">Вход <i class="icon-circle-arrow-right icon-white" style="margin: 3px 0 0 3px;"></i></button>
</div>
</form>
<form action="/register" method="post">
<div class="customer-chat-content-row-register">
<button type="submit" id="customer-chat-login-start" class="customer-chat-content-button-register">Регистрация <i class="icon-circle-arrow-right icon-white" style="margin: 3px 0 0 3px;"></i></button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
profile.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<jsp:include page="/WEB-INF/pages/incudes.jsp" />
<head>
<title>Профиль | LiveChat</title>
</head>
<body>
<div id="customer-chat" class="customer-chat customer-chat-admin">
<div class="customer-chat-header">
<div class="customer-chat-header-title">LiveChat</div>
<div id="customer-chat-button-menu" class="customer-chat-header-button">
<div class="customer-chat-content-message-avatar-operator"></div>
<div class="customer-chat-header-button-text"></div>
<i class="icon-chevron-down icon-white">${user.name}</i>
</div>
<div class="customer-chat-header-menu">
<div class="customer-chat-header-menu-triangle"></div>
<a href="#" id="customer-chat-header-menu-edit" class="customer-chat-header-menu-item" data-id="0"><i class="icon-user"></i> <div>Моя страница</div></a>
<i class="divider"></i>
<a href="" id="customer-chat-header-menu-install" class="customer-chat-header-menu-item"><i class="icon-chevron-right"></i> <div>Редактрировать</div></a>
<a href="" id="customer-chat-header-menu-uninstall" class="customer-chat-header-menu-item"><i class="icon-remove"></i> <div>Настройки</div></a>
<i class="divider"></i>
<a href="#" id="customer-chat-header-menu-widget-snippet" class="customer-chat-header-menu-item"><i class="icon-align-left"></i> <div>Выход</div></a>
</div>
</div>
</div>
</body>
</html>