fix login fail issue

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-16 13:06:33 +08:00
parent ace18d01cd
commit 317172aa4b
8 changed files with 53 additions and 48 deletions

View File

@ -30,6 +30,7 @@
<!-- 未登录状态下会自动跳转到/login登录页--> <!-- 未登录状态下会自动跳转到/login登录页-->
<security:form-login login-page="/login" <security:form-login login-page="/login"
default-target-url="/dashboard" default-target-url="/dashboard"
authentication-success-handler-ref="customAuthenticationSuccessHandler"
authentication-failure-handler-ref="customAuthenticationFailureHandler"/> authentication-failure-handler-ref="customAuthenticationFailureHandler"/>
<security:logout logout-url="/logout"/> <security:logout logout-url="/logout"/>
<security:logout logout-success-url="/login?logout=true"/> <security:logout logout-success-url="/login?logout=true"/>

View File

@ -146,7 +146,7 @@
<th scope="col">授课课程ID</th> <th scope="col">授课课程ID</th>
<th scope="col">授课课程名</th> <th scope="col">授课课程名</th>
<th scope="col">授课班级</th> <th scope="col">授课班级</th>
<%-- <th scope="col" class="text-center">操作</th>--%> <th scope="col" class="text-center">操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -159,26 +159,16 @@
<td>${teacher.course.courseID}</td> <td>${teacher.course.courseID}</td>
<td>${teacher.course.courseName}</td> <td>${teacher.course.courseName}</td>
<td>${teacher.classes}</td> <td>${teacher.classes}</td>
<%-- <td class="text-center">--%> <td class="text-center">
<%-- <div class="btn-group" role="group" aria-label="Basic example">--%> <div class="btn-group" role="group" aria-label="Basic example">
<%-- <c:choose>--%> <button type="button" class="btn btn-danger">
<%-- <c:when test="${user.disabled_str == false}">--%> <i class="fas fa-pencil me-1"></i>禁用账户
<%-- <button type="button" class="btn btn-danger"><i--%> </button>
<%-- class="fas fa-ban me-1"></i>禁用账户--%> <button type="button" class="btn btn-primary">
<%-- </button>--%> <i class="fas fa-trash me-1"></i>重设密码
<%-- </c:when>--%> </button>
<%-- <c:when test="${user.disabled_str == true}">--%> </div>
<%-- <button type="button" class="btn btn-success"><i--%> </td>
<%-- class="fas fa-circle-check me-1"--%>
<%-- onclick="userenabled(${user.id})"></i>启用账户--%>
<%-- </button>--%>
<%-- </c:when>--%>
<%-- </c:choose>--%>
<%-- <button type="button" class="btn btn-primary" onclick="resetPWD(${user.id})"><i--%>
<%-- class="fas fa-arrow-rotate-right me-1"></i>重设密码--%>
<%-- </button>--%>
<%-- </div>--%>
<%-- </td>--%>
</tr> </tr>
</c:forEach> </c:forEach>
</tbody> </tbody>
@ -282,7 +272,8 @@
<div class="form-outline"> <div class="form-outline">
<input type="text" id="typeText8" class="form-control" <input type="text" id="typeText8" class="form-control"
name="classes"/> name="classes"/>
<label class="form-label" for="typeText8">授课班级(一班~五班)</label> <label class="form-label"
for="typeText8">授课班级(一班~五班)</label>
</div> </div>
</div> </div>
</div> </div>
@ -361,7 +352,8 @@
<div class="form-outline"> <div class="form-outline">
<input type="text" id="typeText15" class="form-control" <input type="text" id="typeText15" class="form-control"
name="classes"/> name="classes"/>
<label class="form-label" for="typeText15">授课班级(一班~五班)</label> <label class="form-label"
for="typeText15">授课班级(一班~五班)</label>
</div> </div>
</div> </div>
</div> </div>
@ -466,7 +458,6 @@
</div> </div>
</div> </div>
<!-- Tabs content --> <!-- Tabs content -->
</div> </div>
</div> </div>
</div> </div>

View File

@ -24,6 +24,7 @@ public class ViewController {
if (username != null) { if (username != null) {
model.addAttribute("username", username); model.addAttribute("username", username);
} }
// model.addAttribute("errorMessage","null");
return "dashboard"; // 返回 dashboard 视图名 return "dashboard"; // 返回 dashboard 视图名
} }

