Skip to content

Commit

Permalink
add login application
Browse files Browse the repository at this point in the history
  • Loading branch information
leelance committed Jan 3, 2017
1 parent 640d0a7 commit cefbc5d
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.lance.activiti.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lance.activiti.common.SystemConstants;
import com.lance.activiti.common.captcha.KaptchaContext;
import com.lance.activiti.common.captcha.KaptchaType;
import com.lance.activiti.common.shiro.FormAuthenticationFilterExt;
import com.lance.activiti.utils.ShiroSessionUtils;

@Controller
public class LoginController {
private Logger logger = LogManager.getLogger(getClass());

/**
* Login
* @return
*/
@RequestMapping(value="login", method=RequestMethod.GET)
public String login(){
return "login.jsp";
}

/**
* 登录失败,真正登录的POST请求由Filter完成
* @author lance
* @since 2016年11月5日下午3:59:17
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public String loginFail(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirect) {
Object principal = ShiroSessionUtils.getSubject().getPrincipal();

// 如果已经登录,则跳转到管理首页
if(principal != null){
return "redirect:/admin/welcome";
}

String username = WebUtils.getCleanParam(request, FormAuthenticationFilterExt.DEFAULT_USERNAME_PARAM);
String message = (String)request.getAttribute(FormAuthenticationFilterExt.DEFAULT_MESSAGE_PARAM);

if (StringUtils.isBlank(message) || StringUtils.equals(message, "null")){
message = "用户或密码错误, 请重试.";
}

redirect.addFlashAttribute(FormAuthenticationFilterExt.DEFAULT_USERNAME_PARAM, username);
redirect.addFlashAttribute(FormAuthenticationFilterExt.DEFAULT_MESSAGE_PARAM, message);

if (logger.isDebugEnabled()){
logger.debug("login fail, message: {}", message);
}

return "redirect:/login";
}

/**
* 登录验证码
* @param req
* @param res
* @throws ServletException
* @throws IOException
*/
@RequestMapping(value = "kaptcha/backloginCapt", method = RequestMethod.GET)
public void backloginCapt(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
new KaptchaContext().generate(KaptchaType.SIMPLE.value(), req, res, SystemConstants.ADMIN_VALID_KEY);
}

/**
* 后台管理首页
* @author lance
* @since 2016年11月25日下午2:49:04
*/
@RequestMapping("admin/index")
public String index() {
return "admin/index.jsp";
}

@RequestMapping("admin/welcome")
public String welcome() {
return "admin/welcome.jsp";
}

/**
* 用户退出登录
* @author lance
* @since 2016年11月25日下午2:43:47
*/
@RequestMapping("admin/logout")
public String logout() {
ShiroSessionUtils.getSubject().logout();
return "redirect:/back/login";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.lance.activiti.web.process;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lance.activiti.common.page.PageInfo;
import com.lance.activiti.model.process.ProcessDefineInfo;
import com.lance.activiti.service.process.ProcessDefineService;
import com.lance.activiti.utils.FastJsonUtils;

/**
* 流程管理
* @author Administrator
*/
@Controller
@RequestMapping("/admin/process/manage/")
public class ProcessManageController {
@Autowired
private ProcessDefineService processDefineService;

/**
* 跳转列表页面
* @return
*/
@RequestMapping(value="list", method=RequestMethod.GET)
public String list(){
return "admin/process/process-manage-list.jsp";
}

/**
* 查询列表Post
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value="list", method=RequestMethod.POST)
public String list(@RequestParam Map<String, Object> params){
List<ProcessDefineInfo> list = processDefineService.findAll();
String page = params.get("page")+"";

PageInfo<ProcessDefineInfo> pageInfo = new PageInfo<>(list.size(), Integer.valueOf(page));
pageInfo.setRows(list);
return FastJsonUtils.toJson(pageInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lance.activiti.web.system;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
* 角色管理
* @author Administrator
*/
@Controller
@RequestMapping("admin/system/role")
public class RoleController {

/**
* 角色首页
* @return
*/
@RequestMapping(value={"","/","index"}, method=RequestMethod.GET)
public String index() {
return "admin/system/index.jsp";
}
}
47 changes: 47 additions & 0 deletions spring-boot-activiti/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# IDENTITY (ContextIdApplicationContextInitializer)
spring.application.index=Spring-boot-Activiti.v1.1
spring.application.name=Spring-boot-ACTIVITI

#Server
server.port=80
server.jsp-servlet.class-name=org.apache.jasper.servlet.JspServlet

security.basic.enabled=false
management.security.enabled=false

#MVC
spring.mvc.view.prefix=/WEB-INF/views/

#LOG
logging.config=classpath:log4j2.xml

#MYBATIS
mybatis.type-aliases-package=com.lance.activiti.model
mybatis.mapper-locations=classpath*:/mapper/**/*Mapper.xml
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.use-generated-keys=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=30

#DATASOURCE
spring.datasource.continueOnError=true

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost/demo-schema
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.validationQuery=SELECT 1
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters=stat
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
1 change: 1 addition & 0 deletions spring-boot-activiti/src/main/resources/common.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deploy.imgPath=E:\\gitwork\\spring-boot-all\\spring-boot-activiti\\src\\main\\resources\\processes\\
28 changes: 28 additions & 0 deletions spring-boot-activiti/src/main/resources/ehcache-shiro.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="shirocache">

<diskStore path="java.io.tmpdir"/>

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
/>

<cache name="shiro-activeSessionCache"
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="1800"/>

<cache name="org.apache.shiro.realm.SimpleAccountRealm.authorization"
maxElementsInMemory="100"
eternal="false"
timeToLiveSeconds="1800"
overflowToDisk="false"/>
</ehcache>
61 changes: 61 additions & 0 deletions spring-boot-activiti/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="off">
<!-- 日志文件目录和压缩文件 -->
<Properties>
<Property name="fileName">/tmp/logs</Property>
<Property name="fileGz">/tmp/logs/7z</Property>
</Properties>
<Appenders>
<!--这个输出控制台的配置 -->
<Console name="console" target="SYSTEM_OUT">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch) -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="NEUTRAL" />
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="NEUTRAL" />
<!--输出日志的格式 -->
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} %L %M - %msg%xEx%n" />
</Console>

<!--这个会打印出所有的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档 -->
<RollingRandomAccessFile name="rollingInfoFile" fileName="${fileName}/springboot-info.log" immediateFlush="false"
filePattern="${fileGz}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.springboot-info.gz">
<PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss z} [%t] %-5level %logger{36} %L %M - %msg%xEx%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
<Filters>
<!-- 只记录info级别信息 -->
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
<!-- 指定每天的最大压缩包个数,默认7个,超过了会覆盖之前的 -->
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>


