Controller
@Controller
public class UserListController {
@PostMapping("/login")
public @ResponseBody ResponseEntity<?> signIn(@RequestBody UserList
userlist) throws UserNotFoundException{
{
UserList user =
userListService.findUserByEmailAndPassword(userlist);
if (user == null)
return new ResponseEntity<>("User not found!",
HttpStatus.NOT_FOUND);
return ResponseEntity.ok(user);
}
}
}
Service
@Service
public class UserListService {
// check mail and pass
public UserList findUserByEmailAndPassword(UserList
userlist)throws UserNotFoundException {
try {
UserList user =
userListRepository.findByEmail(userlist.getEmail());
String rawPassword = userlist.getPassword();
if (user != null &&
userlist.getEmail().equals(user.getEmail())
&& passwordEncoder.matches(rawPassword,
user.getPassword())) {
UserList Result = user;
return Result;
}
throw new UserNotFoundException("Invalid email or password !, Try again.");
} catch (Exception e) {
throw new UserNotFoundException(e.getMessage());
}
}
}
Repository
@Repository
public interface UserListRepository extends JpaRepository<UserList,
Integer> {
UserList findByEmail(String email);
}
Confuguration File
@Configuration
//to indicate there are one or more bean methods for process by spring container
public class SecurityConfig {
@Bean//it produces bean to get managed by spring container
public PasswordEncoder passwordEncoder() {
// PasswordEncoder service interface to encode passwords by BCryptPasswordEncoder
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
enter image description here} Postman error