Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
godcheese committed Mar 15, 2020
1 parent 3b8316a commit d2e6f7b
Show file tree
Hide file tree
Showing 30 changed files with 82 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

## Changelog
- v0.7.1 2020.03.15
- 修复 jar 包运行登录界面验证码图片生成失败问题
- v0.7.0 2020.03.08
- 新的界面(20200307)
- v0.6.5 2019.11.26
Expand Down
47 changes: 17 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

<groupId>com.gioov</groupId>
<artifactId>nimrod</artifactId>
<version>0.7.0</version>
<!-- jar 打包引用此属性值 -->
<!-- <packaging>jar</packaging>-->
<!-- war 打包引用此属性值 -->
<packaging>war</packaging>
<version>0.7.1</version>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<description>Demo project for Spring Boot</description>
<url>http://www.godcheese.com/</url>
Expand Down Expand Up @@ -43,7 +40,7 @@

<repositories>
<repository>
<id>godcheese</id>
<id>godcheese-github-maven-repository</id>
<url>https://raw.githubusercontent.com/godcheese/maven-repository/master/repository</url>
</repository>
</repositories>
Expand All @@ -52,7 +49,7 @@
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -83,20 +80,14 @@
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
<version>1.2.13</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <optional>true</optional>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down Expand Up @@ -129,13 +120,13 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -154,19 +145,25 @@
<version>1.0.0</version>
</dependency>
</dependencies>

<build>
<finalName>${finalName}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 如果没有该项配置,devtools 不会起作用,即应用不会 restart -->
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -199,16 +196,6 @@
<include>LICENSE</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/lib</directory>
<!-- jar 打包引用此属性值 -->
<!-- <targetPath>BOOT-INF/lib</targetPath> -->
<!-- war 打包引用此属性值 -->
<targetPath>${project.basedir}/target/${project.build.finalName}/WEB-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
</build>
</project>
2 changes: 1 addition & 1 deletion scripts/git_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ git commit -m "$REMARK"
echo "Submit code..."
git push origin master
echo "Submit complete,close..."
cd "${CURRENT_DIR}" || exit
cd "${CURRENT_DIR}" || exit
2 changes: 1 addition & 1 deletion scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SCRIPTS_DIR=$(cd "$(dirname $0)" || exit; pwd)
cd "${SCRIPTS_DIR}" || exit
cd ..
./mvnw clean package -DskipTests=true -Dmaven.javadoc.skip=true -Dspring-boot.run.profiles=prod
cd "${CURRENT_DIR}" || exit
cd "${CURRENT_DIR}" || exit
34 changes: 15 additions & 19 deletions src/main/java/com/gioov/NimrodBootstrap.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.gioov;

