Skip to content
Snippets Groups Projects
Commit bbaaf1e7 authored by Ethan Allen-Harris's avatar Ethan Allen-Harris
Browse files

Changed SignUp method to use service, and started category selection after signup

parent 53d9cc94
No related branches found
No related tags found
4 merge requests!56tags will be saved to userFavTags table (needs user ID of current logged in user),!22Branch Update,!19created signUp page and form that sends data to controller,!17Removal of "AUTO_INCREMENT" on AdminTypes id field since there will only ever...
Showing with 254 additions and 0 deletions
package com.example.clientproject.services;
public class TwoFactorAuthOBJ {
private long twoFactorMethodId;
private String twoFactorMethodName;
public TwoFactorAuthOBJ(long id, String twoFA_name) {
}
}
package com.example.clientproject.services;
import com.example.clientproject.data.tags.Tags;
import org.springframework.stereotype.Service;
import java.util.List;
public interface getAllTagsService {
List<Tags> findAll();
}
\ No newline at end of file
package com.example.clientproject.services;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.tags.TagsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class getAllTagsServiceStatic implements getAllTagsService{
@Autowired
TagsRepo tagsRepo;
@Override
public List<Tags> findAll() {
return tagsRepo.findAll();
}
}
package com.example.clientproject.services;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethods;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethodsRepo;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.data.users.UsersRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Service
public class registerUserServiceStatic implements registerUserService{
@Autowired
UsersRepo usersRepo;
@Autowired
TwoFactorMethodsRepo twoFactorMethodsRepo;
public void save(newAccountDTO accountDTO){
long ID = 1;
TwoFactorMethods twoFactorMethods = new TwoFactorMethods();
twoFactorMethods.setTwoFactorMethodId(ID);
twoFactorMethods.setTwoFactorMethodName("None");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
Users newUser = new Users(accountDTO.getName(), accountDTO.getSurname(), accountDTO.getEmail(), accountDTO.getPassword(),
"", "",
LocalDateTime.now().format(formatter), twoFactorMethods);
Users users = usersRepo.save(newUser);
}
}
package com.example.clientproject.web.controllers.selectCategories;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.services.getAllTagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import java.awt.desktop.ScreenSleepEvent;
import java.util.List;
@Controller
public class selectCategoriesControllers {
private getAllTagsService getTagService;
@Autowired
public void getAllTagsController(getAllTagsService allTagsService) { getTagService = allTagsService;}
@PostMapping("/selectCategories")
public String selectCategories(){
return("selectCategories");
}
@GetMapping("/selectCategories")
public String selectCategories(Model model){
List<Tags> allTags = getTagService.findAll();
model.addAttribute("allTags", allTags);
for (Tags allTag : allTags) {
System.out.println(allTag);
}
System.out.println("Test");
return("selectCategories");
}
}
.MainText {
float: left;
width: 100%;
height: 12vh;
text-align: center;
color: white;
font-size: 45px;
font-weight: bold;
background: rgb(1,126,255);
background: linear-gradient(90deg, rgba(0,76,255,1) 0%, rgba(1,126,255,1) 100%);
}
.submit {
position: absolute;
background: rgb(1,126,255);
color: white !important;
width: 150px;
font-size: 15px;
margin: 10px;
background: transparent;
border-width: 2px;
border-color: white !important;
right: 20px;
top: 7px;
}
.submit:hover{
background: #0050ff;
}
.categoyContainer {
float: left;
display: flex;
flex-wrap: wrap;
}
.category-Button {
background: rgb(1,126,255);
color: white !important;
padding-left: 15px;
padding-right: 15px;
margin: 10px;
}
body {background-color: #ededed;}
const categoryID = 0;
function toggle_onclick(categoryID){
const selected = document.getElementById(categoryID);
const number = selected.value;
if (number == "0"){
selected.style.backgroundColor = 'green' ;
selected.value = 1;
} else {
selected.style.backgroundColor = 'rgb(1,126,255)' ;
selected.value = 0;
}
}
\ No newline at end of file
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="css/bulma.min.css">
<link rel="stylesheet" type="text/css" href="css/category.css">
<script src="/js/selectCategories.js"></script>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Categories</title>
</head>
<body>
<div class="MainText">Pick 3 categories or more
<img style="position: absolute; top: 20px; left: 20px;" src="imgs/Logo.png" width="112" height="28" class="logo">
</div>
<button class="button submit">Submit</button>
<div class="categoyContainer" th:with="mycounter = 0">
<button th:each="allTags : ${shopTags}" th:with="mycounter=${mycounter + 1}" onclick="toggle_onclick(${mycounter})" type="submit" id="${mycounter}" value="0" class="button is-rounded category-Button" th:text="${shopTags}"></button>
<!-- toggle_onclick("have server automatically pass ID here"), and also for id="" -->
<button type="submit" class="button is-rounded category-Button">Furniture</button>
<button type="submit" class="button is-rounded category-Button">Coffee</button>
<button type="submit" class="button is-rounded category-Button">Cooking</button>
<button type="submit" class="button is-rounded category-Button">Electronics</button>
<button type="submit" class="button is-rounded category-Button">Cars</button>
<button type="submit" class="button is-rounded category-Button">Clothing</button>
<tr th:each="charity : ${matches}">
<th scope="row">
<a th:id="@{charityLink{id} (id=${charity.id})}"
th:href="@{/charity/{id} (id=${charity.id})}">
<span th:text="${charity.name}"></span>
</a>
</th>
<td th:text="${charity.registrationNumber}"></td>
</tr>
</body>
</html>
package com.example.clientproject.data.users;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethods;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethodsRepo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@DataJpaTest
@Sql(scripts={"/schema-test-h2.sql","/script-test-h2.sql"})
@ActiveProfiles("h2")
@DirtiesContext
public class UsersTests {
@Autowired
UsersRepo usersRepo;
@Autowired
TwoFactorMethodsRepo twoFactorMethodsRepo;
@Test
public void shouldGet160Users() throws Exception {
List<Users> usersList = usersRepo.findAll();
assertEquals(160, usersList.size());
}
@Test
public void shouldGet161UsersAfterInsert() throws Exception {
TwoFactorMethods twoFactorMethods = twoFactorMethodsRepo.findByTwoFactorMethodId(1).get();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
Users newUser = new Users("", "", "", "",
"", "",
LocalDateTime.now().format(formatter), twoFactorMethods);
Users users = usersRepo.save(newUser);
List<Users> usersList = usersRepo.findAll();
assertEquals(161, usersList.size());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment