diff --git a/src/main/java/com/example/clientproject/service/Utils/CheckUserOwner.java b/src/main/java/com/example/clientproject/service/Utils/CheckUserOwner.java new file mode 100644 index 0000000000000000000000000000000000000000..82b55bc53e6db5bdd69901a53ee918a959a471b1 --- /dev/null +++ b/src/main/java/com/example/clientproject/service/Utils/CheckUserOwner.java @@ -0,0 +1,28 @@ +package com.example.clientproject.service.Utils; + +import com.example.clientproject.data.shops.Shops; +import com.example.clientproject.data.userPermissions.UserPermissions; +import com.example.clientproject.data.userPermissions.UserPermissionsRepo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class CheckUserOwner { + + @Autowired + UserPermissionsRepo permissionsRepo; + + public boolean checkOwner(int userId, int shopId){ + List<UserPermissions> permissions = permissionsRepo.findByShopID(shopId); + + for(UserPermissions u:permissions){ + if(u.getUser().getUserId() == userId){ + if(u.getAdminType().getAdminTypeId() == 2){ + return true; + } + } + }return false; + } +} diff --git a/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java b/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java index 45ab5ef3f0487eb8de8b9ac09fe6de79ed2ada12..e2c5606b441a2d7b62132fd991873cdd6f07599f 100644 --- a/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java +++ b/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java @@ -98,7 +98,7 @@ public class BusinessRegisterSaver { if(tagsLowerList.contains(t.toLowerCase())){ tag = tagsRepo.findByTagNameIgnoreCase(t).get(); }else{ - tag = new Tags(t); + tag = new Tags(t.toLowerCase()); tagsRepo.save(tag); } diff --git a/src/main/java/com/example/clientproject/services/UserLinked.java b/src/main/java/com/example/clientproject/services/UserLinked.java index ce19265921e8a724490618555b9801343c109b43..173162d5e8e083c6aea22b5f48c0da8b7a1709ac 100644 --- a/src/main/java/com/example/clientproject/services/UserLinked.java +++ b/src/main/java/com/example/clientproject/services/UserLinked.java @@ -30,4 +30,22 @@ public class UserLinked { } } return false; } + + public boolean isAnyAdmin(int userId){ + List<UserPermissions> allLinks = userPermRepo.findByUserId(userId); + for(UserPermissions u:allLinks){ + if(u.getAdminType().getAdminTypeId() == 2){ + return true; + } + }return false; + } + + public int userAdminShopId(int userId){ + List<UserPermissions> allLinks = userPermRepo.findByUserId(userId); + for(UserPermissions u:allLinks){ + if(u.getAdminType().getAdminTypeId() == 2){ + return (int) u.getShop().getShopId(); + } + }return 0; + } } diff --git a/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java b/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java index e1e203a73d734b0974d6d04ef2b548d335dc7264..57c894bd27d8a2fb0e0ca531bbea90f316a76a9b 100644 --- a/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java +++ b/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java @@ -6,6 +6,7 @@ import com.example.clientproject.data.socials.Socials; import com.example.clientproject.data.socials.SocialsRepo; import com.example.clientproject.data.stampBoards.StampBoards; import com.example.clientproject.data.stampBoards.StampBoardsRepo; +import com.example.clientproject.data.tags.Tags; import com.example.clientproject.data.userPermissions.UserPermissions; import com.example.clientproject.data.userPermissions.UserPermissionsRepo; import com.example.clientproject.data.userStampBoards.UserStampBoards; @@ -110,9 +111,18 @@ public class BusinessDetails { UserStampPosOBJ.add(UserStampPos); model.addAttribute("UserStampPos", UserStampPosOBJ); + String tags = "Tags: "; + for(int i=0; i<shop.getShopTags().size(); i++){ + if(i != shop.getShopTags().size()-1){ + tags+=shop.getShopTags().get(i).getTagName() + ", "; + }else{ + tags += shop.getShopTags().get(i).getTagName(); + } + } //model.addAttribute("stampBoard", stampBoard); model.addAttribute("loggedInUser", user.get()); + model.addAttribute("tags", tags); model.addAttribute("shop", shop); model.addAttribute("stampBoard", stampBoard); return "shopDetails.html"; diff --git a/src/main/java/com/example/clientproject/web/controllers/signUpAndIn/SignInController.java b/src/main/java/com/example/clientproject/web/controllers/signUpAndIn/SignInController.java index 2f482b51a6c142ebf6c3b72220f4d9f0e31d52a0..fa58652817475e596f294d23e5cb7f2066d0854c 100644 --- a/src/main/java/com/example/clientproject/web/controllers/signUpAndIn/SignInController.java +++ b/src/main/java/com/example/clientproject/web/controllers/signUpAndIn/SignInController.java @@ -11,6 +11,7 @@ import com.example.clientproject.service.dtos.UsersDTO; import com.example.clientproject.service.searches.UsersSearch; import com.example.clientproject.services.BusinessRegisterDTO; import com.example.clientproject.services.BusinessRegisterSaver; +import com.example.clientproject.services.UserLinked; import com.example.clientproject.services.UserShopLinked; import com.example.clientproject.web.forms.BusinessRegisterForm; import com.example.clientproject.web.forms.signUpAndIn.LoginForm; @@ -35,20 +36,20 @@ public class SignInController { private JWTUtils jwtUtils; - private UserShopLinked userShopLinked; + private UserLinked userLinked; private UserPermissionsRepo userPermissionsRepo; private CategoriesRepo catRepo; public SignInController(UsersSearch aUsersSearch, BusinessRegisterSaver sBusiness, JWTUtils ajwtUtils, - UserShopLinked aUserShopLinked, + UserLinked aUserShopLinked, UserPermissionsRepo aUserPermissionsRepo, CategoriesRepo aCatRepo) { usersSearch = aUsersSearch; saveBusiness = sBusiness; jwtUtils = ajwtUtils; - userShopLinked = aUserShopLinked; + userLinked = aUserShopLinked; userPermissionsRepo = aUserPermissionsRepo; catRepo = aCatRepo; } @@ -72,13 +73,11 @@ public class SignInController { } //System.out.println(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get())); - if(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get())){ - long userId = jwtUtils.getLoggedInUserId(session).get(); - long shopId = userPermissionsRepo.findByUserId(userId).get(0).getShop().getShopId(); - if(shopId == 1){ - shopId = userPermissionsRepo.findByUserId(userId).get(1).getShop().getShopId(); - } - return "redirect:/businessDetails?shopId="+shopId; + if(userLinked.isAnyAdmin(jwtUtils.getLoggedInUserId(session).get())){ + + int shopId = userLinked.userAdminShopId(jwtUtils.getLoggedInUserId(session).get()); + + return "redirect:/redirect?url=businessDetails?shopId="+shopId; } List<Categories> categories = catRepo.findAll(); model.addAttribute("loggedInUser", user.get()); diff --git a/src/main/resources/static/css/manageStaff.css b/src/main/resources/static/css/manageStaff.css index 74dbe05aa3290d2348ebb4f399726d99902aa6b2..4f8d804218c2b86d44950e1860c2ffd483c8aef4 100644 --- a/src/main/resources/static/css/manageStaff.css +++ b/src/main/resources/static/css/manageStaff.css @@ -11,3 +11,7 @@ justify-content: space-between; align-items: center; } + +.staffManagementContainer:last-child{ + border-bottom: none!important; +} diff --git a/src/main/resources/static/js/manageStaff.js b/src/main/resources/static/js/manageStaff.js index 2a77b998b425970f6312dcad9f8f9dbf1695a301..a4ec17bbdcb828a4ebace7f9221d05f849cf5cb7 100644 --- a/src/main/resources/static/js/manageStaff.js +++ b/src/main/resources/static/js/manageStaff.js @@ -3,25 +3,29 @@ function submit(shopId, email={"value":""}){ if(email.parentElement.children[0].classList.contains("subtitle")){ emailValue = email.parentElement.children[0].innerHTML - email.parentElement.parentElement.remove() }else{ emailValue = email.parentElement.children[0].value - document.getElementById("staffManagement").innerHTML+= - `<div id="staffManagement"> - <div class="staffManagementContainer"> - <p class="subtitle is-6" style="width:50%; margin-bottom: 0">${emailValue}</p> - <button class="button is-danger is-outlined" style="border-bottom: 1px solid black" - onclick="submit(${document.getElementById("shopId").value},this);"> - <span class="icon is-small"> - <i class="fas fa-times is-danger"></i> - </span> - </button> - </div> - <p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid #00b89c; margin-bottom:1%; width:50%"></p> - </div>` + emailArray = [] + + document.getElementsByName("staffEmail").forEach(x => emailArray.push(x.innerHTML)) + + console.log(emailArray) + + if(emailArray.includes(emailValue)){ + document.getElementById("emailErrorField").innerHTML = "User already added" + return + } + } + + if(emailValue == ""){ + document.getElementById("emailErrorField").innerHTML = "Field blank" + return } + document.getElementById("emailErrorField").innerHTML = "" + + let params = "shopId="+ shopId if(emailValue=="") { params += "&email=" + document.getElementById("emailAddress").value @@ -33,7 +37,27 @@ function submit(shopId, email={"value":""}){ xhttp.onload = function() { if (xhttp.readyState === 4 && xhttp.status === 200) { var response = xhttp.responseText - if (response == "success"){ + if (response == "OK" || response == "USER REMOVED"){ + + if(email.parentElement.children[0].classList.contains("subtitle")){ + email.parentElement.parentElement.remove() + + }else{ + document.getElementById("staffManagement").innerHTML+= + `<div id="staffManagement"> + <div class="staffManagementContainer"> + <p class="subtitle is-6 staffEmail" name="staffEmail" style="width:80%; margin-bottom: 0">${emailValue}</p> + <button class="button is-danger is-outlined" style="border-bottom: 1px solid" + onclick="submit(${document.getElementById("shopId").value},this);"> + <span class="icon is-small"> + <i class="fas fa-times is-danger"></i> + </span> + </button> + </div> + <p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid; margin-bottom:1%; width:50%"></p> + </div>` + } + }else{ } } else { diff --git a/src/main/resources/static/js/registerbusiness.js b/src/main/resources/static/js/registerbusiness.js index e551c7f1a232086ff34b9067b732d17891a7b67e..0b91aa604650c89d43a498e9837b578fee5ed5a8 100644 --- a/src/main/resources/static/js/registerbusiness.js +++ b/src/main/resources/static/js/registerbusiness.js @@ -1,6 +1,15 @@ var modalStage = 0 var urlInput, urlPrefixInput, nameInput, descInput, tagsInput, amountInput = null; +function keyPress(e) { + if(e.key == "Enter"){ + e.preventDefault() + progress() + }if(e.key == "Tab"){ + e.preventDefault() + } +} + function htmlDecode(input) { var doc = new DOMParser().parseFromString(input, "text/html"); return doc.documentElement.textContent; @@ -133,6 +142,11 @@ function progress(){ url.value = document.getElementById("business_register_url_prefix").value + url.value; document.getElementById("businessTags").value = tags; + if(!/^([0-9]+)$/.test(document.getElementById("earnings").value)){ + document.getElementById("business_register_amount_help") + .innerHTML = "Please enter a whole number" + return + } document.getElementById("businessForm").submit(); } @@ -200,6 +214,13 @@ function addTag(e){ if(e.data=="," && tags.length != 20){ let inputField = document.forms["businessForm"]["businessTagsInput"] let text = inputField.value.slice(0,-1); + if(text == ""){ + document.getElementById("tagsHelp").innerHTML = "Tag cannot be blank" + document.getElementById("businessTagsInput").value = "" + return + }else{ + document.getElementById("tagsHelp").innerHTML = "" + } document.getElementById("bulmaTags").innerHTML += ` <div> <div class="control mr-3 mb-2"> @@ -230,6 +251,7 @@ function addTag(e){ inputField.value = "" } } + function removeTag(e){ let text = e.parentElement.children[0].innerHTML tags = tags.filter(tag =>{return tag!=text}); diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html index f82f93e1b05fe64f8846d73b15d8c442d17cdbb1..cfc658cfbe0a3986cbf7a6114559e9eea3f1bd64 100644 --- a/src/main/resources/templates/admin.html +++ b/src/main/resources/templates/admin.html @@ -73,7 +73,7 @@ <div th:replace="fragments/businessInformation :: keyInformation"></div> <div th:replace="fragments/userSocials.html :: userSocial"/> <br> - <th:block th:if="${highestShopLevel>=2}"> + <th:block th:if="${@checkUserOwner.checkOwner(loggedInUser.userId, shop.shopId)}"> <div th:replace="fragments/manageStaff.html :: manageStaffMembers"/> <div th:replace="fragments/deleteShop.html :: deleteShop"/> <div th:replace="fragments/toggleShop.html :: toggleShop"/> diff --git a/src/main/resources/templates/allUserShops.html b/src/main/resources/templates/allUserShops.html index 1599d6292ec0814e922229e3dfe3ab0f20f58073..4aa3e36090eb859ad63586853618673af77eb3f2 100644 --- a/src/main/resources/templates/allUserShops.html +++ b/src/main/resources/templates/allUserShops.html @@ -49,6 +49,8 @@ total_reward_amount=${shop.getStampBoard.getRewards.size}, img_path=${shop.shopImage}, shopId=${shop.shopId}"></div> + <h1 class="subtitle is-5" th:if="${favouriteShops.size == 0 && activeShops.size == 0}"> Looks like you don't have any stamps yet, favourite a shop or make a purchase to start collecting!</h1> + </div> diff --git a/src/main/resources/templates/fragments/businessInformation.html b/src/main/resources/templates/fragments/businessInformation.html index 45b6b7e73aec8433748d584df8e14cd405c8b080..fdf28559eeea01896ca76afa83822ead06f9c7b7 100644 --- a/src/main/resources/templates/fragments/businessInformation.html +++ b/src/main/resources/templates/fragments/businessInformation.html @@ -4,14 +4,14 @@ <script th:fragment="infoJs" src="js/businessInformation.js"></script> </head> <body th:fragment="keyInformation"> -<div style="border-bottom: #000000 1px solid; width:50%"> +<div style="width:50%"> <h6 class="title is-6" style="margin-top: 5px; margin-bottom: 25px">Key Information</h6> <p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Shop Name</p> <input type="text" th:value="${shop.shopName}" id="nameInput" class="input"> <p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Description</p> - <textarea class="textarea" id="descriptionInput" th:text="${shop.shopDescription}" cols="30" rows="10"></textarea> + <textarea class="textarea" id="descriptionInput" maxlength="250" th:text="${shop.shopDescription}" cols="30" rows="10"></textarea> <p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Banner</p> <img class="mb-3" id="bannerPreview" th:src="${shop.shopBanner}" style="margin-top: 5px; max-height: 100px"> @@ -49,5 +49,6 @@ <button th:onclick="'submitInfo('+ ${shop.shopId} +');'" class="button is-link" style="margin-top:15px; margin-bottom:10px;">Save changes</button> </div> +<p style="border-bottom: #000000 1px solid;"></p> </body> </html> \ No newline at end of file diff --git a/src/main/resources/templates/fragments/manageStaff.html b/src/main/resources/templates/fragments/manageStaff.html index 0599fb1818ee77a18039dee1eefc65b1ce3171f0..e9afec56ef5d9cf4ecb626e14e68c0c22fec491e 100644 --- a/src/main/resources/templates/fragments/manageStaff.html +++ b/src/main/resources/templates/fragments/manageStaff.html @@ -17,18 +17,18 @@ </span> </button> </div> + <p class="help is-danger" id="emailErrorField"></p> <p><br>Current Admins</p> <div id="staffManagement"></div> <div id="staffManagement" th:each="user : ${staffMembers}"> - <div class="staffManagementContainer"> - <p class="subtitle is-6" th:text="${user.userEmail}" style="width:50%; margin-bottom: 0"></p> - <button class="button is-danger is-outlined" style="border-bottom: 1px solid black" th:onclick="'submit('+${shop.shopId}+',this);'"> + <div class="staffManagementContainer" style="margin-bottom:1%;"> + <p class="subtitle is-6 staffEmail" name="staffEmail" th:text="${user.userEmail}" style="width:80%; margin-bottom: 0"></p> + <button class="button is-danger is-outlined" th:onclick="'submit('+${shop.shopId}+',this);'"> <span class="icon is-small"> <i class="fas fa-times is-danger"></i> </span> </button> </div> - <p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid #00b89c; margin-bottom:1%; width:50%"> </p> </div> <input id="shopId" class="input is-hidden" th:value="${shop.shopId}"> diff --git a/src/main/resources/templates/fragments/userSocials.html b/src/main/resources/templates/fragments/userSocials.html index 029ab41d47126b88418400337d7b505ae0912166..4a9c7beb86b5a0d11afbdb5feeed74c9f57aeade 100644 --- a/src/main/resources/templates/fragments/userSocials.html +++ b/src/main/resources/templates/fragments/userSocials.html @@ -81,7 +81,7 @@ </div> <button class="button is-link" style="margin-top: 5px" th:onclick="'send('+${shop.shopId}+');'">Save changes</button> </div> -<p style="border-bottom: 1px solid #00b89c;"><br></p> +<p style="border-bottom: 1px solid;"><br></p> </body> diff --git a/src/main/resources/templates/registerbusiness.html b/src/main/resources/templates/registerbusiness.html index 7e1d3c06368645cc557801a2432f988412160d14..13fe590dbd10e697f1e1cc247af21f86b255b8a1 100644 --- a/src/main/resources/templates/registerbusiness.html +++ b/src/main/resources/templates/registerbusiness.html @@ -28,7 +28,7 @@ <div id="progressBar" class="progressBar"> <div style="width:20%"></div> </div> - <form name="businessForm" id="businessForm" action="/businessRegister" th:method="post" onsubmit="return false"> + <form onkeydown="keyPress(event)" name="businessForm" id="businessForm" action="/businessRegister" th:method="post" onsubmit="return false"> <section class="modal-card-body url-centering" id="modal_container"> <div id="modal_page1" class="modal_page"> <h5 class="title is-5" style="text-align:center">Enter your shop URL</h5> @@ -75,10 +75,16 @@ </div> </div> <h5 class="title is-5 mt-2" style="text-align:center; margin-bottom: 2%">Add tags that describe your business</h5> - <div class="is-flex is-justify-content-center" style="width:100%;"> + <p class="subtitle is-6 mt-1" style="text-align: center">Press comma after typing the tag</p> + <div class="is-flex is-justify-content-center"> <!-- Need to fix this, shouldn't be full width of modal --> - <input id="businessTagsInput" maxlength="50" style="width:75%;" class="input" oninput="addTag(event)"></input> + <div class="is-flex is-flex-direction-column is-justify-content-center is-align-content-center" + style="width:75%"> + <input id="businessTagsInput" maxlength="50" class="input" oninput="addTag(event)"></input> + <p class="help is-danger" style="text-align: center" id="tagsHelp"></p> + </div> <input hidden name="businessTags" id="businessTags"/> + </div> <div class = "field is-grouped is-grouped-multiline p-4" id="bulmaTags"> <div id="tagCount" style="display: none" class="mr-3"> diff --git a/src/main/resources/templates/shopDetails.html b/src/main/resources/templates/shopDetails.html index 18882f8fa9592f9d7258f761adc0e0688a38a90f..19c9fe0c8f7085081f7141f981840b6ffd31bfab 100644 --- a/src/main/resources/templates/shopDetails.html +++ b/src/main/resources/templates/shopDetails.html @@ -119,6 +119,7 @@ </div> </div> <div class="content" style="margin-left: 1rem" th:text="${shop.shopDescription}"></div> + <div style="margin-left: 1rem" th:text="${tags}"></div> <footer class="card-footer"> <a th:href="${shop.shopWebsite}"><p class="card-footer-item websiteLinkText">Click for website<a></a> </footer>