From 854b5b1ec9f1d19b0313b0b5f78c29822e2671da Mon Sep 17 00:00:00 2001 From: Reid Phillips Date: Sat, 11 Jan 2020 10:35:59 -0600 Subject: [PATCH 01/29] Shared, initial changes for sprint2, incomplete. --- .../ValidateActiveUserCommand.java | 41 +++++ .../employees/helpers/EmployeeHelper.java | 23 +++ .../controllers/BaseRestController.java | 89 ++++++++++ .../controllers/BaseRouteController.java | 117 +++++++++++++ .../enums/QueryParameterMessages.java | 45 +++++ .../controllers/enums/ViewNames.java | 5 +- .../uark/registerapp/models/api/Employee.java | 145 ++++++++++++++++ .../models/entities/ActiveUserEntity.java | 91 ++++++++++ .../models/entities/EmployeeEntity.java | 164 ++++++++++++++++++ .../models/enums/EmployeeClassification.java | 58 +++++++ .../repositories/ActiveUserRepository.java | 13 ++ .../repositories/EmployeeRepository.java | 15 ++ src/main/resources/static/scripts/master.js | 26 +++ src/main/resources/static/styles/master.css | 18 ++ 14 files changed, 849 insertions(+), 1 deletion(-) create mode 100644 src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java create mode 100644 src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/BaseRestController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java create mode 100644 src/main/java/edu/uark/registerapp/models/api/Employee.java create mode 100644 src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java create mode 100644 src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java create mode 100644 src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java create mode 100644 src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java create mode 100644 src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java new file mode 100644 index 00000000..d04784cb --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ValidateActiveUserCommand.java @@ -0,0 +1,41 @@ +package edu.uark.registerapp.commands.activeUsers; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; + +@Service +public class ValidateActiveUserCommand implements ResultCommandInterface { + @Override + public ActiveUserEntity execute() { + final Optional activeUserEntity = + this.activeUserRepository.findBySessionKey(this.sessionKey); + + if (!activeUserEntity.isPresent()) { + throw new UnauthorizedException(); + } + + return activeUserEntity.get(); + } + + // Properties + private String sessionKey; + + public String getSessionKey() { + return this.sessionKey; + } + + public ValidateActiveUserCommand setSessionKey(final String sessionKey) { + this.sessionKey = sessionKey; + return this; + } + + @Autowired + private ActiveUserRepository activeUserRepository; +} diff --git a/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java b/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java new file mode 100644 index 00000000..5b9ddc71 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/employees/helpers/EmployeeHelper.java @@ -0,0 +1,23 @@ +package edu.uark.registerapp.commands.employees.helpers; + +import org.apache.commons.lang3.StringUtils; + +public class EmployeeHelper { + public static String padEmployeeId(final int employeeId) { + final String employeeIdAsString = Integer.toString(employeeId); + + return ((employeeIdAsString.length() < EMPLOYEE_ID_MAXIMUM_LENGTH) + ? StringUtils.leftPad( + employeeIdAsString, + EMPLOYEE_ID_MAXIMUM_LENGTH, + "0") + : employeeIdAsString); + } + + public static byte[] hashPassword(final String password) { + // TODO: Hash the password using a MessageDigest. An example can be found at http://tutorials.jenkov.com/java-cryptography/messagedigest.html + return new byte[0]; + } + + private static final int EMPLOYEE_ID_MAXIMUM_LENGTH = 5; +} diff --git a/src/main/java/edu/uark/registerapp/controllers/BaseRestController.java b/src/main/java/edu/uark/registerapp/controllers/BaseRestController.java new file mode 100644 index 00000000..0f39f55f --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/BaseRestController.java @@ -0,0 +1,89 @@ +package edu.uark.registerapp.controllers; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import edu.uark.registerapp.commands.activeUsers.ValidateActiveUserCommand; +import edu.uark.registerapp.commands.exceptions.ConflictException; +import edu.uark.registerapp.commands.exceptions.NotFoundException; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; +import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; +import edu.uark.registerapp.controllers.enums.QueryParameterMessages; +import edu.uark.registerapp.controllers.enums.QueryParameterNames; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.api.ApiResponse; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.enums.EmployeeClassification; + +public class BaseRestController extends BaseController { + protected ApiResponse redirectSessionNotActive( + final HttpServletResponse response + ) { + + response.setStatus(HttpStatus.FOUND.value()); + return (new ApiResponse()) + .setRedirectUrl( + ViewNames.SIGN_IN.getRoute().concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.SESSION_NOT_ACTIVE.getKeyAsString()))); + } + + protected ApiResponse redirectUserNotElevated( + final HttpServletRequest request, + final HttpServletResponse response + ) { + + return this.redirectUserNotElevated(request, response, ViewNames.MAIN_MENU.getRoute()); + } + + protected ApiResponse redirectUserNotElevated( + final HttpServletRequest request, + final HttpServletResponse response, + final String redirectRoute + ) { + + try { + final ActiveUserEntity activeUserEntity = + this.validateActiveUserCommand + .setSessionKey(request.getSession().getId()) + .execute(); + + if (activeUserEntity == null) { + return this.redirectSessionNotActive(response); + } else if (!EmployeeClassification.isElevatedUser(activeUserEntity.getClassification())) { + response.setStatus(HttpStatus.FOUND.value()); + + return (new ApiResponse()) + .setRedirectUrl( + redirectRoute.concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.NO_PERMISSIONS_FOR_ACTION.getKeyAsString()))); + } + } catch (final UnauthorizedException e) { + return this.redirectSessionNotActive(response); + } + + return new ApiResponse(); + } + + @ExceptionHandler({ + ConflictException.class, + NotFoundException.class, + UnauthorizedException.class, + UnprocessableEntityException.class + }) + public @ResponseBody ApiResponse handleError(final Exception e) { + return (new ApiResponse()).setErrorMessage(e.getMessage()); + } + + // Properties + @Autowired + private ValidateActiveUserCommand validateActiveUserCommand; +} diff --git a/src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java b/src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java new file mode 100644 index 00000000..58774f84 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/BaseRouteController.java @@ -0,0 +1,117 @@ +package edu.uark.registerapp.controllers; + +import java.util.Map; +import java.util.Optional; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.ModelAndView; + +import edu.uark.registerapp.commands.activeUsers.ValidateActiveUserCommand; +import edu.uark.registerapp.commands.exceptions.UnauthorizedException; +import edu.uark.registerapp.controllers.enums.ViewModelNames; +import edu.uark.registerapp.controllers.enums.QueryParameterMessages; +import edu.uark.registerapp.controllers.enums.QueryParameterNames; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.enums.EmployeeClassification; + +public abstract class BaseRouteController extends BaseController { + protected ModelAndView setErrorMessageFromQueryString( + ModelAndView modelAndView, + final Map queryParameters + ) { + + if (!queryParameters.containsKey(QueryParameterNames.ERROR_CODE.getValue())) { + return modelAndView; + } + + try { + modelAndView = + this.setErrorMessageFromQueryString( + modelAndView, + Integer.parseInt( + queryParameters.get( + QueryParameterNames.ERROR_CODE.getValue()))); + } catch (final NumberFormatException e) { } + + return modelAndView; + } + protected ModelAndView setErrorMessageFromQueryString( + final ModelAndView modelAndView, + final Optional errorCode + ) { + + if (!errorCode.isPresent()) { + return modelAndView; + } + + return this.setErrorMessageFromQueryString(modelAndView, errorCode.get()); + } + + protected Optional getCurrentUser( + final HttpServletRequest request + ) { + + try { + return Optional.of( + this.validateActiveUserCommand + .setSessionKey(request.getSession().getId()) + .execute()); + } catch (final UnauthorizedException e) { + return Optional.ofNullable(null); + } + } + + protected ModelAndView buildInvalidSessionResponse() { + return new ModelAndView( + REDIRECT_PREPEND.concat( + ViewNames.SIGN_IN.getRoute().concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.SESSION_NOT_ACTIVE.getKeyAsString())))); + } + + protected boolean isElevatedUser(final ActiveUserEntity activeUserEntity) { + return EmployeeClassification.isElevatedUser( + activeUserEntity.getClassification()); + } + + protected ModelAndView buildNoPermissionsResponse() { + return this.buildNoPermissionsResponse(ViewNames.MAIN_MENU.getRoute()); + } + + protected ModelAndView buildNoPermissionsResponse(final String redirectRoute) { + return new ModelAndView( + REDIRECT_PREPEND.concat( + redirectRoute.concat( + this.buildInitialQueryParameter( + QueryParameterNames.ERROR_CODE.getValue(), + QueryParameterMessages.NO_PERMISSIONS_TO_VIEW.getKeyAsString())))); + } + + protected static final String REDIRECT_PREPEND = "redirect:"; + + // Helper methods + private ModelAndView setErrorMessageFromQueryString( + final ModelAndView modelAndView, + final int errorCode + ) { + + final String errorMessage = QueryParameterMessages.mapMessage(errorCode); + + if (!StringUtils.isBlank(errorMessage)) { + modelAndView.addObject( + ViewModelNames.ERROR_MESSAGE.getValue(), + errorMessage); + } + + return modelAndView; + } + + // Properties + @Autowired + private ValidateActiveUserCommand validateActiveUserCommand; +} diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java b/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java new file mode 100644 index 00000000..3f1bed87 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/enums/QueryParameterMessages.java @@ -0,0 +1,45 @@ +package edu.uark.registerapp.controllers.enums; + +import java.util.HashMap; +import java.util.Map; + +public enum QueryParameterMessages { + NOT_DEFINED(-1, ""), + SESSION_NOT_ACTIVE(1001, "The current user's session is no longer active."), + NO_PERMISSIONS_TO_VIEW(1101, "You do not have permission to view this resource."), + NO_PERMISSIONS_FOR_ACTION(1102, "You do not have permission to perform this action."); + + public int getKey() { + return this.key; + } + public String getKeyAsString() { + return Integer.toString(this.key); + } + public String getMessage() { + return this.message; + } + + public static String mapMessage(final int key) { + if (valueMap == null) { + valueMap = new HashMap(); + + for (final QueryParameterMessages status : QueryParameterMessages.values()) { + valueMap.put(status.getKey(), status.getMessage()); + } + } + + return (valueMap.containsKey(key) + ? valueMap.get(key) + : QueryParameterMessages.NOT_DEFINED.getMessage()); + } + + private int key; + private String message; + + private static Map valueMap = null; + + private QueryParameterMessages(final int key, final String message) { + this.key = key; + this.message = message; + } +} diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java index cd1a1246..3e3e2ca2 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewNames.java @@ -1,8 +1,11 @@ package edu.uark.registerapp.controllers.enums; public enum ViewNames { + SIGN_IN("signIn", "/"), + MAIN_MENU("mainMenu"), PRODUCT_DETAIL("productDetail"), - PRODUCT_LISTING("productListing", "/"); + EMPLOYEE_DETAIL("employeeDetail"), + PRODUCT_LISTING("productListing"); public String getRoute() { return this.route; diff --git a/src/main/java/edu/uark/registerapp/models/api/Employee.java b/src/main/java/edu/uark/registerapp/models/api/Employee.java new file mode 100644 index 00000000..6e313bfc --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/api/Employee.java @@ -0,0 +1,145 @@ +package edu.uark.registerapp.models.api; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; + +import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; +import edu.uark.registerapp.models.entities.EmployeeEntity; + +public class Employee extends ApiResponse { + private UUID id; + public UUID getId() { + return this.id; + } + public Employee setId(final UUID id) { + this.id = id; + return this; + } + + private String employeeId; + public String getEmployeeId() { + return this.employeeId; + } + public Employee setEmployeeId(final int employeeId) { + this.employeeId = EmployeeHelper.padEmployeeId(employeeId); + return this; + } + public Employee setEmployeeId(final String employeeId) { + this.employeeId = employeeId; + return this; + } + + private String firstName; + public String getFirstName() { + return this.firstName; + } + public Employee setFirstName(final String firstName) { + this.firstName = firstName; + return this; + } + + private String lastName; + public String getLastName() { + return this.lastName; + } + public Employee setLastName(final String lastName) { + this.lastName = lastName; + return this; + } + + private String password; + public String getPassword() { + return this.password; + } + public Employee setPassword(final String password) { + this.password = password; + return this; + } + + private boolean isActive; + public boolean getIsActive() { + return this.isActive; + } + public Employee setIsActive(final boolean isActive) { + this.isActive = isActive; + return this; + } + + private int classification; + public int getClassification() { + return this.classification; + } + public Employee setClassification(final int classification) { + this.classification = classification; + return this; + } + + private UUID managerId; + public UUID getManagerId() { + return this.managerId; + } + public Employee setManagerId(final UUID managerId) { + this.managerId = managerId; + return this; + } + + private String createdOn; + public String getCreatedOn() { + return this.createdOn; + } + public Employee setCreatedOn(final String createdOn) { + this.createdOn = createdOn; + return this; + } + public Employee setCreatedOn(final LocalDateTime createdOn) { + this.createdOn = + createdOn.format(DateTimeFormatter.ofPattern("MM/dd/yyyy")); + + return this; + } + + private boolean isInitialEmployee; + public boolean getIsInitialEmployee() { + return this.isInitialEmployee; + } + public Employee setIsInitialEmployee(final boolean isInitialEmployee) { + this.isInitialEmployee = isInitialEmployee; + return this; + } + + public Employee() { + super(); + + this.isActive = true; + this.id = new UUID(0, 0); + this.classification = -1; + this.isInitialEmployee = false; + this.managerId = new UUID(0, 0); + this.lastName = StringUtils.EMPTY; + this.password = StringUtils.EMPTY; + this.firstName = StringUtils.EMPTY; + this.employeeId = StringUtils.EMPTY; + + this.setCreatedOn(LocalDateTime.now()); + } + + public Employee(final EmployeeEntity employeeEntity) { + super(false); + + this.isInitialEmployee = false; + this.id = employeeEntity.getId(); + this.password = StringUtils.EMPTY; + this.isActive = employeeEntity.getIsActive(); + this.lastName = employeeEntity.getLastName(); + this.firstName = employeeEntity.getFirstName(); + this.managerId = employeeEntity.getManagerId(); + this.classification = employeeEntity.getClassification(); + this.employeeId = + EmployeeHelper.padEmployeeId(employeeEntity.getEmployeeId()); + + this.setCreatedOn(employeeEntity.getCreatedOn()); + } +} diff --git a/src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java b/src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java new file mode 100644 index 00000000..6eba3528 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/entities/ActiveUserEntity.java @@ -0,0 +1,91 @@ +package edu.uark.registerapp.models.entities; + +import java.time.LocalDateTime; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +@Entity +@Table(name="activeuser") +public class ActiveUserEntity { + @Id + @Column(name="id", updatable = false) + @GeneratedValue(strategy=GenerationType.AUTO) + private final UUID id; + + public UUID getId() { + return this.id; + } + + @Column(name = "employeeid") + private UUID employeeId; + + public UUID getEmployeeId() { + return this.employeeId; + } + + public ActiveUserEntity setEmployeeId(final UUID employeeId) { + this.employeeId = employeeId; + return this; + } + + @Column(name = "name") + private String name; + + public String getName() { + return this.name; + } + + public ActiveUserEntity setName(final String name) { + this.name = name; + return this; + } + + @Column(name = "classification") + private int classification; + + public int getClassification() { + return this.classification; + } + + public ActiveUserEntity setClassification(final int classification) { + this.classification = classification; + return this; + } + + @Column(name = "sessionkey") + private String sessionKey; + + public String getSessionKey() { + return this.sessionKey; + } + + public ActiveUserEntity setSessionKey(final String sessionKey) { + this.sessionKey = sessionKey; + return this; + } + + @Column(name="createdon", insertable=false, updatable = false) + @Generated(GenerationTime.INSERT) + private LocalDateTime createdOn; + public LocalDateTime getCreatedOn() { + return this.createdOn; + } + + public ActiveUserEntity() { + this.id = new UUID(0, 0); + this.classification = -1; + this.name = StringUtils.EMPTY; + this.employeeId = new UUID(0, 0); + this.sessionKey = StringUtils.EMPTY; + } +} diff --git a/src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java b/src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java new file mode 100644 index 00000000..324e5b31 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/entities/EmployeeEntity.java @@ -0,0 +1,164 @@ +package edu.uark.registerapp.models.entities; + +import java.time.LocalDateTime; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +import edu.uark.registerapp.commands.employees.helpers.EmployeeHelper; +import edu.uark.registerapp.models.api.Employee; + +@Entity +@Table(name="employee") +public class EmployeeEntity { + @Id + @Column(name="id", updatable = false) + @GeneratedValue(strategy=GenerationType.AUTO) + private final UUID id; + + public UUID getId() { + return this.id; + } + + @Column(name = "employeeid", insertable = false, updatable = false) + @Generated(GenerationTime.INSERT) + private int employeeId; + + public int getEmployeeId() { + return this.employeeId; + } + + @Column(name = "firstname") + private String firstName; + + public String getFirstName() { + return this.firstName; + } + + public EmployeeEntity setFirstName(final String firstName) { + this.firstName = firstName; + return this; + } + + @Column(name = "lastname") + private String lastName; + + public String getLastName() { + return this.lastName; + } + + public EmployeeEntity setLastName(final String lastName) { + this.lastName = lastName; + return this; + } + + @Column(name = "password") + private byte[] password; + + public byte[] getPassword() { + return this.password; + } + + public EmployeeEntity setPassword(final byte[] password) { + this.password = password; + return this; + } + + @Column(name = "active") + private boolean isActive; + + public boolean getIsActive() { + return this.isActive; + } + + public EmployeeEntity setIsActive(final boolean isActive) { + this.isActive = isActive; + return this; + } + + @Column(name = "classification") + private int classification; + + public int getClassification() { + return this.classification; + } + + public EmployeeEntity setClassification(final int classification) { + this.classification = classification; + return this; + } + + @Column(name = "managerid") + private UUID managerId; + + public UUID getManagerId() { + return this.managerId; + } + + public EmployeeEntity setManagerId(final UUID managerId) { + this.managerId = managerId; + return this; + } + + @Column(name = "createdon", insertable = false, updatable = false) + @Generated(GenerationTime.INSERT) + private LocalDateTime createdOn; + + public LocalDateTime getCreatedOn() { + return this.createdOn; + } + + public Employee synchronize(final Employee apiEmployee) { + this.setIsActive(apiEmployee.getIsActive()); + this.setLastName(apiEmployee.getLastName()); + this.setFirstName(apiEmployee.getFirstName()); + this.setClassification(apiEmployee.getClassification()); + if (apiEmployee.getManagerId() != null) { + this.setManagerId(apiEmployee.getManagerId()); + } + if (!StringUtils.isBlank(apiEmployee.getPassword())) { + this.setPassword( + EmployeeHelper.hashPassword( + apiEmployee.getPassword())); + } + + apiEmployee.setId(this.getId()); + apiEmployee.setCreatedOn(this.getCreatedOn()); + apiEmployee.setEmployeeId(this.getEmployeeId()); + + return apiEmployee; + } + + public EmployeeEntity() { + this.employeeId = -1; + this.isActive = false; + this.id = new UUID(0, 0); + this.classification = -1; + this.password = new byte[0]; + this.managerId = new UUID(0, 0); + this.lastName = StringUtils.EMPTY; + this.firstName = StringUtils.EMPTY; + } + + public EmployeeEntity(final Employee apiEmployee) { + this.id = new UUID(0, 0); + this.isActive = apiEmployee.getIsActive(); + this.lastName = apiEmployee.getLastName(); + this.firstName = apiEmployee.getFirstName(); + this.classification = apiEmployee.getClassification(); + this.password = EmployeeHelper.hashPassword(apiEmployee.getPassword()); + this.managerId = ( + (apiEmployee.getManagerId() != null) + ? apiEmployee.getManagerId() + : new UUID(0, 0)); + } +} diff --git a/src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java b/src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java new file mode 100644 index 00000000..751c80ef --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/enums/EmployeeClassification.java @@ -0,0 +1,58 @@ +package edu.uark.registerapp.models.enums; + +import java.util.HashMap; +import java.util.Map; + +public enum EmployeeClassification { + NOT_DEFINED(-1, "Not Selected"), + CASHIER(101, "Cashier"), + SHIFT_MANAGER(501, "Shift Manager"), + GENERAL_MANAGER(701, "General Manager"); + + public int getClassification() { + return this.classification; + } + + public String getDisplayLabel() { + return this.displayLabel; + } + + public static EmployeeClassification map(final int key) { + if (valueMap == null) { + valueMap = new HashMap(); + + for (final EmployeeClassification employeeClassification : EmployeeClassification.values()) { + valueMap.put( + employeeClassification.getClassification(), + employeeClassification); + } + } + + return ((valueMap.containsKey(key) + ? valueMap.get(key) + : EmployeeClassification.NOT_DEFINED)); + } + + public static boolean isElevatedUser(final int classification) { + final EmployeeClassification employeeClassification = + EmployeeClassification.map(classification); + + return ( + (employeeClassification == EmployeeClassification.GENERAL_MANAGER) + || (employeeClassification == EmployeeClassification.SHIFT_MANAGER)); + } + + private int classification; + private String displayLabel; + + private static Map valueMap = null; + + private EmployeeClassification( + final int classification, + final String displayLabel + ) { + + this.displayLabel = displayLabel; + this.classification = classification; + } +} diff --git a/src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java b/src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java new file mode 100644 index 00000000..53746cee --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/repositories/ActiveUserRepository.java @@ -0,0 +1,13 @@ +package edu.uark.registerapp.models.repositories; + +import java.util.Optional; +import java.util.UUID; + +import org.springframework.data.repository.CrudRepository; + +import edu.uark.registerapp.models.entities.ActiveUserEntity; + +public interface ActiveUserRepository extends CrudRepository { + Optional findByEmployeeId(UUID employeeId); + Optional findBySessionKey(String sessionKey); +} diff --git a/src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java b/src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java new file mode 100644 index 00000000..8ba4b81f --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/repositories/EmployeeRepository.java @@ -0,0 +1,15 @@ +package edu.uark.registerapp.models.repositories; + +import java.util.Optional; +import java.util.UUID; + +import org.springframework.data.repository.CrudRepository; + +import edu.uark.registerapp.models.entities.EmployeeEntity; + +public interface EmployeeRepository extends CrudRepository { + boolean existsByIsActive(boolean isActive); + boolean existsByEmployeeId(int employeeId); + Optional findById(UUID id); + Optional findByEmployeeId(int employeeId); +} diff --git a/src/main/resources/static/scripts/master.js b/src/main/resources/static/scripts/master.js index 88b039d0..c61d3563 100644 --- a/src/main/resources/static/scripts/master.js +++ b/src/main/resources/static/scripts/master.js @@ -1,3 +1,10 @@ +document.addEventListener("DOMContentLoaded", () => { + const signOutActionElement = getSignOutActionElement(); + if (signOutActionElement != null) { + signOutActionElement.addEventListener("click", signOutActionClickHandler); + } +}); + // AJAX function ajaxGet(resourceRelativeUri, callback) { return ajax(resourceRelativeUri, "GET", null, callback); @@ -158,6 +165,10 @@ function displayError(errorMessage) { // End display error message //Getters and setters +function getSignOutActionElement() { + return document.getElementById("signOutImage"); +} + function getErrorMessageContainerElement() { return document.getElementById("error"); } @@ -166,3 +177,18 @@ function getErrorMessageDisplayElement() { return document.getElementById("errorMessage"); } // End getters and setters + +//Sign out +function signOutActionClickHandler() { + ajaxDelete("/api/signOut", (callbackResponse) => { + if ((callbackResponse.data != null) + && (callbackResponse.data.redirectUrl != null) + && (callbackResponse.data.redirectUrl !== "")) { + + window.location.replace(callbackResponse.data.redirectUrl); + } else { + window.location.replace("/"); + } + }); +} +//End sign out \ No newline at end of file diff --git a/src/main/resources/static/styles/master.css b/src/main/resources/static/styles/master.css index 2b060e6d..f35bb48a 100644 --- a/src/main/resources/static/styles/master.css +++ b/src/main/resources/static/styles/master.css @@ -30,6 +30,24 @@ td.hidden { display: none } +div.footer { + left: 0; + right: 0; + bottom: 0; + position: absolute; +} + +img.footer { + z-index: 1; + height: 50px; + text-decoration: none; + display: inline-block; + cursor: pointer; + position: fixed; + right: 20; + bottom: 20; +} + div.inputContent, form.inputContent { display: inline-block; From 4ff35304f25f4a27815576183a4fd98c510758fd Mon Sep 17 00:00:00 2001 From: Reid Phillips Date: Sat, 11 Jan 2020 10:50:36 -0600 Subject: [PATCH 02/29] Initial changes for sprint 2 sign in and main menu functionality, incomplete. --- .../controllers/MainMenuRouteController.java | 45 +++++++++++++++++ .../controllers/SignInRestController.java | 26 ++++++++++ .../controllers/SignInRouteController.java | 32 ++++++++++++ .../controllers/enums/ViewModelNames.java | 1 + src/main/resources/static/scripts/signIn.js | 8 +++ src/main/resources/templates/mainMenu.html | 49 +++++++++++++++++++ src/main/resources/templates/signIn.html | 31 ++++++++++++ 7 files changed, 192 insertions(+) create mode 100644 src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/SignInRestController.java create mode 100644 src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java create mode 100644 src/main/resources/static/scripts/signIn.js create mode 100644 src/main/resources/templates/mainMenu.html create mode 100644 src/main/resources/templates/signIn.html diff --git a/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java new file mode 100644 index 00000000..9a3cda2d --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/MainMenuRouteController.java @@ -0,0 +1,45 @@ +package edu.uark.registerapp.controllers; + +import java.util.Map; +import java.util.Optional; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import edu.uark.registerapp.controllers.enums.ViewModelNames; +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.entities.ActiveUserEntity; + +@Controller +@RequestMapping(value = "/mainMenu") +public class MainMenuRouteController extends BaseRouteController { + @RequestMapping(method = RequestMethod.GET) + public ModelAndView start( + @RequestParam final Map queryParameters, + final HttpServletRequest request + ) { + + final Optional activeUserEntity = + this.getCurrentUser(request); + if (!activeUserEntity.isPresent()) { + return this.buildInvalidSessionResponse(); + } + + ModelAndView modelAndView = + this.setErrorMessageFromQueryString( + new ModelAndView(ViewNames.MAIN_MENU.getViewName()), + queryParameters); + + // TODO: Examine the ActiveUser classification if you want this information + modelAndView.addObject( + ViewModelNames.IS_ELEVATED_USER.getValue(), + true); + + return modelAndView; + } +} diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java new file mode 100644 index 00000000..68133574 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java @@ -0,0 +1,26 @@ +package edu.uark.registerapp.controllers; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import edu.uark.registerapp.controllers.enums.ViewNames; +import edu.uark.registerapp.models.api.ApiResponse; + +@RestController +@RequestMapping(value = "/api") +public class SignInRestController extends BaseRestController { + @RequestMapping(value="/signOut", method = RequestMethod.DELETE) + public @ResponseBody ApiResponse removeActiveUser( + final HttpServletRequest request + ) { + + // TODO: Sign out the user associated with request.getSession().getId() + + return (new ApiResponse()) + .setRedirectUrl(ViewNames.SIGN_IN.getRoute()); + } +} diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java new file mode 100644 index 00000000..306f98fb --- /dev/null +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRouteController.java @@ -0,0 +1,32 @@ +package edu.uark.registerapp.controllers; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import edu.uark.registerapp.controllers.enums.ViewNames; + +@Controller +@RequestMapping(value = "/") +public class SignInRouteController extends BaseRouteController { + // TODO: Route for initial page load + + @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) + public ModelAndView performSignIn( + // TODO: Define an object that will represent the sign in request and add it as a parameter here + HttpServletRequest request + ) { + + // TODO: Use the credentials provided in the request body + // and the "id" property of the (HttpServletRequest)request.getSession() variable + // to sign in the user + + return new ModelAndView( + REDIRECT_PREPEND.concat( + ViewNames.MAIN_MENU.getRoute())); + } +} diff --git a/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java b/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java index 7c39b102..6ee26935 100644 --- a/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java +++ b/src/main/java/edu/uark/registerapp/controllers/enums/ViewModelNames.java @@ -3,6 +3,7 @@ public enum ViewModelNames { NOT_DEFINED(""), ERROR_MESSAGE("errorMessage"), + IS_ELEVATED_USER("isElevatedUser"), PRODUCTS("products"), // Product listing PRODUCT("product"); // Product detail diff --git a/src/main/resources/static/scripts/signIn.js b/src/main/resources/static/scripts/signIn.js new file mode 100644 index 00000000..a1524a6a --- /dev/null +++ b/src/main/resources/static/scripts/signIn.js @@ -0,0 +1,8 @@ +document.addEventListener("DOMContentLoaded", function(event) { + // TODO: Anything you want to do when the page is loaded? +}); + +function validateForm() { + // TODO: Validate the user input + return true; +} diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html new file mode 100644 index 00000000..36bdbf1b --- /dev/null +++ b/src/main/resources/templates/mainMenu.html @@ -0,0 +1,49 @@ + + + + Register - Main Menu + + + + + + + + + + +
+

Main Menu

+
+ +
+
+

+
+ + +
+ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html new file mode 100644 index 00000000..96f63609 --- /dev/null +++ b/src/main/resources/templates/signIn.html @@ -0,0 +1,31 @@ + + + + Register - Sign In + + + + + + + + + + +
+

Sign In

+
+ +
+
+

+
+ +
+ +
+
+ + + + \ No newline at end of file From 49821087d911e6176fc77d8d7e12a862f0344d81 Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Fri, 12 Feb 2021 06:01:00 +0900 Subject: [PATCH 03/29] Update signIn.html validate employee ID and password --- src/main/resources/templates/signIn.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index 96f63609..556bb5ca 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -1,4 +1,4 @@ - + -- task three Sign in client side functionality Register - Sign In @@ -28,4 +28,4 @@

- \ No newline at end of file + From 74774365847f15e5d61fc483fd1acee72088cb68 Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Tue, 16 Feb 2021 06:35:06 +0900 Subject: [PATCH 04/29] Update signIn.html add employee ID and password submit buttons --- src/main/resources/templates/signIn.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index 556bb5ca..88de8443 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -1,4 +1,4 @@ - -- task three Sign in client side functionality + Register - Sign In @@ -10,6 +10,14 @@ +
+ Employee ID: + + + Password: + +
+
From ae507eaf604e6a7e0461ccb1946df590a8e3d1cc Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Tue, 16 Feb 2021 09:37:09 +0900 Subject: [PATCH 05/29] Update signIn.html change place of input fields --- src/main/resources/templates/signIn.html | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index 88de8443..b12f97fc 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -1,4 +1,4 @@ - + //sprint2 task3 Register - Sign In @@ -9,14 +9,6 @@ - -
- Employee ID: - - - Password: - -
@@ -25,6 +17,18 @@

Sign In

+
+
+ + +
+
+ + +
+ +
+

From 633aa87deaa35f291c264de5aa4bdd53864c731f Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Wed, 17 Feb 2021 04:36:36 +0900 Subject: [PATCH 06/29] Update mainMenu.html add five buttons to go github links --- src/main/resources/templates/mainMenu.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index 36bdbf1b..e605e996 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -17,6 +17,14 @@

Main Menu

+ + + + + + + +

@@ -46,4 +54,4 @@

- \ No newline at end of file + From 1b43c68114fddd3645d13137bb69baf20dbb5780 Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Wed, 17 Feb 2021 07:26:09 +0900 Subject: [PATCH 07/29] Update signIn.html correct button word --- src/main/resources/templates/signIn.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index b12f97fc..6c981504 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -1,4 +1,4 @@ - //sprint2 task3 + Register - Sign In @@ -26,7 +26,7 @@

Sign In

- +
From cef371d8a82abb371a91db9b4edb2d8663de7035 Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Wed, 17 Feb 2021 07:46:27 +0900 Subject: [PATCH 08/29] Update mainMenu.html I need to figure out how to find appropriate url place --- src/main/resources/templates/mainMenu.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index e605e996..c57b8b25 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -17,7 +17,7 @@

Main Menu

- + From 6b1e3a7682d4824dfea86f4eebbb515161c7ee8a Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Wed, 17 Feb 2021 08:33:22 +0900 Subject: [PATCH 09/29] Update mainMenu.html add buttons with alert messages --- src/main/resources/templates/mainMenu.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index c57b8b25..c1d637ea 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -18,11 +18,11 @@

Main Menu

- + - - + +
From cb3a8a021a816a27d5f9f36545fd1069cf7a1d1c Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Fri, 19 Feb 2021 06:20:34 +0900 Subject: [PATCH 10/29] Update signIn.html fix button function and add some comments --- src/main/resources/templates/signIn.html | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index 6c981504..601cafab 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -1,4 +1,4 @@ - + Register - Sign In @@ -17,24 +17,25 @@

Sign In

+
+

+
+
-
+ + + +
-
-
+
+ +
- -
- - - -
-

-
+ +
-
- +
From 4a8a40f615483bdc45cc0086967155b3077a6ce6 Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Fri, 19 Feb 2021 06:23:09 +0900 Subject: [PATCH 11/29] Update signIn.js create functions of validate whether EmployeeID & Password are blank and whether EmployeeID is index --- src/main/resources/static/scripts/signIn.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/resources/static/scripts/signIn.js b/src/main/resources/static/scripts/signIn.js index a1524a6a..0cb0f343 100644 --- a/src/main/resources/static/scripts/signIn.js +++ b/src/main/resources/static/scripts/signIn.js @@ -4,5 +4,21 @@ document.addEventListener("DOMContentLoaded", function(event) { function validateForm() { // TODO: Validate the user input - return true; + //get value of Employee ID and Password + var employeeId = document.getElementById("employeeId").value; + var password = document.getElementById("password").value; + + if (employeeId != '' && password != ''){ + if (isNaN(employeeId)) { + document.getElementById("errorMessage").innerHTML = "You can use only index" + } + else { + document.getElementById("errorMessage").innerHTML = "Sign in successful!!" + return true; + } + } + else{ + document.getElementById("errorMessage").innerHTML = "Please do not keep blank Employee ID & Password" + return false; + } } From 2736282cb7d33fbe65ecf559b4666e02c3527257 Mon Sep 17 00:00:00 2001 From: ahw0010 <77364083+ahw0010@users.noreply.github.com> Date: Tue, 23 Feb 2021 13:07:24 -0600 Subject: [PATCH 12/29] Update signIn.html Defined sign-in view. --- src/main/resources/templates/signIn.html | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/resources/templates/signIn.html b/src/main/resources/templates/signIn.html index 601cafab..0459b0bd 100644 --- a/src/main/resources/templates/signIn.html +++ b/src/main/resources/templates/signIn.html @@ -11,9 +11,19 @@ - -
-

Sign In

+ + +

+
+
+

My GPA Needs An A

@@ -24,18 +34,26 @@

- + +

+
+ +

sign in

+
- + -
+
- +
+

+
+ From 52c2e3cc494df1a8d3f95332c4ea6fae9fc3a526 Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:30:29 -0600 Subject: [PATCH 13/29] Update productListing.html --- src/main/resources/templates/productListing.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index c4b758ae..a770b4c6 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -22,6 +22,9 @@

+ From 331ccd652acd872718c8635438cca1da00e7736d Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:32:36 -0600 Subject: [PATCH 14/29] Update productListing.html --- src/main/resources/templates/productListing.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index a770b4c6..c4b758ae 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -22,9 +22,6 @@

- From 7800b3453d15228d2b5c96106a1b459fcf974c5d Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:34:45 -0600 Subject: [PATCH 15/29] Update productListing.html --- src/main/resources/templates/productListing.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index c4b758ae..1593ed08 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -27,6 +27,10 @@



+ +
  • From e635942b25207ba70c2987b76fc4239d9161b72b Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:45:12 -0600 Subject: [PATCH 16/29] Update productListing.html --- src/main/resources/templates/productListing.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 1593ed08..1bb42be0 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -25,13 +25,14 @@

    - -

    +

    + +
    • From 0984b54b3cd8d142aaf5ced0365d5858eac9c5c4 Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:47:11 -0600 Subject: [PATCH 17/29] Update productListing.html --- src/main/resources/templates/productListing.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 1bb42be0..79b7ab8e 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -26,6 +26,7 @@

      Create New +

      From dbbeea03ec32e0caa9cf4c0c5b4a7e10e2125372 Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:49:48 -0600 Subject: [PATCH 18/29] Update productListing.html --- src/main/resources/templates/productListing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 79b7ab8e..a1e90d08 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -23,7 +23,7 @@



      From c1b5faa9cb7d6c6a21175ded2d8c7a8d1d73b27f Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:51:53 -0600 Subject: [PATCH 19/29] Update productListing.html --- src/main/resources/templates/productListing.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index a1e90d08..24ac9c66 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -23,12 +23,12 @@





      From 98f3cac1267c69b419a2c4bb1a50cd494bf97127 Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 02:25:23 -0600 Subject: [PATCH 20/29] Update productListing.html --- src/main/resources/templates/productListing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 24ac9c66..dbd7e63c 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -28,7 +28,7 @@





      From 31880c6de2da334f6739ecaa7e3fe0af2b01ac6e Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 02:51:53 -0600 Subject: [PATCH 21/29] Update productListing.html --- src/main/resources/templates/productListing.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index dbd7e63c..3e055627 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -28,8 +28,10 @@



      +
      + Sign Out

      From 496c5aeb67c053d124452f1996503754e7eabc16 Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 02:56:06 -0600 Subject: [PATCH 22/29] Update productListing.html --- src/main/resources/templates/productListing.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 3e055627..06eff4da 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -30,8 +30,9 @@

      +

      - Sign Out + Sign Out

      From ca84a389f68b0dbfff08916e2d39c9d81ee63d1f Mon Sep 17 00:00:00 2001 From: IsogaiYugo <41026474+IsogaiYugo@users.noreply.github.com> Date: Wed, 3 Mar 2021 01:26:28 +0900 Subject: [PATCH 23/29] Update mainMenu.html navigate another html files --- src/main/resources/templates/mainMenu.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/templates/mainMenu.html b/src/main/resources/templates/mainMenu.html index c1d637ea..7d1abb27 100644 --- a/src/main/resources/templates/mainMenu.html +++ b/src/main/resources/templates/mainMenu.html @@ -19,8 +19,8 @@

      Main Menu

      - - + View Products + Create Employee From b015590751d635a8e2834517028e3485f1badda5 Mon Sep 17 00:00:00 2001 From: creighton1199 <77364452+creighton1199@users.noreply.github.com> Date: Tue, 2 Mar 2021 10:36:11 -0600 Subject: [PATCH 24/29] Update productListing.html --- src/main/resources/templates/productListing.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 06eff4da..fe73240e 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -31,11 +31,8 @@

      Main Menu


      -
      - Sign Out - -

      +
      • @@ -63,6 +60,10 @@

      + + From c327f5faeb2e028f4496fda9bbd295c26ee7e27e Mon Sep 17 00:00:00 2001 From: ahw0010 <77364083+ahw0010@users.noreply.github.com> Date: Tue, 2 Mar 2021 16:59:34 -0600 Subject: [PATCH 25/29] Update SignInRestController.java adding user delete --- .../registerapp/controllers/SignInRestController.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java index 68133574..bf9758b1 100644 --- a/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java @@ -6,9 +6,11 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; import edu.uark.registerapp.controllers.enums.ViewNames; import edu.uark.registerapp.models.api.ApiResponse; +import edu.uark.registerapp.commands.activeUsers.ActiveUserDeleteCommand; @RestController @RequestMapping(value = "/api") @@ -18,9 +20,13 @@ public class SignInRestController extends BaseRestController { final HttpServletRequest request ) { - // TODO: Sign out the user associated with request.getSession().getId() + this.activeUserDeleteCommand + .setSessionKey(request.getSession().getId()) + .execute(); return (new ApiResponse()) .setRedirectUrl(ViewNames.SIGN_IN.getRoute()); } + @Autowired + private ActiveUserDeleteCommand activeUserDeleteCommand; } From 4ff43ce933bb2ed051f12ae14453e3dd187c3c02 Mon Sep 17 00:00:00 2001 From: ahw0010 <77364083+ahw0010@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:03:25 -0600 Subject: [PATCH 26/29] Create ActiveUserDeleteCommand.java created variation of user delete --- .../activeUsers/ActiveUserDeleteCommand.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java new file mode 100644 index 00000000..dcd7895c --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java @@ -0,0 +1,37 @@ +package edu.uark.registerapp.commands.activeUsers; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import edu.uark.registerapp.commands.VoidCommandInterface; +import edu.uark.registerapp.models.entities.ActiveUserEntity; +import edu.uark.registerapp.models.repositories.ActiveUserRepository; + +@Service +public class ActiveUserDeleteCommand implements VoidCommandInterface { + @Transactional + @Override + public void execute() { + final Optional activeUserEntity = + this.activeUserRepository.findBySessionKey(this.sessionKey); + + if (activeUserEntity.isPresent()) { + this.activeUserRepository.delete(activeUserEntity.get()); + } + } + + private String sessionKey; + public String getSessionKey() { + return this.sessionKey; + } + public ActiveUserDeleteCommand setSessionKey(final String sessionKey) { + this.sessionKey = sessionKey; + return this; + } + + @Autowired + private ActiveUserRepository activeUserRepository; +} From 48641feff816936ce468682508fa78828e312dee Mon Sep 17 00:00:00 2001 From: ahw0010 <77364083+ahw0010@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:12:02 -0600 Subject: [PATCH 27/29] Update SignInRestController.java --- .../uark/registerapp/controllers/SignInRestController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java index bf9758b1..c7694c61 100644 --- a/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java +++ b/src/main/java/edu/uark/registerapp/controllers/SignInRestController.java @@ -20,7 +20,7 @@ public class SignInRestController extends BaseRestController { final HttpServletRequest request ) { - this.activeUserDeleteCommand + this.deleteUserCommand .setSessionKey(request.getSession().getId()) .execute(); @@ -28,5 +28,5 @@ public class SignInRestController extends BaseRestController { .setRedirectUrl(ViewNames.SIGN_IN.getRoute()); } @Autowired - private ActiveUserDeleteCommand activeUserDeleteCommand; + private DeleteUserCommand deleteUserCommand; } From c213499b1398a2ef4f46f1c6297a93b4d4729154 Mon Sep 17 00:00:00 2001 From: ahw0010 <77364083+ahw0010@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:13:44 -0600 Subject: [PATCH 28/29] Update and rename ActiveUserDeleteCommand.java to DeleteUserCommand.java --- .../{ActiveUserDeleteCommand.java => DeleteUserCommand.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/java/edu/uark/registerapp/commands/activeUsers/{ActiveUserDeleteCommand.java => DeleteUserCommand.java} (86%) diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java similarity index 86% rename from src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java rename to src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java index dcd7895c..bde40ce7 100644 --- a/src/main/java/edu/uark/registerapp/commands/activeUsers/ActiveUserDeleteCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java @@ -11,7 +11,7 @@ import edu.uark.registerapp.models.repositories.ActiveUserRepository; @Service -public class ActiveUserDeleteCommand implements VoidCommandInterface { +public class DeleteUserCommand implements VoidCommandInterface { @Transactional @Override public void execute() { @@ -27,7 +27,7 @@ public void execute() { public String getSessionKey() { return this.sessionKey; } - public ActiveUserDeleteCommand setSessionKey(final String sessionKey) { + public DeleteUserCommand setSessionKey(final String sessionKey) { this.sessionKey = sessionKey; return this; } From 62d20b4fe00aa0a9d8105f077812e84870856a74 Mon Sep 17 00:00:00 2001 From: ahw0010 <77364083+ahw0010@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:21:09 -0600 Subject: [PATCH 29/29] Delete DeleteUserCommand.java --- .../activeUsers/DeleteUserCommand.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java diff --git a/src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java b/src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java deleted file mode 100644 index bde40ce7..00000000 --- a/src/main/java/edu/uark/registerapp/commands/activeUsers/DeleteUserCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package edu.uark.registerapp.commands.activeUsers; - -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import edu.uark.registerapp.commands.VoidCommandInterface; -import edu.uark.registerapp.models.entities.ActiveUserEntity; -import edu.uark.registerapp.models.repositories.ActiveUserRepository; - -@Service -public class DeleteUserCommand implements VoidCommandInterface { - @Transactional - @Override - public void execute() { - final Optional activeUserEntity = - this.activeUserRepository.findBySessionKey(this.sessionKey); - - if (activeUserEntity.isPresent()) { - this.activeUserRepository.delete(activeUserEntity.get()); - } - } - - private String sessionKey; - public String getSessionKey() { - return this.sessionKey; - } - public DeleteUserCommand setSessionKey(final String sessionKey) { - this.sessionKey = sessionKey; - return this; - } - - @Autowired - private ActiveUserRepository activeUserRepository; -}