[ADD] CHANGES 03012024

parent 6f5b4963
...@@ -155,6 +155,11 @@ ...@@ -155,6 +155,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.poi</groupId>-->
<!-- <artifactId>poi-ooxml</artifactId>-->
<!-- <version>5.2.3</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
<build> <build>
......
...@@ -29,7 +29,7 @@ public class EmailApi { ...@@ -29,7 +29,7 @@ public class EmailApi {
this.dotenv = dotenv; this.dotenv = dotenv;
} }
@RequestMapping(path = "/public/simple", method = RequestMethod.POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}) @RequestMapping(path = "/public/simple_generate", method = RequestMethod.POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<?> simple(@ModelAttribute EmailRequest request) { public ResponseEntity<?> simple(@ModelAttribute EmailRequest request) {
try { try {
MimeMessage message = emailService.simpleMessage(request); MimeMessage message = emailService.simpleMessage(request);
...@@ -40,7 +40,7 @@ public class EmailApi { ...@@ -40,7 +40,7 @@ public class EmailApi {
} }
} }
@RequestMapping(path = "/private/full", method = RequestMethod.POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}) @RequestMapping(path = "/private/generate", method = RequestMethod.POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<?> full(@ModelAttribute EmailRequest request) { public ResponseEntity<?> full(@ModelAttribute EmailRequest request) {
try { try {
MimeMessage message = emailService.htmlMessage(request); MimeMessage message = emailService.htmlMessage(request);
......
package web.multitask.app.api;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("excel")
public class ExcelApi {
@PostMapping("/public/generate")
public ResponseEntity<Resource> generateExcel() {
return null;
}
}
\ No newline at end of file
...@@ -32,6 +32,7 @@ class JWTokenApi { ...@@ -32,6 +32,7 @@ class JWTokenApi {
JSONObject response; JSONObject response;
JSONObject json = new JSONObject(authenticationRequest); JSONObject json = new JSONObject(authenticationRequest);
String username = json.getString("username"); String username = json.getString("username");
try{
UserDetails userDetails = userRepo.findByUsername(username); UserDetails userDetails = userRepo.findByUsername(username);
if (!Objects.equals(userDetails.getPassword(), json.getString("password"))) { if (!Objects.equals(userDetails.getPassword(), json.getString("password"))) {
response = new JSONObject().put("token", "").put("message", "Invalid Credentials").put("status", false); response = new JSONObject().put("token", "").put("message", "Invalid Credentials").put("status", false);
...@@ -39,6 +40,10 @@ class JWTokenApi { ...@@ -39,6 +40,10 @@ class JWTokenApi {
} else { } else {
return ResponseEntity.ok(new JSONObject().put("token", jwtTokenUtil.generateToken((User) userDetails, json.optBigInteger("ms", BigInteger.valueOf(3600000)))).put("message", "Generated").put("status", true).toMap()); return ResponseEntity.ok(new JSONObject().put("token", jwtTokenUtil.generateToken((User) userDetails, json.optBigInteger("ms", BigInteger.valueOf(3600000)))).put("message", "Generated").put("status", true).toMap());
} }
}catch (Exception e){
response = new JSONObject().put("token", "").put("message", "Invalid Credentials").put("status", false);
return ResponseEntity.status(401).body(response.toMap());
}
} }
@PostMapping("/validate") @PostMapping("/validate")
...@@ -89,4 +94,10 @@ class JWTokenApi { ...@@ -89,4 +94,10 @@ class JWTokenApi {
} }
} }
@PostMapping("/remaining")
public ResponseEntity<?> remainingTime(@RequestBody String token) {
JSONObject json = new JSONObject(token);
return ResponseEntity.ok(new JSONObject().put("remaining", jwtTokenUtil.getExperyTime(json.getString("token"))).put("message", "OK").put("status", true).toMap());
}
} }
\ No newline at end of file
...@@ -11,7 +11,6 @@ import lombok.Setter; ...@@ -11,7 +11,6 @@ import lombok.Setter;
@NoArgsConstructor @NoArgsConstructor
@Getter @Getter
@Setter @Setter
@Entity(name = "roles") @Entity(name = "roles")
public class Role { public class Role {
@Id @Id
......
package web.multitask.app.service;
//
//import lombok.var;
//import org.apache.poi.ss.util.CellRangeAddress;
//import org.apache.poi.xssf.usermodel.XSSFRow;
//import org.apache.poi.xssf.usermodel.XSSFSheet;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//import org.json.JSONArray;
//import org.json.JSONObject;
//import org.springframework.stereotype.Service;
//
//import java.time.LocalDateTime;
//import java.util.Arrays;
//import java.util.stream.IntStream;
//@Service
public class ExcelService {
// public byte[] generateExcel (JSONObject json){
// XSSFWorkbook workbook = new XSSFWorkbook();
// }
//
// private void createSheet(XSSFWorkbook workbook, JSONObject json){
// if(!json.optJSONArray("data", new JSONArray()).isEmpty()){
// XSSFSheet sheet = workbook.createSheet(json.optString("sheet_name", "no_name"));
// buildSheet(sheet, json);
// }
// }
//
// private void buildSheet (XSSFSheet sheet, JSONObject json){
//
// int row_index = 0;
// String title = json.optString("title", "");
// String title_style = json.optString("title_style", "");
// String responsible = json.optString("responsible", "");
// JSONArray headers = json.optJSONArray("headers", new JSONArray());
// JSONArray style_headers = json.optJSONArray("style_headers", new JSONArray());
// JSONArray identifiers = json.optJSONArray("identifiers", new JSONArray());
// JSONArray data = json.optJSONArray("data", new JSONArray());
// int total_rows = data.length();
// String currentDate = LocalDateTime.now().toString();
//
// XSSFRow row_title = sheet.createRow(row_index);
// row_title.createCell(0).setCellValue(title);
// CellRangeAddress cellRangeAddress = new CellRangeAddress(row_index, row_index, 0, headers.length() - 1);
// sheet.addMergedRegion(cellRangeAddress);
// row_index++;
// sheet.createRow(row_index);
// XSSFRow row_responsible = sheet.createRow(row_index);
// row_responsible.createCell(0).setCellValue(responsible);
// CellRangeAddress cellRangeAddress2 = new CellRangeAddress(row_index, row_index, 0, headers.length() - 1);
// sheet.addMergedRegion(cellRangeAddress2);
// row_index++;
// XSSFRow row_date = sheet.createRow(row_index);
// row_date.createCell(0).setCellValue("Fecha: " + currentDate);
// CellRangeAddress cellRangeAddress3 = new CellRangeAddress(row_index, row_index, 0, headers.length() - 1);
// sheet.addMergedRegion(cellRangeAddress3);
// row_index++;
// XSSFRow row_header = sheet.createRow(row_index);
// IntStream.range(0, headers.length()).forEach(i -> {
// row_header.createCell(0).setCellValue(headers.optString(i, "").toUpperCase());
// });
//
// for(int i = 0; i < data.length(); i++){
// row_index++;
// XSSFRow row_data = sheet.createRow(row_index);
// int finalI = i;
// IntStream.range(0, identifiers.length()).forEach(j -> {
// row_data.createCell(j).setCellValue(data.optJSONObject(finalI).optString(identifiers.optString(j, ""), ""));
// });
// }
// }
}
\ No newline at end of file
...@@ -68,4 +68,13 @@ public class JWTokenUtil implements Serializable{ ...@@ -68,4 +68,13 @@ public class JWTokenUtil implements Serializable{
.before(new Date()); .before(new Date());
} }
public int getExperyTime(String token){
return (int) ((Jwts.parserBuilder()
.setSigningKey(Keys.hmacShaKeyFor(jwtSecret.getBytes()))
.build()
.parseClaimsJws(token)
.getBody()
.getExpiration()
.getTime() - new Date().getTime())/1000);
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment