Skip to content

Commit

Permalink
fix login for returning users
Browse files Browse the repository at this point in the history
  • Loading branch information
l-brendle committed Oct 22, 2023
1 parent 6a93279 commit 9cb76a3
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.baloise.collab.springbackend.security;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Objects;

@RestController
@RequiredArgsConstructor
@Log
Expand All @@ -22,13 +17,14 @@ public class RegistrationController {
private final PasswordEncoder encoder;

@PostMapping("/user/registration")
public boolean registerUser(HttpServletRequest request, @RequestBody Credential credential) throws ServletException, IOException {
public boolean registerUser(@RequestBody Credential credential) {

if (userDetailsManager.userExists(credential.username())) {
if(Objects.equals(userDetailsManager.loadUserByUsername(credential.username()).getPassword(), credential.password())){
log.info("User already exists + password is correct - returning okey");
if(encoder.matches(credential.password(), userDetailsManager.loadUserByUsername(credential.username()).getPassword())){
log.info(credential.username() + " User already exists + password is correct - returning okey");
return true;
} else {
log.info(credential.username() + " User already exists but password is wrong");
return false;
}
} else {
Expand Down

0 comments on commit 9cb76a3

Please sign in to comment.