mirror of https://github.com/halo-dev/halo
Log login and logout action.
parent
b3122184e1
commit
7f7710ed67
|
@ -1,36 +0,0 @@
|
||||||
package run.halo.app.model.support;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <pre>
|
|
||||||
* 日志常量
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @author ryanwang
|
|
||||||
* @date : 2018/1/19
|
|
||||||
*/
|
|
||||||
public interface LogsRecord {
|
|
||||||
|
|
||||||
String INSTALL = "初始化博客";
|
|
||||||
|
|
||||||
String LOGIN = "登录后台";
|
|
||||||
|
|
||||||
String LOGIN_SUCCESS = "登录成功";
|
|
||||||
|
|
||||||
String LOGIN_ERROR = "登录失败";
|
|
||||||
|
|
||||||
String LOGOUT = "退出登录";
|
|
||||||
|
|
||||||
String PUSH_POST = "发表文章";
|
|
||||||
|
|
||||||
String PUSH_PAGE = "发表页面";
|
|
||||||
|
|
||||||
String REMOVE_POST = "删除文章";
|
|
||||||
|
|
||||||
String CHANGE_THEME = "更换主题";
|
|
||||||
|
|
||||||
String UPLOAD_THEME = "上传主题";
|
|
||||||
|
|
||||||
String UPLOAD_FILE = "上传附件";
|
|
||||||
|
|
||||||
String REMOVE_FILE = "移除附件";
|
|
||||||
}
|
|
|
@ -17,6 +17,7 @@ public class QiNiuPutSet {
|
||||||
* 文件hash值
|
* 文件hash值
|
||||||
*/
|
*/
|
||||||
public String hash;
|
public String hash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件名
|
* 文件名
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run.halo.app.service.impl;
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -10,6 +11,7 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
import run.halo.app.cache.StringCacheStore;
|
||||||
import run.halo.app.config.properties.HaloProperties;
|
import run.halo.app.config.properties.HaloProperties;
|
||||||
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
import run.halo.app.exception.ServiceException;
|
import run.halo.app.exception.ServiceException;
|
||||||
|
@ -17,6 +19,7 @@ import run.halo.app.model.dto.EnvironmentDTO;
|
||||||
import run.halo.app.model.dto.StatisticDTO;
|
import run.halo.app.model.dto.StatisticDTO;
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
import run.halo.app.model.enums.CommentStatus;
|
import run.halo.app.model.enums.CommentStatus;
|
||||||
|
import run.halo.app.model.enums.LogType;
|
||||||
import run.halo.app.model.enums.Mode;
|
import run.halo.app.model.enums.Mode;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.params.LoginParam;
|
import run.halo.app.model.params.LoginParam;
|
||||||
|
@ -76,6 +79,8 @@ public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
private final HaloProperties haloProperties;
|
private final HaloProperties haloProperties;
|
||||||
|
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
private final String driverClassName;
|
private final String driverClassName;
|
||||||
|
|
||||||
private final String mode;
|
private final String mode;
|
||||||
|
@ -92,6 +97,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
StringCacheStore cacheStore,
|
StringCacheStore cacheStore,
|
||||||
RestTemplate restTemplate,
|
RestTemplate restTemplate,
|
||||||
HaloProperties haloProperties,
|
HaloProperties haloProperties,
|
||||||
|
ApplicationEventPublisher eventPublisher,
|
||||||
@Value("${spring.datasource.driver-class-name}") String driverClassName,
|
@Value("${spring.datasource.driver-class-name}") String driverClassName,
|
||||||
@Value("${spring.profiles.active:prod}") String mode) {
|
@Value("${spring.profiles.active:prod}") String mode) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
|
@ -106,6 +112,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
this.haloProperties = haloProperties;
|
this.haloProperties = haloProperties;
|
||||||
|
this.eventPublisher = eventPublisher;
|
||||||
this.driverClassName = driverClassName;
|
this.driverClassName = driverClassName;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +133,8 @@ public class AdminServiceImpl implements AdminService {
|
||||||
userService.getByEmailOfNonNull(username) : userService.getByUsernameOfNonNull(username);
|
userService.getByEmailOfNonNull(username) : userService.getByUsernameOfNonNull(username);
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
log.error("Failed to find user by name: " + username, e);
|
log.error("Failed to find user by name: " + username, e);
|
||||||
|
eventPublisher.publishEvent(new LogEvent(this, "", LogType.LOGIN_FAILED, loginParam.getUsername()));
|
||||||
|
|
||||||
throw new BadRequestException(mismatchTip);
|
throw new BadRequestException(mismatchTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +142,8 @@ public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
if (!userService.passwordMatch(user, loginParam.getPassword())) {
|
if (!userService.passwordMatch(user, loginParam.getPassword())) {
|
||||||
// If the password is mismatch
|
// If the password is mismatch
|
||||||
|
eventPublisher.publishEvent(new LogEvent(this, "", LogType.LOGIN_FAILED, loginParam.getUsername()));
|
||||||
|
|
||||||
throw new BadRequestException(mismatchTip);
|
throw new BadRequestException(mismatchTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +152,9 @@ public class AdminServiceImpl implements AdminService {
|
||||||
throw new BadRequestException("您已登录,请不要重复登录");
|
throw new BadRequestException("您已登录,请不要重复登录");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log it then login successful
|
||||||
|
eventPublisher.publishEvent(new LogEvent(this, user.getUsername(), LogType.LOGGED_IN, user.getNickname()));
|
||||||
|
|
||||||
// Generate new token
|
// Generate new token
|
||||||
return buildAuthToken(user);
|
return buildAuthToken(user);
|
||||||
}
|
}
|
||||||
|
@ -170,6 +184,8 @@ public class AdminServiceImpl implements AdminService {
|
||||||
cacheStore.delete(SecurityUtils.buildRefreshTokenKey(user));
|
cacheStore.delete(SecurityUtils.buildRefreshTokenKey(user));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eventPublisher.publishEvent(new LogEvent(this, user.getUsername(), LogType.LOGGED_OUT, user.getNickname()));
|
||||||
|
|
||||||
log.info("You have been logged out, looking forward to your next visit!");
|
log.info("You have been logged out, looking forward to your next visit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,16 +24,16 @@
|
||||||
<#-- 站点验证代码 -->
|
<#-- 站点验证代码 -->
|
||||||
<#macro verification>
|
<#macro verification>
|
||||||
<#if options.seo_verification_google??>
|
<#if options.seo_verification_google??>
|
||||||
<meta name="google-site-verification" content="${options.seo_verification_google}" />
|
<meta name="google-site-verification" content="${options.seo_verification_google}"/>
|
||||||
</#if>
|
</#if>
|
||||||
<#if options.seo_verification_bing??>
|
<#if options.seo_verification_bing??>
|
||||||
<meta name="msvalidate.01" content="${options.seo_verification_bing}" />
|
<meta name="msvalidate.01" content="${options.seo_verification_bing}"/>
|
||||||
</#if>
|
</#if>
|
||||||
<#if options.seo_verification_baidu??>
|
<#if options.seo_verification_baidu??>
|
||||||
<meta name="baidu-site-verification" content="${options.seo_verification_baidu}" />
|
<meta name="baidu-site-verification" content="${options.seo_verification_baidu}"/>
|
||||||
</#if>
|
</#if>
|
||||||
<#if options.seo_verification_qihu??>
|
<#if options.seo_verification_qihu??>
|
||||||
<meta name="360-site-verification" content="${options.seo_verification_qihu}" />
|
<meta name="360-site-verification" content="${options.seo_verification_qihu}"/>
|
||||||
</#if>
|
</#if>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
@ -51,17 +51,28 @@
|
||||||
</#if>
|
</#if>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
<#-- global head -->
|
||||||
<#macro head>
|
<#macro head>
|
||||||
<#if options.spider_disabled!false>
|
<#if options.spider_disabled!false>
|
||||||
<meta name="robots" content="none">
|
<meta name="robots" content="none">
|
||||||
</#if>
|
</#if>
|
||||||
<meta name="generator" content="Halo ${version!}" />
|
<meta name="generator" content="Halo ${version!}"/>
|
||||||
<@custom_head />
|
<@custom_head />
|
||||||
<@verification />
|
<@verification />
|
||||||
<@favicon />
|
<@favicon />
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
<#-- global footer -->
|
||||||
<#macro footer>
|
<#macro footer>
|
||||||
<@footer_info />
|
<@footer_info />
|
||||||
<@statistics />
|
<@statistics />
|
||||||
|
</#macro>
|
||||||
|
|
||||||
|
<#-- post comment module -->
|
||||||
|
<#macro comment post,type>
|
||||||
|
<#if !post.disallowComment!false>
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
|
||||||
|
<script src="//cdn.jsdelivr.net/gh/halo-dev/halo-comment@1.0.2/dist/halo-comment.min.js"></script>
|
||||||
|
<halo-comment id="${post.id}" type="${type}"/>
|
||||||
|
</#if>
|
||||||
</#macro>
|
</#macro>
|
Loading…
Reference in New Issue