-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
7,951 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>user-manage</artifactId> | ||
<name>user-manage</name> | ||
<description>user management system</description> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.8.RELEASE</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
</dependency> | ||
<!-- <dependency> | ||
<groupId>org.springframework.session</groupId> | ||
<artifactId>spring-session-data-redis</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-cache</artifactId> | ||
</dependency>--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-mail</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<fork>true</fork> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
20 changes: 20 additions & 0 deletions
20
第16课:综合实战用户管理系统/user-manage/src/main/java/com/neo/UserManageApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.neo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.web.support.SpringBootServletInitializer; | ||
|
||
|
||
@SpringBootApplication | ||
public class UserManageApplication extends SpringBootServletInitializer { | ||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
return application.sources(UserManageApplication.class); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(UserManageApplication.class, args); | ||
} | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
第16课:综合实战用户管理系统/user-manage/src/main/java/com/neo/config/SessionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
package com.neo.config; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; | ||
*/ | ||
/** | ||
* maxInactiveIntervalInSeconds: 设置Session失效时间,使用Redis Session之后,原Boot的server.session.timeout属性不再生效 | ||
*//* | ||
@Configuration | ||
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 3000) | ||
public class SessionConfig { | ||
} | ||
*/ |
66 changes: 66 additions & 0 deletions
66
第16课:综合实战用户管理系统/user-manage/src/main/java/com/neo/config/SessionFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.neo.config; | ||
|
||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class SessionFilter implements Filter { | ||
protected Logger log = LoggerFactory.getLogger(SessionFilter.class); | ||
// 不登陆也可以访问的资源 | ||
private static Set<String> GreenUrlSet = new HashSet<String>(); | ||
|
||
public void doFilter(ServletRequest srequest, ServletResponse sresponse, | ||
FilterChain filterChain) throws IOException, ServletException { | ||
HttpServletRequest request = (HttpServletRequest) srequest; | ||
String uri = request.getRequestURI(); | ||
sresponse.setCharacterEncoding("UTF-8");//设置响应编码格式 | ||
sresponse.setContentType("text/html;charset=UTF-8");//设置响应编码格式 | ||
if (uri.endsWith(".js") | ||
|| uri.endsWith(".css") | ||
|| uri.endsWith(".jpg") | ||
|| uri.endsWith(".gif") | ||
|| uri.endsWith(".png") | ||
|| uri.endsWith(".ico")) { | ||
log.debug("security filter, pass, " + request.getRequestURI()); | ||
filterChain.doFilter(srequest, sresponse); | ||
return; | ||
} | ||
|
||
System.out.println("request uri is : "+uri); | ||
//不处理指定的action, jsp | ||
if (GreenUrlSet.contains(uri) || uri.contains("/verified/")) { | ||
log.debug("security filter, pass, " + request.getRequestURI()); | ||
filterChain.doFilter(srequest, sresponse); | ||
return; | ||
} | ||
String id=(String)request.getSession().getAttribute(WebConfiguration.LOGIN_KEY); | ||
if(StringUtils.isBlank(id)){ | ||
String html = "<script type=\"text/javascript\">window.location.href=\"/toLogin\"</script>"; | ||
sresponse.getWriter().write(html); | ||
}else { | ||
filterChain.doFilter(srequest, sresponse); | ||
} | ||
} | ||
|
||
public void destroy() { | ||
|
||
} | ||
|
||
@Override | ||
public void init(FilterConfig filterconfig) throws ServletException { | ||
GreenUrlSet.add("/toRegister"); | ||
GreenUrlSet.add("/toLogin"); | ||
GreenUrlSet.add("/login"); | ||
GreenUrlSet.add("/loginOut"); | ||
GreenUrlSet.add("/register"); | ||
GreenUrlSet.add("/verified"); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
第16课:综合实战用户管理系统/user-manage/src/main/java/com/neo/config/WebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.neo.config; | ||
|
||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.servlet.Filter; | ||
|
||
@Configuration | ||
public class WebConfiguration { | ||
|
||
public static final String LOGIN_KEY="LOGIN_SESSION_KEY"; | ||
public static final String LOGIN_USER="LOGIN_SESSION_USER"; | ||
|
||
@Bean(name = "sessionFilter") | ||
public Filter sessionFilter() { | ||
return new SessionFilter(); | ||
} | ||
|
||
@Bean | ||
public FilterRegistrationBean testFilterRegistration() { | ||
|
||
FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
registration.setFilter(sessionFilter()); | ||
registration.addUrlPatterns("/*"); | ||
registration.addInitParameter("paramName", "paramValue"); | ||
registration.setName("sessionFilter"); | ||
registration.setOrder(1); | ||
return registration; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
第16课:综合实战用户管理系统/user-manage/src/main/java/com/neo/entity/UserEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.neo.entity; | ||
|
||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
|
||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
public class UserEntity implements Serializable{ | ||
private String id; | ||
private String userName; | ||
private String userType; | ||
private String password; | ||
private String email; | ||
private int age; | ||
private Date regTime; | ||
private String state; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUserName() { | ||
return userName; | ||
} | ||
|
||
public void setUserName(String userName) { | ||
this.userName = userName; | ||
} | ||
|
||
public String getUserType() { | ||
return userType; | ||
} | ||
|
||
public void setUserType(String userType) { | ||
this.userType = userType; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
public Date getRegTime() { | ||
return regTime; | ||
} | ||
|
||
public void setRegTime(Date regTime) { | ||
this.regTime = regTime; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public void setState(String state) { | ||
this.state = state; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
第16课:综合实战用户管理系统/user-manage/src/main/java/com/neo/param/LoginParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.neo.param; | ||
|
||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.hibernate.validator.constraints.Email; | ||
import org.hibernate.validator.constraints.Length; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
|
||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.Min; | ||
|
||
|
||
public class LoginParam { | ||
@NotEmpty(message="姓名不能为空") | ||
private String loginName; | ||
@NotEmpty(message="密码不能为空") | ||
@Length(min=6,message="密码长度不能小于6位") | ||
private String password; | ||
|
||
public String getLoginName() { | ||
return loginName; | ||
} | ||
|
||
public void setLoginName(String loginName) { | ||
this.loginName = loginName; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this); | ||
} | ||
} |
Oops, something went wrong.