Author SHA1 Message Date
Elias Harb 932fc88b2e Bug fix: getPicture Endpoint
LocationBasedServices/sumoc-backend/pipeline/pr-main Build queued...
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
- got error that object was too large for transaction ... again
2026-02-25 01:55:10 +01:00
Elias Harb 7c347caea9 add challenge Dummy picture
LocationBasedServices/sumoc-backend/pipeline/pr-main Build queued...
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
2026-02-25 00:17:35 +01:00
kakoschke 29fb04d6ec Merge pull request 'make reset password Kotlin/Android app functional' (#22) from passwordResetRefactoring into main
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
Reviewed-on: #22

passt!
2026-02-23 18:47:33 +01:00
Elias Harb 82014b1d9c make reset password Kotlin/Android app functional
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/pr-main This commit looks good
- small refactor for resetPassword
2026-02-23 18:30:15 +01:00
neuhauss 57e9beb33f Merge pull request 'WIP FirebaseMessageBuilder.java adaptiert, sodass auch iOS Apps Push Benachrichtigungen erhalten und intercepten können.' (#21) from add-ios-notification into main
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
Reviewed-on: #21
2026-02-23 11:47:24 +01:00
9 changed files with 37 additions and 22 deletions
@@ -34,11 +34,11 @@ public interface ChallengeMapper {
challenge.setCriteria(dto.getCriteria());
challenge.setReward(dto.getReward());
if (dto.getBase64image() != null && !dto.getBase64image().isEmpty()) {
challenge.setImage(new ChallengeImageEntity(
challenge,
ImageBase64Util.decode(dto.getBase64image())
));
if (dto.getBase64image() != null && !dto.getBase64image().isBlank()) {
byte[] bytes = ImageBase64Util.decode(dto.getBase64image());
ChallengeImageEntity img = new ChallengeImageEntity();
img.setImageData(bytes);
challenge.setImage(img);
}
return challenge;
@@ -85,6 +85,9 @@ public class Challenge {
public void setImage(ChallengeImageEntity image) {
this.image = image;
if (image != null) {
image.setChallenge(this);
}
}
public Map<String, Integer> getCriteria() {
@@ -102,9 +102,11 @@ public class UserAuthenticationController {
authenticationService.resetPassword(passwordResetDTO);
return ResponseEntity.ok("Passwort erfolgreich geändert");
} catch (InvalidTokenException | UsernameNotFoundException e) {
e.printStackTrace();
return ResponseEntity.badRequest().body(e.getMessage());
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Fehler beim Zurücksetzen des Passworts");
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
}
}
@@ -1,5 +1,6 @@
package SuMoC.backend.security.dtos;
import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@@ -8,7 +9,9 @@ import lombok.Setter;
@Setter
@AllArgsConstructor
public class PasswordResetDTO {
String otp_code;
@JsonAlias({"otp_code", "otpCode"})
String otpCode;
String email;
String new_password;
@JsonAlias({"new_password", "newPassword"})
String newPassword;
}
@@ -17,12 +17,12 @@ public class PasswordResetToken{
private Long id;
private String email;
private String otp_code;
private String otpCode;
private LocalDateTime expiryDate;
public PasswordResetToken(String email, String code) {
this.email = email;
this.otp_code = code;
this.otpCode = code;
this.expiryDate = LocalDateTime.now().plusMinutes(EXPIRY_TIME_MINUTES);
}
@@ -13,8 +13,6 @@ import SuMoC.backend.user.models.User;
import SuMoC.backend.user.repository.UserRepository;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.MailException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -155,7 +153,6 @@ public class AuthenticationService {
});
String otp = generate_six_digit_OTP();
passwordResetTokenRepository.save(new PasswordResetToken(email, passwordEncoder.encode(otp))); //encoded otp
emailService.sendPasswordResetEmail(email, otp);
}
@@ -171,18 +168,17 @@ public class AuthenticationService {
}
//use .matches() so compare raw otp to (salted!) encoded otp
if(!passwordEncoder.matches(passwordResetDTO.getOtp_code(),token.getOtp_code())){
if(!passwordEncoder.matches(passwordResetDTO.getOtpCode(),token.getOtpCode())){
throw new InvalidTokenException("Code ist ungültig");
}
if(!isPasswordFormatCorrect(passwordResetDTO.getNew_password())) {
if(!isPasswordFormatCorrect(passwordResetDTO.getNewPassword())) {
throw new InvalidTokenException("Passwortformat ist nicht korrekt");
}
User user = userRepository.findByEmail(passwordResetDTO.getEmail())
.orElseThrow(() -> new UsernameNotFoundException("User existiert nicht"));
user.setPassword(passwordEncoder.encode(passwordResetDTO.getNew_password()));
user.setPassword(passwordEncoder.encode(passwordResetDTO.getNewPassword()));
userRepository.save(user);
passwordResetTokenRepository.delete(token);
}
@@ -8,8 +8,10 @@ import jakarta.transaction.Transactional;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
import java.io.InputStream;
import java.util.*;
@Component
@@ -31,6 +33,7 @@ public class DevChallengeSeeder implements CommandLineRunner {
@Override
@Transactional
public void run(String... args) {
final String dummyImageBase64 = loadBase64FromClasspath("images/ChallengeDummy.png");
List<Seed> seeds = generateSeeds();
for (Seed seed : seeds) {
@@ -38,20 +41,20 @@ public class DevChallengeSeeder implements CommandLineRunner {
.map(ChallengeMapper::toDTO)
.ifPresentOrElse(
existingChallenge -> {
// Update existing challenge
existingChallenge.setName(seed.name());
existingChallenge.setDescription(seed.description());
existingChallenge.setCriteria(seed.criteria());
existingChallenge.setReward(seed.reward());
existingChallenge.setBase64image(dummyImageBase64);
challengeService.modifyChallenge(existingChallenge);
},
() -> {
// Create new challenge
ChallengeDTO newChallenge = new ChallengeDTO();
newChallenge.setName(seed.name());
newChallenge.setDescription(seed.description());
newChallenge.setCriteria(seed.criteria());
newChallenge.setReward(seed.reward());
newChallenge.setBase64image(dummyImageBase64);
challengeService.createChallenge(newChallenge);
}
);
@@ -60,6 +63,15 @@ public class DevChallengeSeeder implements CommandLineRunner {
challengeService.weeklyChallengeScheduler();
}
private String loadBase64FromClasspath(String classpathLocation) {
try (InputStream in = new ClassPathResource(classpathLocation).getInputStream()) {
byte[] bytes = in.readAllBytes();
return Base64.getEncoder().encodeToString(bytes);
} catch (Exception e) {
throw new IllegalStateException("Could not load image from classpath: " + classpathLocation, e);
}
}
private record Seed(String name, String description, Map<String, Integer> criteria, Integer reward) {}
private static Seed seed(
@@ -233,16 +233,15 @@ public class UserController {
@ApiResponse(responseCode = "403", description = "Only authorized persons may see the profiles picture"),
@ApiResponse(responseCode = "404", description = "The user does not exist")
})
@GetMapping("/getProfilePicture/{id}")
@GetMapping(value = "/getProfilePicture/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ImageRequestDTO> getProfilePicture(@PathVariable @NotNull Long id) {
ImageRequestDTO imageData = userService.getProfilePicture(id);
return ResponseEntity.ok()
.contentType(MediaType.IMAGE_JPEG)
.contentType(MediaType.APPLICATION_JSON)
.cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
.body(imageData);
}
@Operation(summary = "Get the users own xp", description = "A user can get their own xp.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "XP successfully retrieved",
Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB