Initialer commit
This commit is contained in:
29
registration-service/.classpath
Normal file
29
registration-service/.classpath
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/webapp">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
33
registration-service/.project
Normal file
33
registration-service/.project
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>registration-service</name>
|
||||
<comment></comment>
|
||||
<projects/>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<linkedResources/>
|
||||
<filteredResources/>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
connection.project.dir=..
|
||||
eclipse.preferences.version=1
|
||||
13
registration-service/.settings/org.eclipse.jdt.core.prefs
Normal file
13
registration-service/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,13 @@
|
||||
#
|
||||
#Sat Apr 01 12:17:22 CEST 2023
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="registration-service">
|
||||
<property name="context-root" value="registration-service"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/webapp"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
|
||||
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="jst.java"/>
|
||||
<fixed facet="jst.web"/>
|
||||
<installed facet="jst.web" version="2.4"/>
|
||||
<installed facet="jst.java" version="17"/>
|
||||
</faceted-project>
|
||||
13
registration-service/bin/main/META-INF/hibernate.cfg.xml
Normal file
13
registration-service/bin/main/META-INF/hibernate.cfg.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Validate the database schema on startup -->
|
||||
<property name="hbm2ddl.auto">validate</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
20
registration-service/bin/main/META-INF/persistence.xml
Normal file
20
registration-service/bin/main/META-INF/persistence.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0" >
|
||||
|
||||
<persistence-unit name="registration"
|
||||
transaction-type="JTA">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:/Registration</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.MySQLDialect" />
|
||||
<property
|
||||
name="javax.persistence.schema-generation.database.action"
|
||||
value="drop-and-create" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
6
registration-service/bin/main/WEB-INF/web.xml
Normal file
6
registration-service/bin/main/WEB-INF/web.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><web-app version="5.0"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd">
|
||||
|
||||
</web-app>
|
||||
1
registration-service/bin/main/activation.html
Normal file
1
registration-service/bin/main/activation.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Registrierung erfolgreich abgeschlossen</h1>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
registration-service/bin/main/index.html
Normal file
1
registration-service/bin/main/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Was machst du hier?</h1>
|
||||
17
registration-service/bin/main/log4j2.xml
Normal file
17
registration-service/bin/main/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="MyFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
36
registration-service/build.gradle
Normal file
36
registration-service/build.gradle
Normal file
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'war'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDir 'src/main/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/main/webapp'
|
||||
// srcDir 'src/main/resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'jakarta.platform:jakarta.jakartaee-web-api:9.0.0'
|
||||
compileOnly 'jakarta.persistence:jakarta.persistence-api:3.1.0'
|
||||
compileOnly 'jakarta.resource:jakarta.resource-api:2.1.0'
|
||||
|
||||
compileOnly 'org.jboss.ejb3:jboss-ejb3-ext-api:2.3.0.Final'
|
||||
|
||||
compileOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.20.0'
|
||||
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
registration-service/build/libs/registration-service.war
Normal file
BIN
registration-service/build/libs/registration-service.war
Normal file
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Validate the database schema on startup -->
|
||||
<property name="hbm2ddl.auto">validate</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0" >
|
||||
|
||||
<persistence-unit name="registration"
|
||||
transaction-type="JTA">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:/Registration</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.MySQLDialect" />
|
||||
<property
|
||||
name="javax.persistence.schema-generation.database.action"
|
||||
value="drop-and-create" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><web-app version="5.0"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd">
|
||||
|
||||
</web-app>
|
||||
@@ -0,0 +1 @@
|
||||
<h1>Registrierung erfolgreich abgeschlossen</h1>
|
||||
1
registration-service/build/resources/main/index.html
Normal file
1
registration-service/build/resources/main/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Was machst du hier?</h1>
|
||||
17
registration-service/build/resources/main/log4j2.xml
Normal file
17
registration-service/build/resources/main/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="MyFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Binary file not shown.
2
registration-service/build/tmp/war/MANIFEST.MF
Normal file
2
registration-service/build/tmp/war/MANIFEST.MF
Normal file
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.client.ClientBuilder;
|
||||
import jakarta.ws.rs.client.Entity;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
@ApplicationScoped
|
||||
@Path("activation")
|
||||
public class ActivationResource {
|
||||
|
||||
@Inject private RegistrationDAO registrationDao;
|
||||
|
||||
@GET
|
||||
@Path("{uuid}")
|
||||
public Response activate(@PathParam("uuid") String registrationId, @Context UriInfo info) {
|
||||
RegistrationEntity registration = registrationDao.findById(UUID.fromString(registrationId));
|
||||
if (registration != null && !Boolean.TRUE.equals(registration.getActivated())) {
|
||||
Response response = ClientBuilder.newClient().target("http://localhost:8080/user-service/user").request().post(Entity.entity(registration.toRegistration(), MediaType.APPLICATION_JSON));
|
||||
if (200 == response.getStatus()) {
|
||||
registration.setActivated(Boolean.TRUE);
|
||||
registrationDao.update(registration);
|
||||
return Response.seeOther(info.getBaseUriBuilder().path("activation.html").build()).build();
|
||||
} else {
|
||||
return Response.serverError().build();
|
||||
}
|
||||
} else {
|
||||
return Response.noContent().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
public class Email {
|
||||
|
||||
private String emailAdresse;
|
||||
private String titel;
|
||||
private String text;
|
||||
|
||||
public String getEmailAdresse() {
|
||||
return emailAdresse;
|
||||
}
|
||||
|
||||
public void setEmailAdresse(String emailAdresse) {
|
||||
this.emailAdresse = emailAdresse;
|
||||
}
|
||||
|
||||
public String getTitel() {
|
||||
return titel;
|
||||
}
|
||||
|
||||
public void setTitel(String titel) {
|
||||
this.titel = titel;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("ping")
|
||||
public class PingResource {
|
||||
|
||||
@GET
|
||||
public Response ping() {
|
||||
LoggerFactory.getLogger(getClass()).debug("Ping");
|
||||
return Response.ok("ping").build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Registration {
|
||||
|
||||
private UUID id;
|
||||
private String name;
|
||||
private String email;
|
||||
private String passwordHash;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
public void setPasswordHash(String passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Registration [id=" + id + ", name=" + name + ", email=" + email + ", passwordHash=" + passwordHash
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import jakarta.ws.rs.ApplicationPath;
|
||||
import jakarta.ws.rs.core.Application;
|
||||
|
||||
@ApplicationPath("/")
|
||||
public class RegistrationApplication extends Application {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.transaction.HeuristicMixedException;
|
||||
import jakarta.transaction.HeuristicRollbackException;
|
||||
import jakarta.transaction.NotSupportedException;
|
||||
import jakarta.transaction.RollbackException;
|
||||
import jakarta.transaction.SystemException;
|
||||
import jakarta.transaction.UserTransaction;
|
||||
|
||||
@ApplicationScoped
|
||||
public class RegistrationDAO {
|
||||
|
||||
private Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@PersistenceContext(name = "registration")
|
||||
private EntityManager entityManager;
|
||||
@Resource
|
||||
private UserTransaction transaction;
|
||||
|
||||
public List<RegistrationEntity> findByEmail(String email) {
|
||||
TypedQuery<RegistrationEntity> query = entityManager
|
||||
.createQuery("select r from RegistrationEntity r where r.email = :email", RegistrationEntity.class);
|
||||
query.setParameter("email", email);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<RegistrationEntity> findByName(String name) {
|
||||
TypedQuery<RegistrationEntity> query = entityManager
|
||||
.createQuery("select r from RegistrationEntity r where r.name = :name", RegistrationEntity.class);
|
||||
query.setParameter("name", name);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public void update(RegistrationEntity toUpdate) {
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.merge(toUpdate);
|
||||
transaction.commit();
|
||||
} catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException
|
||||
| HeuristicMixedException | HeuristicRollbackException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void persist(RegistrationEntity toPersist) {
|
||||
try {
|
||||
transaction.begin();
|
||||
LOGGER.info("Persisting Entity " + toPersist);
|
||||
entityManager.persist(toPersist);
|
||||
transaction.commit();
|
||||
} catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException
|
||||
| HeuristicMixedException | HeuristicRollbackException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(RegistrationEntity toRemove) {
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.remove(toRemove);
|
||||
transaction.commit();
|
||||
} catch (NotSupportedException | SystemException | SecurityException | IllegalStateException | RollbackException
|
||||
| HeuristicMixedException | HeuristicRollbackException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public RegistrationEntity findById(UUID id) {
|
||||
return entityManager.find(RegistrationEntity.class, id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "registration")
|
||||
public class RegistrationEntity {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
private UUID registrationId;
|
||||
@Column
|
||||
private String name;
|
||||
@Column
|
||||
private String email;
|
||||
@Column
|
||||
private String password;
|
||||
@Column
|
||||
private Boolean activated;
|
||||
|
||||
public UUID getRegistrationId() {
|
||||
return registrationId;
|
||||
}
|
||||
|
||||
public void setRegistrationId(UUID registrationId) {
|
||||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RegistrationEntity [registrationId=" + registrationId + ", name=" + name + ", email=" + email + "]";
|
||||
}
|
||||
|
||||
public Registration toRegistration() {
|
||||
Registration registration = new Registration();
|
||||
registration.setId(registrationId);
|
||||
registration.setEmail(email);
|
||||
registration.setName(name);
|
||||
registration.setPasswordHash(password);
|
||||
return registration;
|
||||
}
|
||||
|
||||
public static RegistrationEntity create(Registration registration) {
|
||||
RegistrationEntity entity = new RegistrationEntity();
|
||||
entity.setRegistrationId(UUID.randomUUID());
|
||||
entity.setEmail(registration.getEmail());
|
||||
entity.setActivated(Boolean.FALSE);
|
||||
entity.setName(registration.getName());
|
||||
entity.setPassword(registration.getPasswordHash());
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Boolean getActivated() {
|
||||
return activated;
|
||||
}
|
||||
|
||||
public void setActivated(Boolean activated) {
|
||||
this.activated = activated;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package de.oaa.xxx.registration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.client.ClientBuilder;
|
||||
import jakarta.ws.rs.client.Entity;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("registration")
|
||||
@ApplicationScoped
|
||||
public class RegistrationResource {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationResource.class);
|
||||
|
||||
@Inject private RegistrationDAO dao;
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response create(Registration registration) {
|
||||
LOGGER.info("POST " + getClass().getName() + ": " + registration);
|
||||
if (dao.findByEmail(registration.getEmail()).size() > 0) {
|
||||
LOGGER.warn("User mit E-Mail " + registration.getEmail() + " bereits vorhanden");
|
||||
return Response.status(400).build();
|
||||
}
|
||||
RegistrationEntity entity = RegistrationEntity.create(registration);
|
||||
dao.persist(entity);
|
||||
registration.setId(entity.getRegistrationId());
|
||||
Email email = new Email();
|
||||
email.setTitel("Bitte bestätige deine E-Mail Adresse");
|
||||
email.setEmailAdresse(registration.getEmail());
|
||||
email.setText(getMailText(registration));
|
||||
if (!sendEmail(email)) {
|
||||
dao.remove(entity);
|
||||
return Response.serverError().build();
|
||||
}
|
||||
return Response.accepted().build();
|
||||
}
|
||||
|
||||
private boolean sendEmail(Email email) {
|
||||
boolean result = false;
|
||||
Client client = null;
|
||||
try {
|
||||
client = ClientBuilder.newClient();
|
||||
Response response = client.target("http://localhost:8080/mail-service/send").request().post(Entity.entity(email, MediaType.APPLICATION_JSON));
|
||||
if (200 == response.getStatus()) {
|
||||
result = true;
|
||||
} else {
|
||||
LOGGER.error("E-Mail konnte nicht erzeugt werden...Status: {}", response.getStatus());
|
||||
}
|
||||
} finally {
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response get(@QueryParam("id") UUID id) {
|
||||
RegistrationEntity entity = dao.findById(id);
|
||||
if (entity != null) {
|
||||
return Response.ok(entity.toRegistration()).build();
|
||||
} else {
|
||||
return Response.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getMailText(Registration registration) {
|
||||
return """
|
||||
<html>
|
||||
<h1>Moin %s</h1>
|
||||
<p>Vielen Dank für deine Anmeldung bei XXX-BDSM Game!</p>
|
||||
<p>Klicke <a href=\"http://localhost:8080/registration-service/activation/%s\">hier</a> um deine E-Mail-Adresse zu bestätigen.</p>
|
||||
<p>Und nun viel Spass beim Spiel!</p>
|
||||
</html>""".formatted(registration.getName(), registration.getId().toString());
|
||||
}
|
||||
|
||||
}
|
||||
17
registration-service/src/main/resources/log4j2.xml
Normal file
17
registration-service/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="MyFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Validate the database schema on startup -->
|
||||
<property name="hbm2ddl.auto">validate</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0" >
|
||||
|
||||
<persistence-unit name="registration"
|
||||
transaction-type="JTA">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:/Registration</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.MySQLDialect" />
|
||||
<property
|
||||
name="javax.persistence.schema-generation.database.action"
|
||||
value="drop-and-create" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
6
registration-service/src/main/webapp/WEB-INF/web.xml
Normal file
6
registration-service/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><web-app version="5.0"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd">
|
||||
|
||||
</web-app>
|
||||
1
registration-service/src/main/webapp/activation.html
Normal file
1
registration-service/src/main/webapp/activation.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Registrierung erfolgreich abgeschlossen</h1>
|
||||
1
registration-service/src/main/webapp/index.html
Normal file
1
registration-service/src/main/webapp/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Was machst du hier?</h1>
|
||||
Reference in New Issue
Block a user