Skip to content

Commit

Permalink
3.0版本开发
Browse files Browse the repository at this point in the history
  • Loading branch information
langhsu committed Jan 22, 2019
1 parent aa80d86 commit fa21ce5
Show file tree
Hide file tree
Showing 152 changed files with 8,841 additions and 2,800 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
- 更多文档及教程见 [http://mtons.com/dock/mblog](http://mtons.com/dock/mblog)
- QQ交流群:378433412

### 最新版本(3.0)更新内容:
1. 注册开关, 发文开关, 评论开发(全关就是个人博客)
2. 后台主题替换及功能完善
3. 上传文件支持又拍云
4. Docker
5. 添加启动脚本(windows/linux)
6. 升级为spring-boot2

### 最新版本(2.8)更新内容:
1. 项目结构调整
2. 合并了之前的内嵌数据库分支, 采用通过maven环境变量的方式可切换mysql/h2(懒人福利)
Expand Down
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 拉取最新的源码
# git pull

# 停止已运行的服务
# sh run.sh stop

# 执行打包
mvn clean package -Dmaven.test.skip=true

# 运行
# sh run.sh start

echo "mblog打包完毕, 可使用sh run.sh start进行启动"
50 changes: 25 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mtons.mblog</groupId>
<artifactId>mblog</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>latest</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -18,13 +18,14 @@
<coobird.thumbnailator>0.4.8</coobird.thumbnailator>
<alibaba.fastjson>1.2.16</alibaba.fastjson>
<org.jsoup>1.9.2</org.jsoup>
<apache.lucene>5.5.4</apache.lucene>
<apache.lucene>5.5.5</apache.lucene>
<upyun.sdk.version>4.0.1</upyun.sdk.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<version>2.1.2.RELEASE</version>
<relativePath/>
</parent>

Expand All @@ -34,6 +35,14 @@
<artifactId>javax.servlet-api</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down Expand Up @@ -109,7 +118,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.6.3.Final</version>
<version>5.11.0.Final</version>
</dependency>
<!--hibernate search dependency-->
<dependency>
Expand Down Expand Up @@ -138,24 +147,20 @@
<!-- shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<artifactId>shiro-ehcache</artifactId>
<version>${shiro}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<artifactId>shiro-spring-boot-web-starter</artifactId>
<version>${shiro}</version>
</dependency>

<!-- 又拍云SDK -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>${shiro}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<groupId>com.upyun</groupId>
<artifactId>java-sdk</artifactId>
<version>${upyun.sdk.version}</version>
</dependency>

<!-- config -->
Expand All @@ -171,6 +176,11 @@
<scope>test</scope>
</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>
Expand Down Expand Up @@ -259,16 +269,6 @@
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<mainClass>com.mtons.mblog.BootApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<!-- 用于打包jar -->
<goal>repackage</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
68 changes: 68 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
APP_NAME=mblog-latest.jar

usage() {
echo "case: sh run.sh [start|stop|restart|status]"
exit 1
}

is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}

start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} running. pid=${pid}"
else
nohup java -jar ./target/$APP_NAME > log.file 2>log.error &
echo "${APP_NAME} started"
fi
}

stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
echo "${pid} stopped"
else
echo "${APP_NAME} not running"
fi
}

status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} running. Pid is ${pid}"
else
echo "${APP_NAME} not running"
fi
}

restart(){
stop
start
}

