register中移除多余的代码

添加模态框2以显示success的消息

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-08 11:29:56 +08:00
parent d925e15308
commit e64a15de55
2 changed files with 26 additions and 10 deletions

View File

@ -70,18 +70,11 @@ public class UserController {
user = new User(username, password);
userMapper.insertUser(user);
model.addAttribute("message", "注册成功");
return "login";
}
} else {
model.addAttribute("errorMessage", "用户已存在,请重新输入。");
return "login";
}
if (user != null && user.getPassword().equals(password)) {
model.addAttribute("message", "登陆成功");
return "redirect:/dashboard"; // 重定向到 dashboard 页面
} else {
model.addAttribute("errorMessage", "用户名或密码不正确,请重新输入。");
return "login";
}
}
}

View File

@ -182,7 +182,27 @@
</div>
</div>
</div>
<%-- todo: Modal2--%>
<!-- Modal -->
<div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModalLabel2" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel2">
<i class="fas fa-circle-check me-2"></i>成功
</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<c:if test="${not empty successMessage}">
${successMessage}
</c:if>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-mdb-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
</main>
<footer>
@ -194,9 +214,12 @@
<script>
$(document).ready(function () {
<%-- 判断模型中是否存在错误信息 --%>
<c:if test="${not empty errorMessage}">
<c:if test="${not empty errorMessage && errorMessage ne 'null'}">
$('#exampleModal').modal('show');
</c:if>
<c:if test="${not empty successMessage && successMessage ne 'null'}">
$('#exampleModal2').modal('show');
</c:if>
});
</script>
</body>