<RollingRandomAccessFile name="rollingErrorFile" fileName="${fileName}springboot-error.log" immediateFlush="false"
filePattern="${fileGz}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.springboot-error.gz">
<PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss z} [%t] %-5level %logger{36} %L %M - %msg%xEx%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
<Filters>
<!-- 只记录error级别信息 -->
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
<!-- 指定每天的最大压缩包个数,默认7个,超过了会覆盖之前的 -->
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>

</Appenders>

<Loggers>
<!-- 全局配置,默认所有的Logger都继承此配置 -->
<AsyncRoot level="debug" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="rollingInfoFile"/>
<AppenderRef ref="rollingErrorFile"/>
</AsyncRoot>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lance.activiti.mapper.process.ProcessDefineMapper">

<!-- findAll -->
<select id="findAll" resultType="ProcessDefineInfo">
select *from t_process_define
</select>

<!-- findOne -->
<select id="findOne" resultType="ProcessDefineInfo">
select *from t_process_define where id=#{value}
</select>

<!-- save -->
<insert id="save" parameterType="ProcessDefineInfo">
insert into t_process_define(process_name,process_key,process_file, create_time)values(
#{processName},#{processKey},#{processFile},now()
)
</insert>

<!-- update -->
<update id="update" parameterType="ProcessDefineInfo">
update t_process_define SET
process_name=#{processName},
process_key=#{processKey},
process_file=#{processFile},
update_time=now()
where id=#{id}
</update>

<!-- delete -->
<delete id="delete">
delete from t_process_define where id=#{value}
</delete>
</mapper>
Loading

0 comments on commit cefbc5d

Please sign in to comment.