View File

@ -0,0 +1,20 @@
package cyou.chenx221.handler;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
request.getSession().removeAttribute("errorMessage");
super.onAuthenticationSuccess(request, response, authentication);
}
}

View File

@ -30,6 +30,7 @@
<!-- 未登录状态下会自动跳转到/login登录页--> <!-- 未登录状态下会自动跳转到/login登录页-->
<security:form-login login-page="/login" <security:form-login login-page="/login"
default-target-url="/dashboard" default-target-url="/dashboard"
authentication-success-handler-ref="customAuthenticationSuccessHandler"
authentication-failure-handler-ref="customAuthenticationFailureHandler"/> authentication-failure-handler-ref="customAuthenticationFailureHandler"/>
<security:logout logout-url="/logout"/> <security:logout logout-url="/logout"/>
<security:logout logout-success-url="/login?logout=true"/> <security:logout logout-success-url="/login?logout=true"/>

View File

@ -146,7 +146,7 @@
<th scope="col">授课课程ID</th> <th scope="col">授课课程ID</th>
<th scope="col">授课课程名</th> <th scope="col">授课课程名</th>
<th scope="col">授课班级</th> <th scope="col">授课班级</th>
<%-- <th scope="col" class="text-center">操作</th>--%> <th scope="col" class="text-center">操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -159,26 +159,16 @@
<td>${teacher.course.courseID}</td> <td>${teacher.course.courseID}</td>
<td>${teacher.course.courseName}</td> <td>${teacher.course.courseName}</td>
<td>${teacher.classes}</td> <td>${teacher.classes}</td>
<%-- <td class="text-center">--%> <td class="text-center">
<%-- <div class="btn-group" role="group" aria-label="Basic example">--%> <div class="btn-group" role="group" aria-label="Basic example">
<%-- <c:choose>--%> <button type="button" class="btn btn-danger">
<%-- <c:when test="${user.disabled_str == false}">--%> <i class="fas fa-pencil me-1"></i>禁用账户
<%-- <button type="button" class="btn btn-danger"><i--%> </button>
<%-- class="fas fa-ban me-1"></i>禁用账户--%> <button type="button" class="btn btn-primary">
<%-- </button>--%> <i class="fas fa-trash me-1"></i>重设密码
<%-- </c:when>--%> </button>
<%-- <c:when test="${user.disabled_str == true}">--%> </div>
<%-- <button type="button" class="btn btn-success"><i--%> </td>
<%-- class="fas fa-circle-check me-1"--%>
<%-- onclick="userenabled(${user.id})"></i>启用账户--%>
<%-- </button>--%>
<%-- </c:when>--%>
<%-- </c:choose>--%>
<%-- <button type="button" class="btn btn-primary" onclick="resetPWD(${user.id})"><i--%>
<%-- class="fas fa-arrow-rotate-right me-1"></i>重设密码--%>
<%-- </button>--%>
<%-- </div>--%>
<%-- </td>--%>
</tr> </tr>
</c:forEach> </c:forEach>
</tbody> </tbody>
@ -282,7 +272,8 @@
<div class="form-outline"> <div class="form-outline">
<input type="text" id="typeText8" class="form-control" <input type="text" id="typeText8" class="form-control"
name="classes"/> name="classes"/>
<label class="form-label" for="typeText8">授课班级(一班~五班)</label> <label class="form-label"
for="typeText8">授课班级(一班~五班)</label>
</div> </div>
</div> </div>
</div> </div>
@ -361,7 +352,8 @@
<div class="form-outline"> <div class="form-outline">
<input type="text" id="typeText15" class="form-control" <input type="text" id="typeText15" class="form-control"
name="classes"/> name="classes"/>
<label class="form-label" for="typeText15">授课班级(一班~五班)</label> <label class="form-label"
for="typeText15">授课班级(一班~五班)</label>
</div> </div>
</div> </div>
</div> </div>
@ -466,7 +458,6 @@
</div> </div>
</div> </div>
<!-- Tabs content --> <!-- Tabs content -->
</div> </div>
</div> </div>
</div> </div>