Skip to content

Commit

Permalink
Sur la page d'accueil de l'espace producteur, revoir l'action dans le…
Browse files Browse the repository at this point in the history
… cas où l'utilisateur n'a pas déjà un compte #9
  • Loading branch information
benjaminpochat committed Nov 9, 2024
1 parent 0db13c1 commit e9394b2
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package eu.viandeendirect.domains.production;

import eu.viandeendirect.api.BeefProductionsApiDelegate;
import eu.viandeendirect.common.ApplicationContextVerifyer;
import eu.viandeendirect.domains.sale.SaleRepository;
import eu.viandeendirect.domains.user.ProducerRepository;
import eu.viandeendirect.model.BeefProduction;
import eu.viandeendirect.model.PackageLot;
import eu.viandeendirect.model.Production;
import eu.viandeendirect.model.Sale;
import eu.viandeendirect.domains.sale.SaleRepository;
import eu.viandeendirect.security.specs.AuthenticationServiceSpecs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
Expand All @@ -23,7 +20,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package eu.viandeendirect.domains.registration;

import eu.viandeendirect.api.RegistrationsApiDelegate;
import eu.viandeendirect.common.EmailService;
import eu.viandeendirect.model.Registration;
import jakarta.mail.MessagingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
public class RegistrationsService implements RegistrationsApiDelegate {

@Autowired
EmailService emailService;

@Override
public ResponseEntity<Void> processRegistration(Registration registration) {
try {
emailService.sendMail(
"[email protected]",
"Nouvelle demande d'inscription d'un producteur sur ViandeEnDirect.eu",
String.format("""
<html>
Nouvelle demande d'inscription d'un producteur :
<br>
<br>
<div>
<b>Nom :</b><br>
%s<br>
</div>
<br>
<div>
<b>Prénom :</b><br>
%s<br>
</div>
<br>
<div>
<b>Email :</b><br>
%s<br>
</div>
<br>
<div>
<b>Téléphone :</b><br>
%s<br>
</div>
<br>
<div>
<b>Nom de l'exploitation agricole :</b><br>
%s<br>
</div>
<br>
<div>
<b>N° SIREN de l'exploitation agricole :</b><br>
%s<br>
</div>
<br>
<div>
<b>Description de la production :</b><br>
%s<br>
</div>
</html>
""",
registration.getProducer().getUser().getFirstName(),
registration.getProducer().getUser().getLastName(),
registration.getProducer().getUser().getEmail(),
registration.getProducer().getUser().getPhone(),
registration.getProducer().getLegalName(),
registration.getProducer().getLegalIdentificationNumber(),
registration.getProductionDescription()
)
);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/error").permitAll()
.requestMatchers("/payments/stripeAccountEvents", "/payments/stripeConnectEvents").permitAll()
.requestMatchers("/labels/**").hasRole(ROLE_PRODUCER)
.requestMatchers("/registrations").permitAll()
);
http.oauth2Login(Customizer.withDefaults());
http.logout(logoutCustomizer -> logoutCustomizer.addLogoutHandler(keycloakLogoutHandler).logoutSuccessUrl("/"));
Expand Down
9 changes: 0 additions & 9 deletions backend/app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ server.error.include-message=always
#----------
spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:database/changelog/changelog-master.yaml

# MOLLIE
#-------
mollie.client-id=app_JSUEw3CWPXcEhFDkCiRCXbPs
mollie.client-secret=NWBG6qptFNVVqq2vSWwbMgW3GryNGdPJPHvy8Uqk
mollie.redirect-url=https://customer.sandbox.viandeendirect.eu
mollie.authorization-url=https://my.mollie.com/oauth2/authorize
mollie.access-token-url=https://api.mollie.com/oauth2/tokens
mollie.resource-owner-url=https://api.mollie.com/v2/organizations/me
101 changes: 101 additions & 0 deletions backend/model/src/main/java/eu/viandeendirect/model/Registration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package eu.viandeendirect.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Generated;
import jakarta.validation.Valid;

import java.util.Objects;

/**
* the registration of new producer
*/

@Schema(name = "Registration", description = "the registration of new producer")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class Registration {

@JsonProperty("producer")
private Producer producer;

@JsonProperty("productionDescription")
private String productionDescription;

public Registration producer(Producer producer) {
this.producer = producer;
return this;
}

/**
* Get producer
* @return producer
*/
@Valid
@Schema(name = "producer", required = false)
public Producer getProducer() {
return producer;
}

public void setProducer(Producer producer) {
this.producer = producer;
}

public Registration productionDescription(String productionDescription) {
this.productionDescription = productionDescription;
return this;
}

/**
* Get productionDescription
* @return productionDescription
*/

@Schema(name = "productionDescription", required = false)
public String getProductionDescription() {
return productionDescription;
}

public void setProductionDescription(String productionDescription) {
this.productionDescription = productionDescription;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Registration registration = (Registration) o;
return Objects.equals(this.producer, registration.producer) &&
Objects.equals(this.productionDescription, registration.productionDescription);
}

@Override
public int hashCode() {
return Objects.hash(producer, productionDescription);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Registration {\n");
sb.append(" producer: ").append(toIndentedString(producer)).append("\n");
sb.append(" productionDescription: ").append(toIndentedString(productionDescription)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

13 changes: 13 additions & 0 deletions frontend/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react": "^18.2.0",
"react-cookie": "^7.0.2",
"react-dom": "^18.2.0",
"react-google-recaptcha-v3": "^1.10.1",
"react-hook-form": "^7.46.1",
"react-hook-form-mui": "^6.8.0",
"react-router-dom": "^6.23.0",
Expand Down
6 changes: 4 additions & 2 deletions frontend/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { CookiesProvider } from 'react-cookie'
import './App.css'
import { ThemeFactory } from './layouts/ThemeFactory.ts'

import { GoogleReCaptchaProvider } from 'react-google-recaptcha-v3';

import ViandeEnDirectRouterProvider from './layouts/ViandeEnDirectRouterProvider.tsx'
import SnackbarProvider from './domains/commons/components/SnackbarProvider.tsx';

Expand All @@ -32,8 +34,8 @@ function App() {
<ThemeProvider theme={themeFactory.createTheme()}>
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="fr">
<SnackbarProvider>
<ViandeEnDirectRouterProvider></ViandeEnDirectRouterProvider>
</SnackbarProvider>
<ViandeEnDirectRouterProvider/>
</SnackbarProvider>
</LocalizationProvider>
</ThemeProvider>
</ReactKeycloakProvider>
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/src/api/mock/MockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { MockApiCustomers } from "./MockApiCustomers.ts"
import { MockApiProductions } from "./MockApiProductions.ts"
import { MockApiSales } from "./MockApiSales.ts"
import { MockApiProducers } from "./MockApiProducers.ts"
import { getPopoverUtilityClass } from "@mui/material"

export class MockApi {

Expand Down Expand Up @@ -157,4 +156,8 @@ export class MockApi {
this.log('getProducerPaymentsSummary', args)
return this.mockApiProducers.getProducerPaymentsSummary()
}

processRegistration(args) {
this.log('processRegistration', args)
}
}
5 changes: 3 additions & 2 deletions frontend/app/src/layouts/producer/AnonymousLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { styled } from '@mui/material/styles';
import { AppBar, Box, Typography, CssBaseline, Toolbar, Grid, Paper, Button } from "@mui/material";
import { useKeycloak } from '@react-keycloak/web'
import React from 'react';
import { Navigate } from 'react-router-dom';
import { Navigate, useNavigate } from 'react-router-dom';
import Footer from '../../domains/commons/components/Footer.tsx';

export default function AnonymousLayout() {

const { keycloak, initialized } = useKeycloak()
const navigate = useNavigate()

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
Expand All @@ -22,7 +23,7 @@ export default function AnonymousLayout() {
}

function register() {
keycloak.register()
navigate('/registration')
}

function getAnonymousLayout() {
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/src/layouts/producer/ProducerRouterFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import OrderView, { loadOrderViewData } from "../../domains/sale/views/OrderView
import ProducerOrderForm, { loadProducerOrderFormData } from "../../domains/sale/views/ProducerOrderForm.tsx";
import CustomersList, { loadCustomersListData } from "../../domains/customer/views/CustomersList.tsx";
import PublicationBeefProductionToSale, { loadPublicationBeefProductionToSaleData } from "../../domains/production/views/beefProduction/PublicationBeefProductionToSale.tsx";
import RegistrationForm from "./RegistrationForm.tsx";

export class ProducerRouterFactory {
getRouter(keycloak) {
Expand Down Expand Up @@ -95,6 +96,10 @@ export class ProducerRouterFactory {
path: '/authentication',
element: <AnonymousLayout/>
},
{
path: '/registration',
element: <RegistrationForm/>
},
{
path: '/unauthorized',
element: <NotAuthorizedForCustomers/>,
Expand Down
Loading

0 comments on commit e9394b2

Please sign in to comment.