+
This commit is contained in:
3
pom.xml
3
pom.xml
@ -66,6 +66,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-vault-config</artifactId>
|
<artifactId>spring-cloud-starter-vault-config</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
@ -198,7 +199,7 @@
|
|||||||
<version>2.22.2</version>
|
<version>2.22.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<spring.config.location>file:org_ccalm_jwt.yml</spring.config.location>
|
<spring.config.location>file:org-ccalm-jwt.yml</spring.config.location>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@ -65,6 +65,7 @@ import java.util.Properties;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class MainController implements ServletContextAware {
|
public class MainController implements ServletContextAware {
|
||||||
@ -111,6 +112,7 @@ public class MainController implements ServletContextAware {
|
|||||||
|
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||||
|
private final Environment environment;
|
||||||
private HikariDataSource dataSource;
|
private HikariDataSource dataSource;
|
||||||
public Storage storage = new Storage();
|
public Storage storage = new Storage();
|
||||||
|
|
||||||
@ -119,16 +121,26 @@ public class MainController implements ServletContextAware {
|
|||||||
this.context = servletContext;
|
this.context = servletContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Autowired
|
||||||
|
//public void DatabaseService(HikariDataSource dataSource) {
|
||||||
|
// this.dataSource = dataSource;
|
||||||
|
//}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
@Autowired
|
@Autowired
|
||||||
public void DatabaseService(HikariDataSource dataSource) {
|
public MainController(NamedParameterJdbcTemplate jdbcTemplate,HikariDataSource dataSource,Environment environment) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
this.environment = environment;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
@Autowired
|
public boolean isProduction() {
|
||||||
public MainController(NamedParameterJdbcTemplate jdbcTemplate) {
|
for (String profile : environment.getActiveProfiles()) {
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
if ("prod".equalsIgnoreCase(profile)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
public String createStrJSONError(int code, String message, String setting, String marker) {
|
public String createStrJSONError(int code, String message, String setting, String marker) {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
@ -509,9 +521,14 @@ public class MainController implements ServletContextAware {
|
|||||||
json.put("error_code",0);
|
json.put("error_code",0);
|
||||||
json.put("error_message","");
|
json.put("error_message","");
|
||||||
|
|
||||||
//Генерю Captcha
|
ImageCaptcha.Builder builder;
|
||||||
ImageCaptcha imageCaptcha = new ImageCaptcha.Builder(400, 100)
|
if(Tools.isInteger(email_model.getWidth())) {
|
||||||
.addContent(new LatinContentProducer(7),
|
builder = new ImageCaptcha.Builder(Integer.valueOf(email_model.getWidth()), 100);
|
||||||
|
}else{
|
||||||
|
builder = new ImageCaptcha.Builder(400, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageCaptcha imageCaptcha = builder.addContent(new LatinContentProducer(7),
|
||||||
new DefaultWordRenderer.Builder()
|
new DefaultWordRenderer.Builder()
|
||||||
.randomColor(Color.BLACK, Color.BLUE, Color.CYAN, Color.RED)
|
.randomColor(Color.BLACK, Color.BLUE, Color.CYAN, Color.RED)
|
||||||
.build())
|
.build())
|
||||||
@ -520,7 +537,9 @@ public class MainController implements ServletContextAware {
|
|||||||
.build();
|
.build();
|
||||||
BufferedImage img = imageCaptcha.getImage();
|
BufferedImage img = imageCaptcha.getImage();
|
||||||
|
|
||||||
|
if(!isProduction())
|
||||||
json.put("code",imageCaptcha.getContent());//json.put("code","");
|
json.put("code",imageCaptcha.getContent());//json.put("code","");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ImageIO.write(img, "jpeg", baos);
|
ImageIO.write(img, "jpeg", baos);
|
||||||
@ -1411,8 +1430,6 @@ public class MainController implements ServletContextAware {
|
|||||||
Translation trt = new Translation(language_id,jdbcTemplate);
|
Translation trt = new Translation(language_id,jdbcTemplate);
|
||||||
String result=createStrJSONError(10000,trt.trt("Request_not_processed"), (String)null, (String)null);
|
String result=createStrJSONError(10000,trt.trt("Request_not_processed"), (String)null, (String)null);
|
||||||
try{
|
try{
|
||||||
//Connection conn = getConnection();
|
|
||||||
|
|
||||||
int index = restore.getToken().indexOf(".");
|
int index = restore.getToken().indexOf(".");
|
||||||
String payload = restore.getToken().substring(0, index);
|
String payload = restore.getToken().substring(0, index);
|
||||||
String signature1 = restore.getToken().substring(index+1);
|
String signature1 = restore.getToken().substring(index+1);
|
||||||
@ -1440,7 +1457,7 @@ public class MainController implements ServletContextAware {
|
|||||||
if(token.getLong("exp")<Instant.now().getEpochSecond()){
|
if(token.getLong("exp")<Instant.now().getEpochSecond()){
|
||||||
return createStrJSONError(10000,trt.trt("Captcha_is_outdated"),(String)null,(String)null);
|
return createStrJSONError(10000,trt.trt("Captcha_is_outdated"),(String)null,(String)null);
|
||||||
}
|
}
|
||||||
if (!Tools.isValidEmail(token.getString("email"))) {
|
if (!token.has("email") || !Tools.isValidEmail(token.getString("email"))) {
|
||||||
return createStrJSONError(10000,trt.trt("The_email_field_is_incorrect"),(String)null,(String)null);
|
return createStrJSONError(10000,trt.trt("The_email_field_is_incorrect"),(String)null,(String)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class SecurityConfig {
|
|||||||
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
System.out.println(path); // https://127.0.0.1:8082/logout
|
System.out.println(path); // https://127.0.0.1:8082/logout
|
||||||
return path.equals("/") || path.equals("/login") || path.equals("/logout") || path.equals("/create");
|
return path.equals("/") || path.equals("/login") || path.equals("/logout") || path.equals("/create") || path.equals("/captcha") || path.equals("/restore");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -7,4 +7,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
public class EmailModel {
|
public class EmailModel {
|
||||||
@JsonProperty("email")
|
@JsonProperty("email")
|
||||||
private String email;
|
private String email;
|
||||||
|
@JsonProperty("width")
|
||||||
|
private String width;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,6 +103,7 @@ public class Tools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidEmail(String email) {
|
public static boolean isValidEmail(String email) {
|
||||||
|
if(email==null || email.isEmpty()) return false;
|
||||||
String EMAIL_REGEX = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
|
String EMAIL_REGEX = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
|
||||||
Pattern pattern = Pattern.compile(EMAIL_REGEX);
|
Pattern pattern = Pattern.compile(EMAIL_REGEX);
|
||||||
Matcher matcher = pattern.matcher(email);
|
Matcher matcher = pattern.matcher(email);
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Please check if the user has access to the directory from which the application is being executed -->
|
<!-- Please check if the user has access to the directory from which the application is being executed -->
|
||||||
<property name="LOGS" value="logs" />
|
<property name="LOGS" value="logs" />
|
||||||
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||||
@ -25,10 +28,11 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!--root level="info"-->
|
<root level="info">
|
||||||
<root level="warn">
|
<!--root level="warn"-->
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
<appender-ref ref="CONSOLE" />
|
<appender-ref ref="CONSOLE" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
Reference in New Issue
Block a user