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