fixed bugs added client
This commit is contained in:
parent
c04a69a735
commit
9f21811652
|
|
@ -32,10 +32,10 @@ public class ApplicationStartup implements ApplicationListener<ApplicationReadyE
|
|||
}
|
||||
|
||||
private void checkLanguages() {
|
||||
logger.info("CHECK LANGUAGES");
|
||||
logger.info("CHECKING LANGUAGES");
|
||||
|
||||
if(!languageRepository.findByLocale("en").isPresent()){
|
||||
logger.info("ADD MISSING ENGLISH");
|
||||
logger.info("ADDING MISSING ENGLISH");
|
||||
|
||||
LanguageEntity l = new LanguageEntity("en", "English", true);
|
||||
languageRepository.save(l);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,15 @@ package eu.csc.ODPAppVehOwnServer.controller.registration;
|
|||
|
||||
import eu.csc.ODPAppVehOwnServer.controller.AbstractRestController;
|
||||
import eu.csc.ODPAppVehOwnServer.models.auth.AuthenticationRequest;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.UtilsService;
|
||||
import eu.csc.ODPAppVehOwnServer.services.AuthenticationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping
|
||||
|
|
@ -19,6 +22,9 @@ public class AuthenticationController extends AbstractRestController {
|
|||
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
@Autowired
|
||||
private UtilsService utilsService;
|
||||
|
||||
public AuthenticationController(AuthenticationService authenticationService) {
|
||||
this.authenticationService = authenticationService;
|
||||
}
|
||||
|
|
@ -28,5 +34,18 @@ public class AuthenticationController extends AbstractRestController {
|
|||
return new ResponseEntity<>(authenticationService.generateJWTToken(request.getUsername(), request.getPassword()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/pwdReset")
|
||||
public ResponseEntity resetPassword(@RequestBody AuthenticationRequest request) {
|
||||
|
||||
if (authenticationService.emailExists(request.getUsername())) {
|
||||
request.setPassword(authenticationService.resetPassword(request.getUsername(), utilsService.generateAccessToken()));
|
||||
|
||||
return ResponseEntity.ok(request);
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
//return new ResponseEntity<>(authenticationService.generateJWTToken(request.getUsername(), request.getPassword()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import eu.csc.ODPAppVehOwnServer.persistence.respository.UserRepository;
|
|||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.Optional;
|
||||
|
||||
|
|
@ -31,6 +32,23 @@ public class AuthenticationService {
|
|||
return accountRepository.findOneByEmail(email)
|
||||
.filter(account -> passwordEncoder.matches(password, account.getPassword()))
|
||||
.map(account -> new JWTTokenResponse(jwtTokenService.generateToken(email)))
|
||||
.orElseThrow(() -> new EntityNotFoundException("Account not found"));
|
||||
.orElseThrow(() -> new EntityNotFoundException("Account not found (check email and/or password)"));
|
||||
}
|
||||
|
||||
public boolean emailExists(String email) {
|
||||
return accountRepository.existsByEmail(email);
|
||||
}
|
||||
|
||||
public String resetPassword(String email, String newPassword) {
|
||||
Optional<UserEntity> result = accountRepository.findOneByEmail(email);
|
||||
|
||||
|
||||
if(result.isPresent()) {
|
||||
result.get().setPassword(passwordEncoder.encode(newPassword));
|
||||
accountRepository.save(result.get());
|
||||
}else
|
||||
throw new EntityNotFoundException();
|
||||
|
||||
return newPassword;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* @see eu.csc.ODPAppVehOwnServer.controller.registration.VehicleRegistrationController
|
||||
* @see eu.csc.ODPAppVehOwnServer.controller.data.DeviceController
|
||||
* @see eu.csc.ODPAppVehOwnServer.controller.registration.AuthenticationController
|
||||
*/
|
||||
public class CustomerClientTester extends AbstractClientTester{
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue