Skip to content
Snippets Groups Projects
Commit d6a90b79 authored by Joshua Gill's avatar Joshua Gill
Browse files

Merge branch 'develop' into IssueSix

# Conflicts:
#	build.gradle
#	src/main/java/com/example/clientproject/config/SecurityConfig.java
#	src/main/java/com/example/clientproject/data/users/Users.java
#	src/main/java/com/example/clientproject/web/controllers/HomeController.java
#	src/main/java/com/example/clientproject/web/controllers/SignInController.java
#	src/main/resources/database/Data Script/script.sql
#	src/main/resources/templates/fragments/nav.html
parents 8262e536 eddcb12c
Branches IssueSix
No related tags found
4 merge requests!56tags will be saved to userFavTags table (needs user ID of current logged in user),!30merge,!24All Acceptance Criteria Met, password fields on "script.sql" and...,!23IssueSix complete
Showing
with 488 additions and 55 deletions
package com.example.clientproject.data.misc;
public class ShopTagLinkTable {
private int shopId;
private int tagId;
public ShopTagLinkTable(int shopId, int tagId){
this.shopId = shopId;
this.tagId = tagId;
}
}
......@@ -19,11 +19,13 @@ import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name="shops")
public class Shops {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String shopId;
private String shopName;
private String shopDescription;
private String shopWebsite;
private int shopEarnings;
private String shopImage;
......@@ -41,9 +43,10 @@ public class Shops {
* @param countries - shop countries
* @param active - shop active status
*/
public Shops(String name, String website, int earnings,
public Shops(String name, String website, String description, int earnings,
String image, String countries, boolean active) {
this.shopName = name;
this.shopDescription = description;
this.shopWebsite = website;
this.shopEarnings = earnings;
this.shopImage = image;
......
......@@ -15,7 +15,7 @@ public interface ShopsRepo extends JpaRepository<Shops, Long> {
* FindAll method
* @return list of Shops found
*/
List<Shops> findAll();
// List<Shops> findAll();
/**
* Save method
......
......@@ -23,6 +23,13 @@ public class Tags {
private long tagId;
private String tagName;
/**
*
*/
public Tags(String tagName){
this.tagName = tagName;
}
@ManyToMany(mappedBy="shopTags")
private List<Shops> relatedShops;
......
package com.example.clientproject.data.tags;
import com.example.clientproject.data.shops.Shops;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
......@@ -21,4 +23,7 @@ public interface TagsRepo extends JpaRepository<Tags, Long> {
* @return - the object
*/
Tags save(Tags tags);
@Query("select t.tagId from Tags t where t.tagId = (select max(t.tagId) from Tags t)")
int findMostRecent();
}
package com.example.clientproject.data.users;
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.data.userStampBoards.UserStampBoards;
import com.example.clientproject.services.TwoFactorAuthOBJ;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -28,7 +29,6 @@ public class Users {
private String userLastName;
private String userEmail;
private String userPassword;
// TODO - implement a random salt generator and extra field here
private String userProfilePicture;
private String userResetCode;
private String userResetCodeExpiry;
......@@ -71,7 +71,7 @@ public class Users {
@OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name="User_Id", nullable = false)
private Set<UserStampBoards> userStampBoards;
private Set<StampBoards> stampBoards;
@ManyToMany
@JoinTable(
......
package com.example.clientproject.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Base64;
import java.util.Random;
@Data
public class AccountRegister {
private String name;
private String surname;
private String email;
private String password;
@Override
public String toString(){
return this.getName() + ", " + this.getSurname() + ", " + this.getEmail() + ", " + this.getPassword();
}
public AccountRegister(String name, String surname, String email, String password){
this.name = name;
this.surname = surname;
this.email = email;
this.password = password;
}
public void setPassword(String password) {
final Random RANDOM = new SecureRandom();
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
byte[] salt = new byte[16];// credits to user "Assylias" https://stackoverflow.com/questions/18142745/how-do-i-generate-a-salt-in-java-for-salted-hash
RANDOM.nextBytes(salt);
String generatedSalt = Base64.getEncoder().encodeToString(salt);
//System.out.println(generatedSalt);
this.password = passwordEncoder.encode(password + generatedSalt);
//System.out.println(this.password);
}
}
package com.example.clientproject.services;
import com.example.clientproject.web.forms.BusinessRegisterForm;
import lombok.AllArgsConstructor;
import lombok.Value;
import java.util.ArrayList;
@Value
@AllArgsConstructor
public class BusinessRegisterDTO {
String business_register_url;
String business_register_name;
String business_register_desc;
//String businessCategory;
ArrayList<String> businessTags;
//String instagram;
//String facebook;
//String twitter;
//String tiktok;
int earnings;
public BusinessRegisterDTO(BusinessRegisterForm brf){
this(
brf.getBusiness_register_url(),
brf.getBusiness_register_name(),
brf.getBusiness_register_desc(),
//brf.getBusinessCategory(),
brf.getBusinessTags(),
//brf.getInstagram(),
//brf.getFacebook(),
//brf.getTwitter(),
//brf.getTiktok(),
brf.getEarnings()
);
}
}
package com.example.clientproject.services;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.tags.TagsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.util.List;
@Service
public class BusinessRegisterSaver {
@Autowired
ShopsRepo shopsRepo;
@Autowired
TagsRepo tagsRepo;
@Autowired
JdbcTemplate jdbc;
public void save(BusinessRegisterDTO business){
Shops shop = new Shops(business.getBusiness_register_name(),
business.getBusiness_register_url(),
business.getBusiness_register_desc(),
business.getEarnings(),
"shopPic.png",
"UK United Kingdom",
false);
shopsRepo.save(shop);
List<Tags> tagsList = tagsRepo.findAll();
for(String t: business.getBusinessTags()){
if(tagsList.contains(new Tags(t))){
// Link shop to tag
continue;
}
//long id = 0;
Tags tag = new Tags(t);
tagsRepo.save(tag);
String query = "INSERT INTO Shop_Tag_Links (Shop_Id, Tag_Id) VALUES ("+ shop.getShopId() +
","+tag.getTagId() + ")";
jdbc.execute(query);
}
System.out.println(shop.getShopId());
System.out.println(tagsRepo.findAll());
System.out.println(shopsRepo.findByShopName(business.getBusiness_register_name()));
}
}
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.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
public class newAccountDTO {
String name;
String surname;
String email;
String password;
public newAccountDTO(AccountRegister aAccount){
this(
aAccount.getName(),
aAccount.getSurname(),
aAccount.getEmail(),
aAccount.getPassword()
);
}
}
package com.example.clientproject.services;
public interface registerUserService{
public void save(newAccountDTO accountDTO);
}
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");
twoFactorMethodsRepo.save(twoFactorMethods);
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);
usersRepo.save(newUser);
System.out.println(usersRepo.findById(newUser.getUserId()));
}
}
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.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");
}
}
package com.example.clientproject.web.forms;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Arrays;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BusinessRegisterForm {
String business_register_url;
String business_register_name;
String business_register_desc;
String businessCategory;
ArrayList<String> businessTags;
String instagram;
String facebook;
String twitter;
String tiktok;
int earnings;
public void setTags(String tempTags){
this.businessTags = new ArrayList(Arrays.asList(tempTags.split(",")));
}
}
spring.thymeleaf.cache=false
spring.datasource.url=jdbc:mariadb://localhost:3306/mydb?useSSL=false&requireSSL=false&serverTimezone=UTC
#set credentials explicitly
spring.datasource.username=root
spring.datasource.password=comsc
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment