break
This commit is contained in:
parent
2a99243156
commit
76c97161f9
@ -431,12 +431,14 @@ public class AttendencetService {
|
||||
|
||||
public LocalDateTime getLocalDate(String dateTime) {
|
||||
DateTimeFormatter formatternew = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss")
|
||||
.optionalStart().appendFraction(ChronoField.MICRO_OF_SECOND, 1, 6, true).optionalEnd()
|
||||
.optionalStart().appendFraction(ChronoField.MICRO_OF_SECOND, 1, 9, true).optionalEnd()
|
||||
.parseDefaulting(ChronoField.MICRO_OF_SECOND, 0).parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
|
||||
.parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0).parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
|
||||
.toFormatter();
|
||||
|
||||
return LocalDateTime.parse(dateTime, formatternew);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.realnet.attendence.Services;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
@ -104,7 +105,12 @@ public class BreaktService {
|
||||
// LocalDateTime breakInTime = LocalDateTime.parse(existingBreak.getBreak_in_time(), formatter);
|
||||
LocalDateTime breakInTime = attendanceService.getLocalDate(existingBreak.getBreak_in_time());
|
||||
LocalDateTime breakOutTime = attendanceService.getLocalDate(existingBreak.getBreak_out_time());
|
||||
|
||||
Duration totalBreakDuration = Duration.ZERO;
|
||||
totalBreakDuration = totalBreakDuration.plus(Duration.between(breakInTime, breakOutTime));
|
||||
|
||||
int breakDuration = (int) Duration.between(breakInTime, breakOutTime).toMinutes();
|
||||
|
||||
existingBreak.setBreakDurationMinutes(breakDuration);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new RuntimeException("Failed to parse date-time: " + e.getMessage());
|
||||
@ -122,10 +128,23 @@ public class BreaktService {
|
||||
|
||||
// for particular user
|
||||
public int getTotalBreakDurationForUser(Long userId) {
|
||||
LocalDateTime startOfDay = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
LocalDateTime endOfDay = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59).withNano(999999999);
|
||||
List<Breakt> breaks = Repository.findByUserIdAndDateRange(userId, startOfDay.format(formatter),
|
||||
endOfDay.format(formatter));
|
||||
// Get current time
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// Set the time to 00:00 while appending current seconds
|
||||
LocalDateTime startOfDay = now.withHour(0).withMinute(0).withSecond(now.getSecond()).withNano(0);
|
||||
LocalDateTime endOfDay = LocalDateTime.now().with(LocalTime.MAX);
|
||||
|
||||
String start = startOfDay.toString().replace("T", " ");
|
||||
String end = endOfDay.toString().replace("T", " ");
|
||||
|
||||
// LocalDateTime endOfDay = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59).withNano(999999999);
|
||||
String startDate = attendanceService.getLocalDate(start).toString();
|
||||
String endDate = attendanceService.getLocalDate(end).toString();
|
||||
startDate = startDate.replace("T", " ");
|
||||
endDate = endDate.replace("T", " ");
|
||||
|
||||
List<Breakt> breaks = Repository.findByUserIdAndDateRange(userId, startDate, endDate);
|
||||
return breaks.stream().mapToInt(Breakt::getBreakDurationMinutes).sum();
|
||||
}
|
||||
|
||||
|
@ -64,15 +64,8 @@ public class UserController {
|
||||
@Autowired
|
||||
private FileStorageService fileStorageService;
|
||||
|
||||
private AppUserServiceImpl appUserServiceImpl;
|
||||
private EmailService emailService;
|
||||
|
||||
@Autowired
|
||||
public UserController(AppUserServiceImpl appUserServiceImpl, EmailService emailService) {
|
||||
super();
|
||||
this.appUserServiceImpl = appUserServiceImpl;
|
||||
this.emailService = emailService;
|
||||
}
|
||||
private EmailService emailService;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
@ -189,31 +182,16 @@ public class UserController {
|
||||
@ApiOperation(value = "Reset Password", response = PasswordResetRequest.class)
|
||||
@PostMapping("/reset_password")
|
||||
public ResponseEntity<?> resetPasswordnew(@Valid @RequestBody PasswordResetRequest passwordResetReq) {
|
||||
AppUser reset = userService.resetPasswordnew(passwordResetReq);
|
||||
System.out.println("resetPassword() Controller : RESET ? " + reset);
|
||||
Map<String, AppUser> res = new HashMap<String, AppUser>();
|
||||
if (reset != null) {
|
||||
res.put("reset", reset);
|
||||
return new ResponseEntity<>(res, HttpStatus.ACCEPTED);
|
||||
} else {
|
||||
res.put("reset", reset);
|
||||
return new ResponseEntity<>(res, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
ResponseEntity<?> reset = userService.resetPasswordnew(passwordResetReq);
|
||||
return reset;
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Forgot password", response = PasswordResetRequest.class)
|
||||
@PostMapping("/forgot_password")
|
||||
public ResponseEntity<?> forgotpassword(@Valid @RequestBody PasswordResetRequest passwordResetReq) {
|
||||
AppUser reset = userService.forgotpassword(passwordResetReq);
|
||||
System.out.println("resetPassword() Controller : RESET ? " + reset);
|
||||
Map<String, AppUser> res = new HashMap<String, AppUser>();
|
||||
if (reset != null) {
|
||||
res.put("reset", reset);
|
||||
return new ResponseEntity<>(res, HttpStatus.ACCEPTED);
|
||||
} else {
|
||||
res.put("reset", reset);
|
||||
return new ResponseEntity<>(res, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
ResponseEntity<?> reset = userService.forgotpassword(passwordResetReq);
|
||||
return reset;
|
||||
}
|
||||
|
||||
// Reset password by email sending
|
||||
|
@ -13,6 +13,8 @@ import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@ -366,13 +368,13 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
public AppUser updateAppUserDto(Long userId, AppUserDto appUserDto) {
|
||||
AppUser a = appUserRepository.findById(userId).orElse(null);
|
||||
if (a != null) {
|
||||
String encodedPass1 = bcryptEncoder.encode(appUserDto.getUserPassw());
|
||||
if (a.getUserPassw() != encodedPass1) {
|
||||
a.setUserPassw(encodedPass1);
|
||||
a.setPwdChangedCnt((long) 0);
|
||||
a.setPwdChangedCnt(a.getPwdChangedCnt() + 1);
|
||||
a.setLastPwdChangedDate(new Date());
|
||||
}
|
||||
// String encodedPass1 = bcryptEncoder.encode(appUserDto.getUserPassw());
|
||||
// if (a.getUserPassw() != encodedPass1) {
|
||||
// a.setUserPassw(encodedPass1);
|
||||
// a.setPwdChangedCnt((long) 0);
|
||||
// a.setPwdChangedCnt(a.getPwdChangedCnt() + 1);
|
||||
// a.setLastPwdChangedDate(new Date());
|
||||
// }
|
||||
a.setUsername(appUserDto.getUsername() != null ? appUserDto.getUsername() : a.getUsername());
|
||||
a.setTitle(appUserDto.getTitle() != null ? appUserDto.getTitle() : a.getTitle());
|
||||
a.setShortName(appUserDto.getShortName() != null ? appUserDto.getShortName() : a.getShortName());
|
||||
@ -438,57 +440,78 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
// By Gaurav
|
||||
// RESET PASSWORD WITH CONFIRM PASSWORD
|
||||
|
||||
public AppUser resetPasswordnew(PasswordResetRequest p) {
|
||||
public ResponseEntity<?> resetPasswordnew(PasswordResetRequest p) {
|
||||
AppUser a = appUserRepository.findById(p.getUserId()).orElse(null);
|
||||
|
||||
if (a != null) {
|
||||
if (bcryptEncoder.matches(p.getOldPassword(), a.getUserPassw())) {
|
||||
if (a == null) {
|
||||
|
||||
if (p.getNewPassword().equals(p.getConfirmPassword())) {
|
||||
System.out.println("User Is Empty! ");
|
||||
return new ResponseEntity<>("User Is Empty!", HttpStatus.BAD_REQUEST);
|
||||
|
||||
a.setUserPassw(bcryptEncoder.encode(p.getNewPassword()));
|
||||
a.setPwdChangedCnt(a.getPwdChangedCnt() != null ? (long) 1 + a.getPwdChangedCnt() : (long) 1);
|
||||
a.setLastPwdChangedDate(new Date());
|
||||
a.setChangePassw(p.getNewPassword());
|
||||
|
||||
appUserRepository.save(a);
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
if (!bcryptEncoder.matches(p.getOldPassword(), a.getUserPassw())) {
|
||||
System.out.println("Old Password is Not Right! ");
|
||||
|
||||
return new ResponseEntity<>("Old Password is Not Right!", HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
if (!p.getNewPassword().equals(p.getConfirmPassword())) {
|
||||
System.out.println("new And Confirm Passowrd Should Be Equal! ");
|
||||
|
||||
return new ResponseEntity<>("new And Confirm Passowrd Should Be Equal!", HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
|
||||
a.setUserPassw(bcryptEncoder.encode(p.getNewPassword()));
|
||||
a.setPwdChangedCnt(a.getPwdChangedCnt() != null ? (long) 1 + a.getPwdChangedCnt() : (long) 1);
|
||||
a.setLastPwdChangedDate(new Date());
|
||||
a.setChangePassw(p.getNewPassword());
|
||||
|
||||
AppUser save = appUserRepository.save(a);
|
||||
System.out.println("Password changed Successfully.. ");
|
||||
|
||||
return new ResponseEntity<>(save, HttpStatus.ACCEPTED);
|
||||
|
||||
}
|
||||
|
||||
// By Gaurav
|
||||
// FORGOT PASSWORD
|
||||
|
||||
public AppUser forgotpassword(PasswordResetRequest p) {
|
||||
AppUser a = appUserRepository.findById(p.getUserId()).orElse(null);
|
||||
public ResponseEntity<?> forgotpassword(PasswordResetRequest p) {
|
||||
|
||||
if (a != null) {
|
||||
AppUser a = appUserRepository.findByEmail(p.getEmail());
|
||||
|
||||
if (p.getNewPassword().equals(p.getConfirmPassword())) {
|
||||
if (a == null) {
|
||||
|
||||
a.setUserPassw(bcryptEncoder.encode(p.getNewPassword()));
|
||||
a.setPwdChangedCnt(a.getPwdChangedCnt() != null ? (long) 1 + a.getPwdChangedCnt() : (long) 1);
|
||||
a.setLastPwdChangedDate(new Date());
|
||||
a.setChangePassw(p.getNewPassword());
|
||||
System.out.println("User Is Empty! ");
|
||||
return new ResponseEntity<>("User Is Empty!", HttpStatus.BAD_REQUEST);
|
||||
|
||||
appUserRepository.save(a);
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
if (!p.getNewPassword().equals(p.getConfirmPassword())) {
|
||||
System.out.println("new And Confirm Passowrd Should Be Equal! ");
|
||||
|
||||
return new ResponseEntity<>("new And Confirm Passowrd Should Be Equal!", HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
|
||||
a.setUserPassw(bcryptEncoder.encode(p.getNewPassword()));
|
||||
a.setPwdChangedCnt(a.getPwdChangedCnt() != null ? (long) 1 + a.getPwdChangedCnt() : (long) 1);
|
||||
a.setLastPwdChangedDate(new Date());
|
||||
a.setChangePassw(p.getNewPassword());
|
||||
|
||||
appUserRepository.save(a);
|
||||
AppUser save = appUserRepository.save(a);
|
||||
System.out.println("Password changed Successfully.. ");
|
||||
|
||||
return new ResponseEntity<>(save, HttpStatus.ACCEPTED);
|
||||
|
||||
}
|
||||
|
||||
public String generateRandomHash(int len) {
|
||||
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk" + "lmnopqrstuvwxyz!@#$%&";
|
||||
// Random rnd = new Random();
|
||||
SecureRandom rnd = new SecureRandom();
|
||||
SecureRandom rnd = new SecureRandom();
|
||||
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
|
Loading…
Reference in New Issue
Block a user