Skip to content

Commit

Permalink
add 综合实战用户管理
Browse files Browse the repository at this point in the history
  • Loading branch information
ityouknow committed Dec 3, 2017
1 parent 14fa007 commit 3805f85
Show file tree
Hide file tree
Showing 28 changed files with 7,951 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
- [第09课:如何玩转 Redis](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f97f0d68673133615f7481)
- [第10课:Redis 实现数据缓存和 Session 共享](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f97f3f68673133615f749b)
- [第11课:RabbitMQ 详解](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f97f9c68673133615f74de)
- [第12课:MongoDB 实战](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f97fd568673133615f750e)
- [第12课:MongoDB 实战](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f97fd568673133615f750e)
- [第13课:使用 Spring Boot 发送邮件](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f9800d68673133615f7529)
- [第14课:Spring Boot 集成 Quartz](http://gitbook.cn/gitchat/column/59f5daa149cd4330613605ba/topic/59f9806168673133615f7564)



Expand Down
75 changes: 75 additions & 0 deletions 第16课:综合实战用户管理系统/user-manage/pom.xml
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>
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);
}
}

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 {
}
*/
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");
}
}
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;
}
}
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);
}
}
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);
}
}
Loading

0 comments on commit 3805f85

Please sign in to comment.