Skip to content
Snippets Groups Projects
Commit 53d9cc94 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 916f3f5d
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...
......@@ -25,6 +25,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
implementation 'org.projectlombok:lombok:1.18.20'
implementation 'org.projectlombok:lombok:1.18.20'
implementation 'org.projectlombok:lombok:1.18.20'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
......
......@@ -4,6 +4,7 @@ import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.stampBoards.StampBoards;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethods;
import com.example.clientproject.services.TwoFactorAuthOBJ;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......
......@@ -27,8 +27,6 @@ public class AccountRegister {
this.surname = surname;
this.email = email;
this.password = password;
}
public void setPassword(String password) {
......@@ -48,4 +46,5 @@ public class AccountRegister {
//System.out.println(this.password);
}
}
package com.example.clientproject.services;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethods;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.data.users.UsersRepo;
import com.example.clientproject.domain.AccountRegister;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.springframework.context.annotation.Bean;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethods;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethodsRepo;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Value
@AllArgsConstructor
......@@ -18,4 +27,6 @@ public class newAccountDTO {
aAccount.getPassword()
);
}
}
package com.example.clientproject.services;
public interface registerUserService{
public void save(newAccountDTO accountDTO);
}
package com.example.clientproject.web.controllers.SignUp;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethodsRepo;
import com.example.clientproject.data.twoFactorMethods.TwoFactorMethods;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.data.users.UsersRepo;
import com.example.clientproject.domain.AccountRegister;
import com.example.clientproject.services.newAccountDTO;
import com.example.clientproject.services.registerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
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 org.springframework.web.bind.annotation.RequestMapping;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Controller
public class SignUpController {
private registerUserService regUserService;
@Autowired
public SignUpController(registerUserService rService) {
regUserService = rService;
}
@PostMapping("/signup")
public String signUp(Model model, AccountRegister accountRegister) {
newAccountDTO newAccountDTO1 = new newAccountDTO(accountRegister.getName(), accountRegister.getSurname(), accountRegister.getEmail(), accountRegister.getPassword());
//System.out.println(accountRegister.getEmail());
//System.out.println(accountRegister.getPassword());
//DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//TwoFactorMethods twoFactorMethods = twoFactorMethodsRepo.findByTwoFactorMethodId(1).get();
//Users newUser = new Users(accountRegister.getName(), accountRegister.getSurname(), accountRegister.getEmail(), accountRegister.getPassword(),
//"", "",
//LocalDateTime.now().format(formatter), twoFactorMethods);
//usersRepo.save(newUser);
regUserService.save(newAccountDTO1);
return "signup";
}
@GetMapping("/signup")
public String signupGet(Model model){
return "signup";
}
}
\ No newline at end of file
package com.example.clientproject.web.controllers;
import com.example.clientproject.domain.AccountRegister;
import com.example.clientproject.services.newAccountDTO;
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 org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SignUpController {
@PostMapping("/signup")
public String signUp(Model model, AccountRegister accountRegister) {
//newAccountDTO newAccountDTO1 = new newAccountDTO(accountRegister.getName(), accountRegister.getSurname(), accountRegister.getEmail(), accountRegister.getPassword());
//System.out.println(accountRegister.getEmail());
System.out.println(accountRegister.getPassword());
return "signUp";
}
@GetMapping("/signup")
public String signupGet(Model model){
return "signup";
}
}
......@@ -85,7 +85,7 @@ h2 {
.loginUp-Button {
margin: 10px;
background-color: transparent;
border-color: white
border-color: white;
color: white !important;
width: 140px;
border-width: 2px;
......
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