case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
23 changes: 11 additions & 12 deletions src/main/java/com/mtons/mblog/BootApplication.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package com.mtons.mblog;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* SprintBootApplication
*/
@Slf4j
@SpringBootApplication
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
public class BootApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(BootApplication.class);
}
@EnableCaching
@EnableTransactionManagement
public class BootApplication {

/**
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(BootApplication.class, args);
ApplicationContext context = SpringApplication.run(BootApplication.class, args);
String serverPort = context.getEnvironment().getProperty("server.port");
log.info("mblog started at http://localhost:" + serverPort);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @author langhsu on 2015/9/5.
*/
public interface SiteConfig {
public interface SiteConst {
/**
* 站点类配置
*/
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/mtons/mblog/base/oauth/OauthBaidu.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.mtons.mblog.base.oauth.utils.OathConfig;
import com.mtons.mblog.base.oauth.utils.TokenUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand All @@ -16,7 +17,7 @@
import java.util.Map;

public class OauthBaidu extends Oauth {
private static final Logger LOGGER = Logger.getLogger(OauthBaidu.class);
private static final Logger LOGGER = LoggerFactory.getLogger(OauthBaidu.class);
private static final String AUTH_URL = "https://openapi.baidu.com/oauth/2.0/authorize";
private static final String TOKEN_URL = "https://openapi.baidu.com/oauth/2.0/token";
private static final String USER_INFO_URL = "https://openapi.baidu.com/rest/2.0/passport/users/getInfo";
Expand All @@ -32,7 +33,7 @@ public OauthBaidu() {
}

public String getAuthorizeUrl(String state) throws UnsupportedEncodingException {
Map params = new HashMap();
Map<String, String> params = new HashMap<>();
params.put("response_type", "code");
params.put("client_id", getClientId());
params.put("redirect_uri", getRedirectUri());
Expand All @@ -43,7 +44,7 @@ public String getAuthorizeUrl(String state) throws UnsupportedEncodingException
}

public String getTokenByCode(String code) throws IOException, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException {
Map params = new HashMap();
Map<String, String> params = new HashMap<>();
params.put("code", code);
params.put("client_id", getClientId());
params.put("client_secret", getClientSecret());
Expand All @@ -55,7 +56,7 @@ public String getTokenByCode(String code) throws IOException, KeyManagementExcep
}

public String getUserInfo(String accessToken) throws IOException, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException {
Map params = new HashMap();
Map<String, String> params = new HashMap<>();
params.put("access_token", accessToken);
return super.doPost("https://openapi.baidu.com/rest/2.0/passport/users/getInfo", params);
}
Expand All @@ -68,7 +69,7 @@ public JSONObject getUserInfoByCode(String code) throws IOException, KeyManageme
String userInfo = getUserInfo(accessToken);
JSONObject dataMap = JSON.parseObject(userInfo);
dataMap.put("access_token", accessToken);
LOGGER.debug(dataMap);
LOGGER.debug(JSON.toJSONString(dataMap));
return dataMap;
}
}
13 changes: 7 additions & 6 deletions src/main/java/com/mtons/mblog/base/oauth/OauthDouban.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import com.mtons.mblog.base.oauth.utils.OpenOauthBean;
import com.mtons.mblog.base.oauth.utils.TokenUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand All @@ -18,7 +19,7 @@
import java.util.Map;

public class OauthDouban extends Oauth {
private static final Logger LOGGER = Logger.getLogger(OauthDouban.class);
private static final Logger LOGGER = LoggerFactory.getLogger(OauthDouban.class);
private static final String AUTH_URL = "https://www.douban.com/service/auth2/auth";
private static final String TOKEN_URL = "https://www.douban.com/service/auth2/token";
private static final String USER_INFO_URL = "https://api.douban.com/v2/user/~me";
Expand All @@ -34,7 +35,7 @@ public OauthDouban() {
}

public String getAuthorizeUrl(String state) throws UnsupportedEncodingException {
Map params = new HashMap();
Map<String, String> params = new HashMap<>();
params.put("response_type", "code");
params.put("client_id", getClientId());
params.put("redirect_uri", getRedirectUri());
Expand All @@ -45,7 +46,7 @@ public String getAuthorizeUrl(String state) throws UnsupportedEncodingException
}

public String getTokenByCode(String code) throws IOException, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException {
Map params = new HashMap();
Map<String, String> params = new HashMap<>();
params.put("code", code);
params.put("client_id", getClientId());
params.put("client_secret", getClientSecret());
Expand All @@ -57,7 +58,7 @@ public String getTokenByCode(String code) throws IOException, KeyManagementExcep
}

public JSONObject getUserInfo(String accessToken) throws IOException, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException {
Map params = new HashMap();
Map<String, String> params = new HashMap<>();
params.put("Authorization", "Bearer " + accessToken);
String userInfo = super.doGetWithHeaders("https://api.douban.com/v2/user/~me", params);
JSONObject dataMap = JSON.parseObject(userInfo);
Expand All @@ -72,7 +73,7 @@ public JSONObject getUserInfoByCode(String code) throws IOException, KeyManageme
}
JSONObject dataMap = getUserInfo(accessToken);
dataMap.put("access_token", accessToken);
LOGGER.debug(dataMap);
LOGGER.debug(JSON.toJSONString(dataMap));
return dataMap;
}

Expand Down
Loading

0 comments on commit fa21ce5

Please sign in to comment.