Skip to content

Commit

Permalink
完成记住密码功能
Browse files Browse the repository at this point in the history
  • Loading branch information
minkai95 committed Apr 27, 2018
1 parent 1df9a3e commit 16e238a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 163 deletions.
34 changes: 33 additions & 1 deletion src/main/java/com/snut_tdms/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
Expand All @@ -36,7 +37,10 @@ public UserController(UserService userService) {

@RequestMapping(value = "/login",method = RequestMethod.POST)
@ResponseBody
public JSONObject login(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session){
public JSONObject login(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("rememberPSW") String rememberPSW,
HttpSession session,HttpServletRequest request,HttpServletResponse response){
JSONObject json = new JSONObject();
Map<String,Object> result = userService.userLogin(username,password);
StatusCode code = (StatusCode)result.get("StatusCode");
Expand All @@ -47,6 +51,34 @@ public JSONObject login(@RequestParam("username") String username, @RequestParam
session.setAttribute("userInfo",userInfo);
session.setAttribute("role",userRole.getRole().getName());
json.put("urlStr", "/"+userRole.getRole().getName()+"/index");
if (rememberPSW.equals("1")){
Cookie usernameCookie = new Cookie("username".trim(),username.trim());
Cookie passwordCookie = new Cookie("password".trim(),password.trim());
usernameCookie.setMaxAge(365*24*60*60);// 账号保存一年
passwordCookie.setMaxAge(7*24*60*60); // 密码保存7天
usernameCookie.setPath("/");
passwordCookie.setPath("/");
response.addCookie(usernameCookie);
response.addCookie(passwordCookie);
}else {
Cookie[] cookies = request.getCookies();
if (cookies.length>0) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("username")) {
cookie.setValue(null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
if (cookie.getName().equals("password")) {
cookie.setValue(null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
}
}
}
}else if (StatusCode.LOGIN_SUCCESS.getnCode().equals(code.getnCode()) && (userRole.getUser().getFirstLogin()==0)){
UserInfo userInfo = userService.selectUserInfoByUsername(username);
session.setAttribute("userRole",userRole);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/snut_tdms/util/FileUploadUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ public void update(long pBytesRead, long pContentLength, int arg2) {
fileFormat.add("pdf");
fileFormat.add("ppt");
fileFormat.add("doc");
fileFormat.add("docx");
fileFormat.add("xls");
fileFormat.add("xlsx");
fileFormat.add("png");
fileFormat.add("jpg");
fileFormat.add("jpeg");
if(!fileFormat.contains(fileExtName.toLowerCase())){
map.put("message",StatusCode.FILE_FORMAT_ERROR);
break;
Expand Down
158 changes: 0 additions & 158 deletions src/main/java/com/snut_tdms/util/WriterExcelFile.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/teacher/teacherPublicData.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<td>${dataHelp.userInfo.name}</td>
<td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${dataHelp.data.submitTime}"/></td>
<td style="width: 210px; text-align: center;">
<button type="button" class="btn btn-info btn-sm"><i class="icon-search"></i> 查看</button>
<a href="#" class="btn btn-info btn-sm"><i class="icon-search"></i> 查看</a>
<button type="button" class="btn btn-primary btn-sm" onclick="downloadFile('${dataHelp.data.id}')"><i class="icon-download"></i> 下载</button>
<button type="button" class="btn btn-danger btn-sm" onclick="deleteFile('${dataHelp.data.id}')"><i class="icon-remove-circle"></i> 删除</button>
</td>
Expand Down
6 changes: 3 additions & 3 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<div class="loginFormWrapper">
<form id="loginForm">
<i class="icon-user iconUser"></i>
<input id="username" class="form-control username" type="text" name="username" placeholder="用户名" autofocus>
<input id="username" class="form-control username" type="text" name="username" value="${cookie.username.value}" placeholder="用户名" autofocus>
<i class="icon-lock iconPassword"></i>
<input id="password" class="form-control password" type="password" name="password" placeholder="密码">
<input id="password" class="form-control password" type="password" name="password" value="${cookie.password.value}" placeholder="密码">
<input id="verificationCode" class="form-control verificationCode" type="text" name="verificationCode" placeholder="验证码">
<div id="verificationCodeCont" class="verificationCodeCont"></div>
<div class="rememberPassword">
Expand Down Expand Up @@ -96,7 +96,7 @@
var password = $("#password").val();
$.ajax({
type: "POST",
url: "${ctx}/user/login?username=" + username + "&password=" + password,
url: "${ctx}/user/login?username=" + username + "&password=" + password+"&rememberPSW="+btnResult,
dataType: "json",
success: function (result) {
if (result['message']!=null){
Expand Down

0 comments on commit 16e238a

Please sign in to comment.