-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend for new customer registration
- Loading branch information
1 parent
d8fafb1
commit 88cd572
Showing
23 changed files
with
274 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 16 additions & 9 deletions
25
...ervice/AuthenticationProducerService.java → ...direct/service/AuthenticationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
package eu.viandeendirect.service; | ||
|
||
import eu.viandeendirect.api.ProducersApiDelegate; | ||
import eu.viandeendirect.model.Customer; | ||
import eu.viandeendirect.model.Producer; | ||
import eu.viandeendirect.model.Sale; | ||
import eu.viandeendirect.repository.CustomerRepository; | ||
import eu.viandeendirect.repository.ProducerRepository; | ||
import eu.viandeendirect.repository.SaleRepository; | ||
import eu.viandeendirect.service.specs.AuthenticationProducerServiceSpecs; | ||
import eu.viandeendirect.service.specs.AuthenticationServiceSpecs; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static org.springframework.http.HttpStatus.CREATED; | ||
|
||
@Service | ||
@Profile("!test") | ||
public class AuthenticationProducerService implements AuthenticationProducerServiceSpecs { | ||
public class AuthenticationService implements AuthenticationServiceSpecs { | ||
|
||
@Autowired | ||
ProducerRepository producerRepository; | ||
|
||
@Autowired | ||
CustomerRepository customerRepository; | ||
|
||
@Override | ||
public Producer getAuthenticatedProducer() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
String email = ((JwtAuthenticationToken)authentication).getToken().getClaimAsString("email"); | ||
Producer producer = producerRepository.findByEmail(email).orElseThrow(); | ||
Producer producer = producerRepository.findByEmail(email).orElse(null); | ||
return producer; | ||
} | ||
|
||
@Override | ||
public Customer getAuthenticatedCustomer() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
String email = ((JwtAuthenticationToken)authentication).getToken().getClaimAsString("email"); | ||
Customer customer = customerRepository.findByEmail(email).orElse(null); | ||
return customer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
...app/src/main/java/eu/viandeendirect/service/specs/AuthenticationProducerServiceSpecs.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
backend/app/src/main/java/eu/viandeendirect/service/specs/AuthenticationServiceSpecs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package eu.viandeendirect.service.specs; | ||
|
||
import eu.viandeendirect.model.Customer; | ||
import eu.viandeendirect.model.Producer; | ||
|
||
public interface AuthenticationServiceSpecs { | ||
Producer getAuthenticatedProducer(); | ||
|
||
Customer getAuthenticatedCustomer(); | ||
} |
12 changes: 10 additions & 2 deletions
12
...nd/app/src/test/java/eu/viandeendirect/service/AuthenticationProducerServiceForTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
package eu.viandeendirect.service; | ||
|
||
import eu.viandeendirect.model.Customer; | ||
import eu.viandeendirect.model.Producer; | ||
import eu.viandeendirect.service.specs.AuthenticationProducerServiceSpecs; | ||
import eu.viandeendirect.service.specs.AuthenticationServiceSpecs; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Profile("test") | ||
public class AuthenticationProducerServiceForTests implements AuthenticationProducerServiceSpecs { | ||
public class AuthenticationProducerServiceForTests implements AuthenticationServiceSpecs { | ||
|
||
@Override | ||
public Producer getAuthenticatedProducer() { | ||
var producer = new Producer(); | ||
producer.setId(1000); | ||
return producer; | ||
} | ||
|
||
@Override | ||
public Customer getAuthenticatedCustomer() { | ||
var customer = new Customer(); | ||
customer.setId(1000); | ||
return customer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,18 @@ | ||
import Customer from "viandeendirect_eu/dist/model/Customer" | ||
|
||
export class MockApiCustomers { | ||
getCustomers(): Array<Customer> { | ||
const customer1 = { | ||
|
||
getCustomer() { | ||
return { | ||
id: 1, | ||
user: { | ||
id: 1, | ||
firstName: 'Bob', | ||
lastName: 'Sinclair', | ||
email: '[email protected]', | ||
phone: '01 02 03 04 05' | ||
} | ||
} | ||
const customer2 = { | ||
id: 2, | ||
user: { | ||
firstName: 'Amélie', | ||
lastName: 'Poulain', | ||
email: '[email protected]', | ||
phone: '06 02 03 04 05' | ||
} | ||
} | ||
const customer3 = { | ||
id: 3, | ||
user: { | ||
firstName: 'François', | ||
lastName: 'Pinion', | ||
email: '[email protected]', | ||
phone: '07 02 03 04 05' | ||
lastName: 'Marcel', | ||
email: '[email protected]' | ||
} | ||
} | ||
return [customer1, customer2, customer3] | ||
//return undefined | ||
} | ||
|
||
createCustomer(customer: Customer) { | ||
|
Oops, something went wrong.