Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.passay</groupId>
<artifactId>passay</artifactId>
Expand All @@ -73,6 +78,16 @@
<artifactId>openpdf</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.6.2.Final</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.edu.egg.virtual_wallet.controller;

import com.edu.egg.virtual_wallet.entity.Account;
import com.edu.egg.virtual_wallet.entity.Customer;
import com.edu.egg.virtual_wallet.enums.CurrencyType;
import com.edu.egg.virtual_wallet.exception.InputException;
import com.edu.egg.virtual_wallet.service.AccountService;
Expand All @@ -22,8 +21,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;
import org.springframework.stereotype.Controller;

@RestController
@Controller
@RequestMapping("/account")
public class AccountController {

Expand Down Expand Up @@ -94,7 +94,6 @@ public RedirectView active(@PathVariable Long id) {

}


//COSAS DE DANI

@GetMapping("info/{id}") // para enviar a back DANIEL MOSTRAR FICHA DE CUENTA
Expand All @@ -113,7 +112,6 @@ public ModelAndView showAccountInfo(@PathVariable Long id, HttpServletRequest re
return mav;
}


@PostMapping("/saveAlias")
public RedirectView saveAliasChanges(@ModelAttribute("account") Account account, RedirectAttributes attributes) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
package com.edu.egg.virtual_wallet.controller;

import com.edu.egg.virtual_wallet.entity.Login;

import com.edu.egg.virtual_wallet.exception.InputException;
import com.edu.egg.virtual_wallet.entity.*;
import com.edu.egg.virtual_wallet.security.MyAuthenticationSuccessHandler;
import com.edu.egg.virtual_wallet.service.CustomerService;
import com.edu.egg.virtual_wallet.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.security.Principal;
import java.util.Map;

@Controller
public class AuthenticationController {

@Autowired
private LoginService loginService;

@Autowired
private CustomerService customerService;

@GetMapping("/login")
public ModelAndView login(@RequestParam(required = false) String error, @RequestParam(required = false) String logout,
Principal principal, HttpSession session) throws InputException {
Principal principal, HttpSession session, Authentication authentication) {

ModelAndView modelAndView = new ModelAndView("login");

// Integer idCustomer = customerService.findSessionIdCustomer((Integer) session.getAttribute("id"));
Expand All @@ -36,11 +48,55 @@ public ModelAndView login(@RequestParam(required = false) String error, @Request
}

if (principal != null) {
modelAndView.setViewName("redirect:/myDashboard"); // Redirect to Customers profile
MyAuthenticationSuccessHandler redirectURL = new MyAuthenticationSuccessHandler();
modelAndView.setViewName("redirect:" + redirectURL.determineTargetUrl(authentication)); // Redirect to Customers profile
}

return modelAndView;
}

@GetMapping("/register")
public ModelAndView register(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("signup");

Map<String, ?> flashMap = RequestContextUtils.getInputFlashMap(request);

if(flashMap != null){
mav.addObject("error", flashMap.get("error"));

mav.addObject("customer", flashMap.get("customer"));
mav.addObject("address", flashMap.get("address"));
mav.addObject("contact", flashMap.get("contact"));
mav.addObject("name", flashMap.get("name"));
mav.addObject("login", flashMap.get("login"));
}else{
mav.addObject("customer", new Customer());
mav.addObject("address", new Address());
mav.addObject("contact", new Contact());
mav.addObject("name", new Name());
mav.addObject("login", new Login());
}

return mav;
}

@PostMapping("/register/check")
public RedirectView checkRegistration(@ModelAttribute("customer") Customer customer, @ModelAttribute("address") Address address,
@ModelAttribute("contact") Contact contact, @ModelAttribute("name") Name name,
@ModelAttribute("login") Login login, RedirectAttributes attributes) {
try {
customerService.createCustomer(customer, address, contact, name, login);

return new RedirectView("/login");

} catch(Exception e){
attributes.addFlashAttribute("error",e.getMessage());
attributes.addFlashAttribute("customer",customer);
attributes.addFlashAttribute("address",address);
attributes.addFlashAttribute("contact",contact);
attributes.addFlashAttribute("name",name);
attributes.addFlashAttribute("login",login);

return new RedirectView("/register");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.edu.egg.virtual_wallet.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CryptoAPIController {

@GetMapping("/cryptoAPI") // Preguntar a dani
public ModelAndView crypto (){
ModelAndView mav = new ModelAndView("cryptocurrency-quotes");
return mav;
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
package com.edu.egg.virtual_wallet.controller;



import com.edu.egg.virtual_wallet.enums.CurrencyType;
import com.edu.egg.virtual_wallet.exception.InputException;

import com.edu.egg.virtual_wallet.entity.*;
import com.edu.egg.virtual_wallet.repository.CustomerRepo;

import com.edu.egg.virtual_wallet.entity.*;
import com.edu.egg.virtual_wallet.exception.InputException;

import com.edu.egg.virtual_wallet.service.AccountService;
import com.edu.egg.virtual_wallet.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/myDashboard")
@PreAuthorize("hasRole('CUSTOMER')")
public class CustomerController {

@Autowired
Expand All @@ -37,88 +25,48 @@ public class CustomerController {
@Autowired
private AccountService accountService;

@GetMapping("/register")
public ModelAndView register(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("signup");
Map<String, ?> flashMap = RequestContextUtils.getInputFlashMap(request);

if(flashMap != null){
mav.addObject("error", flashMap.get("error"));

mav.addObject("customer", flashMap.get("customer"));
mav.addObject("address", flashMap.get("address"));
mav.addObject("contact", flashMap.get("contact"));
mav.addObject("name", flashMap.get("name"));
mav.addObject("login", flashMap.get("login"));
}else{
mav.addObject("customer", new Customer());
mav.addObject("address", new Address());
mav.addObject("contact", new Contact());
mav.addObject("name", new Name());
mav.addObject("login", new Login());
}

return mav;
}

@PostMapping("/register/check")
public RedirectView checkRegistration(@ModelAttribute("customer") Customer customer, @ModelAttribute("address") Address address,
@ModelAttribute("contact") Contact contact, @ModelAttribute("name") Name name,
@ModelAttribute("login") Login login, RedirectAttributes attributes) throws InputException {
try{
customerService.createCustomer(customer, address, contact, name, login);
return new RedirectView("/login");
}catch(Exception e){
attributes.addFlashAttribute("error",e.getMessage());
attributes.addFlashAttribute("customer",customer);
attributes.addFlashAttribute("address",address);
attributes.addFlashAttribute("contact",contact);
attributes.addFlashAttribute("name",name);
attributes.addFlashAttribute("login",login);
return new RedirectView("/register");
}

}

@GetMapping("/help")
public ModelAndView help(){
ModelAndView mav = new ModelAndView("help-center");
return mav;
}

@GetMapping("/myDashboard")
@GetMapping
public ModelAndView customerDashboard(HttpSession session) throws InputException {
ModelAndView mav = new ModelAndView("dashboard");

Integer idCustomer = customerService.findSessionIdCustomer((Integer) session.getAttribute("id"));
mav.addObject("accountPeso", accountService.findByCustomerIdCurrency(idCustomer, CurrencyType.PESO_ARG));
mav.addObject("accountDollar", accountService.findByCustomerIdCurrency(idCustomer, CurrencyType.DOLLAR));
mav.addObject("username", session.getAttribute("username"));
return mav;
}

@GetMapping("/profile")
public ModelAndView customerProfile(HttpSession session) throws InputException {

ModelAndView mav = new ModelAndView("editCustomerProfile");

Integer idCustomer = customerService.findSessionIdCustomer((Integer) session.getAttribute("id"));
Customer customer = customerService.returnCustomer(idCustomer);

mav.addObject("postPath", "/myDashboard/profile/edit");
mav.addObject("customer", customer);
mav.addObject("address", customer.getAddressInfo());
mav.addObject("contact", customer.getContactInfo());
mav.addObject("name", customer.getFullName());
mav.addObject("username", customer.getLoginInfo().getUsername());
mav.addObject("login", customer.getLoginInfo());
//mav.addObject("defaultDashboardPath", "/myDashboard");

return mav;
}

@PostMapping("/profile/edit")
public RedirectView editCustomerProfile(@ModelAttribute Customer customer, @ModelAttribute Address address,
@ModelAttribute("contact") Contact contact, @ModelAttribute("name") Name name,
@RequestParam String username, HttpSession session)
throws InputException{
@ModelAttribute("login") Login login, HttpSession session) throws InputException {

Integer idCustomer = customerService.findSessionIdCustomer((Integer) session.getAttribute("id"));
customerService.editCustomer(customer, idCustomer, address, contact, name, username);
customerService.editCustomer(customer, idCustomer, address, contact, name, login.getUsername());
return new RedirectView("/myDashboard");
}

Expand All @@ -134,20 +82,27 @@ public RedirectView deleteAccount(HttpSession session) throws InputException {
public ModelAndView changePassword() {
ModelAndView mav = new ModelAndView("changePassword");

mav.addObject("postPath", "/profile/changePassword/check");
mav.addObject("postPath", "/myDashboard/profile/changePassword/check");
mav.addObject("currentPassword", "");
mav.addObject("newPassword", "");
mav.addObject("confirmNewPassword", "");
mav.addObject("defaultDashboardPath", "/myDashboard");

return mav;
}

@PostMapping("/profile/changePassword/check")
public RedirectView verifyChangedPassword(@RequestParam String currentPassword, @RequestParam String newPassword,
@RequestParam String confirmNewPassword, HttpSession session)
throws InputException {
@RequestParam String confirmNewPassword, HttpSession session) throws InputException {

Integer idCustomer = customerService.findSessionIdCustomer((Integer) session.getAttribute("id"));
customerService.editCustomerPassword(idCustomer, currentPassword, newPassword, confirmNewPassword);
return new RedirectView("/profile");
return new RedirectView("/myDashboard/profile");
}

@GetMapping("/cryptoAPI") // Preguntar a dani
public ModelAndView crypto () {
ModelAndView mav = new ModelAndView("cryptocurrency-quotes");
return mav;
}
}
Loading