import com.gioov.nimrod.common.others.Common;
import com.gioov.nimrod.common.others.SpringContextUtil;
import com.gioov.nimrod.common.properties.NimrodProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,6 +25,9 @@
@SpringBootApplication
public class NimrodBootstrap extends SpringBootServletInitializer {

private static final String NIMROD_VERSION = "0.7.1";
private static final String NIMROD_URL = "https://github.com/godcheese/nimrod";

private static final Logger LOGGER = LoggerFactory.getLogger(NimrodBootstrap.class);

public static void main(String[] args) {
Expand All @@ -45,24 +46,20 @@ protected WebApplicationContext run(SpringApplication application) {
}

private static void bootstrap(WebApplicationContext webApplicationContext) {
NimrodProperties nimrodProperties = (NimrodProperties) SpringContextUtil.getBean("nimrodProperties", NimrodProperties.class);
String nimrodVersion = nimrodProperties.getVersion();
String nimrodUrl = nimrodProperties.getUrl();

// @formatter:off
String banner =
" .__ __. __ .___ ___. .______ ______ _______ \n" +
" | \\ | | | | | \\/ | | _ \\ / __ \\ | \\ \n" +
" | \\| | | | | \\ / | | |_) | | | | | | .--. |\n" +
" | . ` | | | | |\\/| | | / | | | | | | | |\n" +
" | |\\ | | | | | | | | |\\ \\----.| `--' | | '--' |\n" +
" |__| \\__| |__| |__| |__| | _| `._____| \\______/ |_______/ ";
" | \\ | | | | | \\/ | | _ \\ / __ \\ | \\ \n" +
" | \\| | | | | \\ / | | |_) | | | | | | .--. |\n" +
" | . ` | | | | |\\/| | | / | | | | | | | |\n" +
" | |\\ | | | | | | | | |\\ \\----.| `--' | | '--' |\n" +
" |__| \\__| |__| |__| |__| | _| `._____| \\______/ |_______/ ";

String nimrod =
"\n -------------------------------------------------" +
"\n | Nimrod version: " + nimrodVersion + " |" +
"\n | Homepage: " + nimrodUrl +" |" +
"\n -------------------------------------------------";
"\n | Nimrod version: " + NIMROD_VERSION + " |" +
"\n | Homepage: " + NIMROD_URL +" |" +
"\n -------------------------------------------------";

Common.getHost(webApplicationContext);
String scheme = Common.Host.scheme;
Expand All @@ -76,11 +73,10 @@ private static void bootstrap(WebApplicationContext webApplicationContext) {
}
String appRunningAt =
"\n App running at:" +
"\n - Server: " + Common.Host.serverInfo +
"\n - Local: " + local +
"\n - Network: " + network;
// @formatter:on

"\n - Server: " + Common.Host.serverInfo +
"\n - Local: " + local +
"\n - Network: " + network;
// @formatter:on
LOGGER.info("\n\n" + banner + "\n" + nimrod + "\n" + appRunningAt + "\n");
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AuthenticationFailureHandler implements org.springframework.securit
@Override
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
httpServletResponse.setStatus(HttpStatus.NOT_FOUND.value());
httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
PrintWriter printWriter = httpServletResponse.getWriter();

// 检查 e 是否为验证码错误类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AuthenticationSuccessHandler implements org.springframework.securit
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
SimpleUser simpleUser = (SimpleUser) authentication.getPrincipal();
httpServletResponse.setStatus(HttpStatus.OK.value());
httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
PrintWriter printWriter = httpServletResponse.getWriter();
printWriter.write(common.objectToJson(new SuccessEntity(simpleUser)));
printWriter.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class LogoutSuccessHandler implements org.springframework.security.web.au
@Override
public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
httpServletResponse.setStatus(HttpStatus.OK.value());
httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
PrintWriter printWriter = httpServletResponse.getWriter();
printWriter.write(common.objectToJson(new SuccessEntity("注销成功")));
printWriter.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = System.Api.DICTIONARY, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = System.Api.DICTIONARY, produces = MediaType.APPLICATION_JSON_VALUE)
public class DictionaryRestController {

private static final String DICTIONARY = "/API/SYSTEM/DICTIONARY";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = System.Api.FILE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = System.Api.FILE, produces = MediaType.APPLICATION_JSON_VALUE)
public class FileRestController {
private static final Logger LOGGER = LoggerFactory.getLogger(FileRestController.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = System.Api.OPERATION_LOG, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = System.Api.OPERATION_LOG, produces = MediaType.APPLICATION_JSON_VALUE)
public class OperationLogRestController {

private static final String OPERATION_LOG = "/API/SYSTEM/OPERATION_LOG";
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/com/gioov/nimrod/system/api/SystemRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -26,7 +29,6 @@
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
Expand All @@ -52,6 +54,8 @@ public class SystemRestController {

public static final String VERIFY_CODE_NAME = "verifyCode";

private static ResourceLoader resourceLoader = new DefaultResourceLoader();

@Autowired
private DictionaryService dictionaryService;

Expand Down Expand Up @@ -83,16 +87,23 @@ public void verifyCode(HttpServletResponse httpServletResponse, HttpServletReque
fontColor = fontColor.length() == 7 ? fontColor : "#FFFFFF";
ImageUtil.VerifyCodeImage verifyCodeImage;
try {
URL url = ResourceUtil.getResource(fontPath);
LOGGER.info("{}", url.getPath());
LOGGER.info("{}",url.getFile());
File fontFile = new File(URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8.name()));
InputStream fontInputStream = new FileInputStream(fontFile);
LOGGER.info("fontFile.exists()={}", fontFile.exists());
if(!fontFile.exists()) {
throw new BaseResponseException(failureEntity.i18n("system.verify_code_create_fail_font_not_exists"));

if(fontPath.toLowerCase().contains(ResourceLoader.CLASSPATH_URL_PREFIX)) {
Resource fontResource = resourceLoader.getResource(fontPath);
if(!fontResource.getFile().exists()) {
throw new BaseResponseException(failureEntity.i18n("system.verify_code_create_fail_font_not_exists"));
}
InputStream fontInputStream = fontResource.getInputStream();
verifyCodeImage = ImageUtil.createVerifyCodeImage(114, 40, ColorUtil.getRGBColorByHexString(hexBackgroundColor), RandomUtil.randomString(stringLength, RandomUtil.NUMBER_LETTER), ColorUtil.getRGBColorByHexString(fontColor), fontInputStream, yawp, interLine, expiration);

} else {
URL url = ResourceUtil.getResource(fontPath);
File fontFile = new File(URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8.name()));
if(!fontFile.exists()) {
throw new BaseResponseException(failureEntity.i18n("system.verify_code_create_fail_font_not_exists"));
}
verifyCodeImage = ImageUtil.createVerifyCodeImage(114, 40, ColorUtil.getRGBColorByHexString(hexBackgroundColor), RandomUtil.randomString(stringLength, RandomUtil.NUMBER_LETTER), ColorUtil.getRGBColorByHexString(fontColor), fontFile, yawp, interLine, expiration);
}
verifyCodeImage = ImageUtil.createVerifyCodeImage(114, 40, ColorUtil.getRGBColorByHexString(hexBackgroundColor), RandomUtil.randomString(stringLength, RandomUtil.NUMBER_LETTER), ColorUtil.getRGBColorByHexString(fontColor), fontInputStream, yawp, interLine, expiration);

httpServletResponse.addHeader("Pragma", "no-cache");
httpServletResponse.addHeader("Cache-Control", "no-cache");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = User.Api.API_CATEGORY, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = User.Api.API_CATEGORY, produces = MediaType.APPLICATION_JSON_VALUE)
public class ApiCategoryRestController {

private static final String API_CATEGORY = "/API/SYSTEM/API_CATEGORY";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = User.Api.API, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = User.Api.API, produces = MediaType.APPLICATION_JSON_VALUE)
public class ApiRestController {

private static final String API = "/API/SYSTEM/API";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = User.Api.DEPARTMENT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = User.Api.DEPARTMENT, produces = MediaType.APPLICATION_JSON_VALUE)
public class DepartmentRestController {

private static final Logger LOGGER = LoggerFactory.getLogger(DepartmentRestController.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @date 2018-02-22
*/
@RestController
@RequestMapping(value = User.Api.ROLE_AUTHORITY, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = User.Api.ROLE_AUTHORITY, produces = MediaType.APPLICATION_JSON_VALUE)
public class RoleAuthorityRestController {

private static final String ROLE_AUTHORITY = "/API/USER/ROLE_AUTHORITY";
Expand Down
Loading

0 comments on commit d2e6f7b

Please sign in to comment.