Skip to content

Commit

Permalink
Updated project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanerobb committed May 12, 2022
1 parent 11ad2a6 commit 874f94f
Show file tree
Hide file tree
Showing 37 changed files with 247 additions and 119 deletions.
13 changes: 13 additions & 0 deletions .idea/libraries/Maven__net_bytebuddy_byte_buddy_1_12_9.xml

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

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__net_bytebuddy_byte_buddy_agent_1_12_9.xml

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

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_mockito_mockito_core_4_5_1.xml

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

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_objenesis_objenesis_3_2.xml

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

10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

<dependencies>


<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
Expand Down Expand Up @@ -83,6 +84,15 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>



</dependencies>

Expand Down
6 changes: 5 additions & 1 deletion romane_robb_banking_p0.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/romane_robb_java/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
Expand All @@ -22,5 +22,9 @@
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:4.5.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.12.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.12.9" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:3.2" level="project" />
</component>
</module>
83 changes: 0 additions & 83 deletions romane_robb_java/src/com/robb/banking/services/UserServices.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/com/robb/banking/daos/Account_infoDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.robb.banking.daos;

public class Account_infoDao {
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.robb.banking.daos;

import com.robb.banking.util.ConnectionFactory;
import com.robb.banking.models.Customer_info;
import com.robb.banking.util.ConnectionFactory;
import com.robb.banking.util.logging.Logger;
import com.robb.banking.exceptions.ResourcePersistanceException;

import java.io.IOException;
import java.sql.*;
import java.io.*;

public class UserDao implements Crudable<Customer_info> {
public class Customer_infoDao implements Crudable<Customer_info> {

private Logger logger = Logger.getLogger();

Expand Down Expand Up @@ -47,7 +47,7 @@ public Customer_info create(Customer_info newCustomer_info) {
}

@Override
public Customer_info[] findAll() throws IOException {
public static Customer_info[] findAll() throws IOException {

Customer_info[] customer_infos = new Customer_info[10];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.robb.banking.services;

public class Account_infoServices {
}
102 changes: 102 additions & 0 deletions src/main/java/com/robb/banking/services/Customer_infoServices.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.robb.banking.services;
import com.robb.banking.exceptions.AuthenticationException;
import com.robb.banking.exceptions.InvalidRequestException;
import com.robb.banking.models.Customer_info;
import com.robb.banking.daos.Customer_infoDao;
import com.robb.banking.exceptions.ResourcePersistanceException;
import com.robb.banking.util.logging.Logger;

import java.io.IOException;

public class Customer_infoServices implements Serviceable<Customer_info> {

private Customer_infoDao customer_infoDao;

private Logger logger = Logger.getLogger();

public Customer_info[] readAll() {
logger.info("Begin reading customers in our file database.");

try {
Customer_info[] customer_infos = Customer_infoDao.findAll();
logger.info("All customers have been found and here are the results: \n");

return customer_infos;

} catch (IOException | NullPointerException e) {
e.printStackTrace();
return null;
}
}

@Override
public Customer_info readById(String id) {
return null;
}

@Override
public Customer_info update(Customer_info updateObject) {
return null;
}

@Override
public boolean delete(String id) {
return false;
}

@Override
public boolean validateInput(Customer_info object) {
return false;
}

public boolean validateEmailNotUsed(String email) {
return customer_infoDao.checkEmail(email);
}

public Customer_info create(Customer_info newCustomer_info) {
logger.info("Customer trying to be registered: " + newCustomer_info);
if (!validateInput(newCustomer_info)) {
throw new InvalidRequestException("Customer input was not validated. This could be due to an empty String or null values");
}

Customer_info persistedCustomer_info = customer_infoDao.create(newCustomer_info);

if (persistedCustomer_info == null) {
throw new ResourcePersistanceException("Customer was not persisted to the database upon registration.");
}
logger.info("Customer has been persisted: " + newCustomer_info);
return persistedCustomer_info;
}


public boolean validateUserInput(Customer_info newCustomer_info) {
System.out.println("Validating Customer: " + newCustomer_info);
if (newCustomer_info == null) return false;
if (newCustomer_info.getFirst_name() == null || newCustomer_info.getFirst_name().trim().equals(""))
return false;
if (newCustomer_info.getLast_name() == null || newCustomer_info.getLast_name().trim().equals("")) return false;
if (newCustomer_info.getEmail_address() == null || newCustomer_info.getEmail_address().trim().equals(""))
return false;
if (newCustomer_info.getUserpassword() == null || newCustomer_info.getUserpassword().trim().equals(""))
return false;
return newCustomer_info.getDate_of_birth() != null || !newCustomer_info.getDate_of_birth().trim().equals("");
}

public Customer_info authenticateCustomer_info(String email, String password) {

if (password == null || password.trim().equals("") || password == null || password.trim().equals("")) {
throw new InvalidRequestException("Either the username or the password is an invalid entry. Please try logging in again.");
}

Customer_info authenticatedCustomer_info = customer_infoDao.authenticateCustomer_info(email, password);


if (authenticatedCustomer_info == null) {
throw new AuthenticationException("Unauthenticated user. The information provided was not consistent with our database.");
}


return authenticatedCustomer_info;

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.robb.banking.util;

import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.robb.banking.web.servlets;

public class Account_infoServlet {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.robb.banking.web.servlets;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.robb.banking.exceptions.InvalidRequestException;
import com.robb.banking.models.Customer_info;
import com.robb.banking.services.UserServices;

import javax.naming.AuthenticationException;
import com.robb.banking.services.Customer_infoServices;
import com.robb.banking.web.dto.LoginCreds;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.robb.banking.exceptions.AuthenticationException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -14,22 +14,22 @@

public class AuthServlet extends HttpServlet {

private final UserServices userServices;
private final Customer_infoServices customer_infoServices;

private final ObjectMapper mapper;

public AuthServlet(UserServices userServices, ObjectMapper mapper){
this.userServices = userServices;
public AuthServlet(Customer_infoServices userServices, ObjectMapper mapper){
this.customer_infoServices = userServices;
this.mapper = mapper;
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

try {
LoginCreds loginCreds = mapper.readvalue(req.getInputStream(), LoginCreds.class);
LoginCreds loginCreds = mapper.readValue(req.getInputStream(), LoginCreds.class);

Customer_info authCustomer_info = userServices.authenticateCustomer_info(loginCreds.getEmail(), loginCreds.getPassword());
Customer_info authCustomer_info = customer_infoServices.authenticateCustomer_info(loginCreds.getEmail(), loginCreds.getPassword());

HttpSession httpSession = req.getSession(true);
httpSession.setAttribute("authTrainer", authCustomer_info);
Expand Down
Loading

0 comments on commit 874f94f

Please sign in to comment.