Skip to content

Commit

Permalink
1.update user login username and password are read by configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuachun committed Jun 22, 2021
1 parent d7e4808 commit 618a40b
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 156 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules/
dist/
target/
logs/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
9 changes: 0 additions & 9 deletions deploy/mysql/fateboard.sql

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/java/com/webank/ai/fate/board/dao/UserMapper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.alibaba.fastjson.JSON;
import com.webank.ai.fate.board.global.ErrorCode;
import com.webank.ai.fate.board.global.ResponseResult;
import com.webank.ai.fate.board.pojo.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

Expand Down
57 changes: 0 additions & 57 deletions src/main/java/com/webank/ai/fate/board/pojo/UserDO.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/com/webank/ai/fate/board/pojo/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.webank.ai.fate.board.pojo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
Expand Down
59 changes: 45 additions & 14 deletions src/main/java/com/webank/ai/fate/board/services/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,39 @@
*/
package com.webank.ai.fate.board.services;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.webank.ai.fate.board.dao.UserMapper;
import com.webank.ai.fate.board.pojo.UserDO;
import com.webank.ai.fate.board.pojo.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

@Service
public class UserService {
private final static Properties config = new Properties();
private static final Logger logger = LoggerFactory.getLogger(UserService.class);

@Autowired
UserMapper userMapper;

//@Autowired
//UserMapper userMapper;
public boolean login(UserDTO userDTO, HttpServletRequest httpServletRequest) {

String username = userDTO.getName();
String password = userDTO.getPassword();
String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
userDTO.setPassword(md5Password);
List<UserDO> userDOS = userMapper.find(userDTO);
if (userDOS.size() <= 0) {

//String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
//userDTO.setPassword(md5Password);
//List<UserDO> userDOS = userMapper.find(userDTO);
if (!checkUser(username, password)) {
return false;
} else {
HttpSession session = httpServletRequest.getSession();
session.setAttribute("USER", userDOS.get(0));
session.setAttribute("USER", userDTO);
return true;
}

Expand All @@ -53,4 +57,31 @@ public void logout(HttpServletRequest httpServletRequest) {
HttpSession session = httpServletRequest.getSession();
session.invalidate();
}

public boolean checkUser(String username, String password) {
updateConfig();
String usernameValue = getValue("server.board.login.username");
String passwordValue = getValue("server.board.login.password");
return username.equals(usernameValue) && password.equals(passwordValue);
}

public static void updateConfig() {
try {
String confP = "conf/application.properties";
String configP = "config/application.properties";
File configFile = new File(confP);
if (configFile.exists() || (configFile = new File(configP)).exists()) {
BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile));
config.load(bufferedReader);
} else {
config.load(UserService.class.getClassLoader().getResourceAsStream("application.properties"));
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}

public static String getValue(String key){
return config.getProperty(key);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ spring.datasource.druid.filter.config.enabled=false
spring.datasource.druid.web-stat-filter.enabled=false
spring.datasource.druid.stat-view-servlet.enabled=false
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
server.board.login.username=admin
server.board.login.password=admin
13 changes: 0 additions & 13 deletions src/main/resources/fate/fateboard/mapping/UserMapper.xml

This file was deleted.

66 changes: 34 additions & 32 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd"
debug="false" scan="true" scanPeriod="30 second">

<!-- <property name="PROJECT" value="fateboard"/>-->
<!-- <property name="PROJECT" value="fateboard"/>-->
<property name="ROOT" value="logs/"/>
<property name="FILESIZE" value="50MB"/>
<property name="MAXHISTORY" value="100"/>
<timestamp key="DATETIME" datePattern="yyyy-MM-dd HH:mm:ss"/>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
</filter>
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
<!--<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>-->
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n</pattern>
</encoder>
</appender>

<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
<!--<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>-->
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
Expand All @@ -30,17 +33,16 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${ROOT}%d/error.%d.log</fileNamePattern>
<maxHistory>${MAXHISTORY}</maxHistory>
<!-- <timeBasedFileNamingAndTriggeringPolicy-->
<!-- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
<!-- <timeBasedFileNamingAndTriggeringPolicy-->
<!-- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
</rollingPolicy>
</appender>

<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
Expand All @@ -50,16 +52,16 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${ROOT}%d/warn.%d.log</fileNamePattern>
<maxHistory>${MAXHISTORY}</maxHistory>
<!-- <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
<!-- <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
</rollingPolicy>
</appender>

<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
<!--<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>-->
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
Expand All @@ -69,15 +71,15 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${ROOT}%d/info.%d.log</fileNamePattern>
<maxHistory>${MAXHISTORY}</maxHistory>
<!-- <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
<!-- <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
</rollingPolicy>
</appender>
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
<!--<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n</pattern>-->
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
Expand All @@ -87,10 +89,10 @@
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${ROOT}%d/debug.%d.log</fileNamePattern>
<maxHistory>${MAXHISTORY}</maxHistory>
<!-- <timeBasedFileNamingAndTriggeringPolicy-->
<!-- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
<!-- <timeBasedFileNamingAndTriggeringPolicy-->
<!-- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
</rollingPolicy>
</appender>

Expand All @@ -108,10 +110,10 @@
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${ROOT}%d/httpclient.%d.log</fileNamePattern>
<maxHistory>${MAXHISTORY}</maxHistory>
<!-- <timeBasedFileNamingAndTriggeringPolicy-->
<!-- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
<!-- <timeBasedFileNamingAndTriggeringPolicy-->
<!-- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">-->
<!-- <maxFileSize>${FILESIZE}</maxFileSize>-->
<!-- </timeBasedFileNamingAndTriggeringPolicy>-->
</rollingPolicy>
</appender>

Expand All @@ -120,14 +122,14 @@
<appender-ref ref="httpclient"/>
</logger>

<!-- <logger name="org.mybatis.spring" level="INFO" additivity="false"/>-->
<!-- <logger name="org.mybatis.spring" level="INFO" additivity="false"/>-->


<root level="INFO">
<!-- <appender-ref ref="STDOUT"/>-->
<appender-ref ref="STDOUT"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="WARN"/>
<appender-ref ref="INFO"/>
<!-- <appender-ref ref="DEBUG"/>-->
<!-- <appender-ref ref="DEBUG"/>-->
</root>
</configuration>

0 comments on commit 618a40b

Please sign in to comment.