implement change User Settings
This commit is contained in:
		@ -1,7 +0,0 @@
 | 
			
		||||
package org.hso.ecommerce.action.user;
 | 
			
		||||
 | 
			
		||||
import org.hso.ecommerce.entities.user.User;
 | 
			
		||||
 | 
			
		||||
public class ChangeUserAction {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,77 @@
 | 
			
		||||
package org.hso.ecommerce.action.user;
 | 
			
		||||
 | 
			
		||||
import com.sun.xml.bind.v2.TODO;
 | 
			
		||||
import org.hso.ecommerce.entities.user.User;
 | 
			
		||||
import org.hso.ecommerce.repos.user.UserRepository;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
 | 
			
		||||
public class UpdateUserSettingsAction {
 | 
			
		||||
 | 
			
		||||
    private User user;
 | 
			
		||||
    private UserRepository repository;
 | 
			
		||||
 | 
			
		||||
    public UpdateUserSettingsAction(User user, UserRepository repository){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.repository = repository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateEmail(String newMail){
 | 
			
		||||
        if(newMail.equals("")){
 | 
			
		||||
            //TODO: Errorhandling
 | 
			
		||||
        }else{
 | 
			
		||||
            this.user.email = newMail;
 | 
			
		||||
            this.repository.save(this.user); //TODO: Errorhandling
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updatePassword(String oldPassword, String password1, String password2){
 | 
			
		||||
        if(this.user.validatePassword(oldPassword))
 | 
			
		||||
        {
 | 
			
		||||
            if(password1.equals(password2)){
 | 
			
		||||
                this.user.setPassword(password1);
 | 
			
		||||
                this.repository.save(this.user);
 | 
			
		||||
            }else{
 | 
			
		||||
                //TODO Errorhandling
 | 
			
		||||
            }
 | 
			
		||||
        }else{
 | 
			
		||||
            //TODO: Errorhandling
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateShippingInfo(String salutation, String name, String address){
 | 
			
		||||
        if(salutation.equals("") || name.equals("") || address.equals("")){
 | 
			
		||||
            //TODO: Errorhandling
 | 
			
		||||
        }else{
 | 
			
		||||
            this.user.salutation = salutation;
 | 
			
		||||
            this.user.name = name;
 | 
			
		||||
            this.user.defaultDeliveryAddress.addressString = address;
 | 
			
		||||
            this.repository.save(this.user);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateAdvertisementFlag(boolean advertisementFlag){
 | 
			
		||||
        this.user.isAdvertisementActivated = advertisementFlag; //TODO: Errodhandling
 | 
			
		||||
        this.repository.save(this.user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updatePaymentInfo(String creditCardNumber){
 | 
			
		||||
        //TODO: Errorhandling
 | 
			
		||||
        this.user.defaultPayment.creditCardNumber = creditCardNumber;
 | 
			
		||||
        this.repository.save(this.user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class UpdateResult{
 | 
			
		||||
        public boolean updated;  //if true worked, if false not worked
 | 
			
		||||
        public String errorString;
 | 
			
		||||
 | 
			
		||||
        public UpdateResult(boolean updated, String errorString){
 | 
			
		||||
            this.updated = updated;
 | 
			
		||||
            this.errorString = errorString;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public UpdateResult(boolean updated){
 | 
			
		||||
            this.updated = updated;
 | 
			
		||||
            this.errorString = "";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
package org.hso.ecommerce.controller;
 | 
			
		||||
 | 
			
		||||
import org.hso.ecommerce.action.user.UpdateUserSettingsAction;
 | 
			
		||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
 | 
			
		||||
import org.hso.ecommerce.entities.user.User;
 | 
			
		||||
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
 | 
			
		||||
@ -46,7 +47,6 @@ public class UserController {
 | 
			
		||||
    @GetMapping("/orders/")
 | 
			
		||||
    public String userOrdeers(HttpSession session,
 | 
			
		||||
                              Model model) {
 | 
			
		||||
 | 
			
		||||
        List<CustomerOrder> orders = customerOrderRepository.getOrdersByUserId((long) session.getAttribute("userId"));
 | 
			
		||||
 | 
			
		||||
        model.addAttribute("orders", orders);
 | 
			
		||||
@ -55,41 +55,65 @@ public class UserController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/settings/changeMail")
 | 
			
		||||
    public String changeMail(@RequestParam("email") String email){
 | 
			
		||||
    public String changeMail(HttpSession session,
 | 
			
		||||
                             @RequestParam("email") String email
 | 
			
		||||
    ){
 | 
			
		||||
        User user = userRepository.findById((long) session.getAttribute("userId")).get();
 | 
			
		||||
 | 
			
		||||
        //TODO: implement this
 | 
			
		||||
        UpdateUserSettingsAction cusa = new UpdateUserSettingsAction(user, userRepository);
 | 
			
		||||
        cusa.updateEmail(email);
 | 
			
		||||
 | 
			
		||||
        return "user/settings";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/settings/changePwd")
 | 
			
		||||
    public String changePwd(){
 | 
			
		||||
    public String changePwd(HttpSession session,
 | 
			
		||||
                            @RequestParam("old-password") String oldPassword,
 | 
			
		||||
                            @RequestParam("password1") String password1,
 | 
			
		||||
                            @RequestParam("password2") String password2
 | 
			
		||||
    ){
 | 
			
		||||
        User user = userRepository.findById((long) session.getAttribute("userId")).get();
 | 
			
		||||
 | 
			
		||||
        //TODO: implement this
 | 
			
		||||
        UpdateUserSettingsAction cusa = new UpdateUserSettingsAction(user, userRepository);
 | 
			
		||||
        cusa.updatePassword(oldPassword, password1, password2);
 | 
			
		||||
 | 
			
		||||
        return "user/settings";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/settings/changeAddress")
 | 
			
		||||
    public String changeAddress(){
 | 
			
		||||
    public String changeAddress(HttpSession session,
 | 
			
		||||
                                @RequestParam("salutation") String salutation,
 | 
			
		||||
                                @RequestParam("name") String name,
 | 
			
		||||
                                @RequestParam("address") String address
 | 
			
		||||
    ){
 | 
			
		||||
        User user = userRepository.findById((long) session.getAttribute("userId")).get();
 | 
			
		||||
 | 
			
		||||
        //TODO: implement this
 | 
			
		||||
        UpdateUserSettingsAction cusa = new UpdateUserSettingsAction(user, userRepository);
 | 
			
		||||
        cusa.updateShippingInfo(salutation, name, address);
 | 
			
		||||
 | 
			
		||||
        return "user/settings";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/settings/changeAdSettings")
 | 
			
		||||
    public String changeAdSettings(){
 | 
			
		||||
    public String changeAdSettings(HttpSession session,
 | 
			
		||||
                                   @RequestParam("ad") String ad
 | 
			
		||||
    ){
 | 
			
		||||
        User user = userRepository.findById((long) session.getAttribute("userId")).get();
 | 
			
		||||
 | 
			
		||||
        //TODO: implement this
 | 
			
		||||
        UpdateUserSettingsAction cusa = new UpdateUserSettingsAction(user, userRepository);
 | 
			
		||||
        cusa.updateAdvertisementFlag(ad.equals("y"));
 | 
			
		||||
 | 
			
		||||
        return "user/settings";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/settings/changePaymentInfo")
 | 
			
		||||
    public String changePaymentInfo(){
 | 
			
		||||
    public String changePaymentInfo(HttpSession session,
 | 
			
		||||
                                    @RequestParam("creditCardNumber") String creditCardNumber
 | 
			
		||||
    ){
 | 
			
		||||
        User user = userRepository.findById((long) session.getAttribute("userId")).get();
 | 
			
		||||
 | 
			
		||||
        //TODO: implement this
 | 
			
		||||
        UpdateUserSettingsAction cusa = new UpdateUserSettingsAction(user, userRepository);
 | 
			
		||||
        cusa.updatePaymentInfo(creditCardNumber);
 | 
			
		||||
 | 
			
		||||
        return "user/settings";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </form>
 | 
			
		||||
 | 
			
		||||
        <form class="detailflex">
 | 
			
		||||
        <form class="detailflex" method="POST" th:action="@{/user/settings/changePwd}">
 | 
			
		||||
            <div>
 | 
			
		||||
                <h2> Sicherheit </h2>
 | 
			
		||||
            </div>
 | 
			
		||||
@ -42,8 +42,8 @@
 | 
			
		||||
                <input class="full-width" type="password" name="old-password" placeholder="Passwort" id="password"
 | 
			
		||||
                       required>
 | 
			
		||||
 | 
			
		||||
                <label for="password">Neues Passwort</label>
 | 
			
		||||
                <input class="full-width" type="password" name="password" placeholder="Passwort" id="password" required>
 | 
			
		||||
                <label for="password1">Neues Passwort</label>
 | 
			
		||||
                <input class="full-width" type="password" name="password1" placeholder="Passwort" id="password1" required>
 | 
			
		||||
                <label for="password2">Neues Passwort wiederholen</label>
 | 
			
		||||
                <input class="full-width" type="password" name="password2" placeholder="Passwort" id="password2"
 | 
			
		||||
                       required>
 | 
			
		||||
@ -51,7 +51,7 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </form>
 | 
			
		||||
 | 
			
		||||
        <form class="detailflex">
 | 
			
		||||
        <form class="detailflex" method="POST" th:action="@{/user/settings/changeAddress}">
 | 
			
		||||
            <div>
 | 
			
		||||
                <h2> Rechungs- und Lieferinformation </h2>
 | 
			
		||||
            </div>
 | 
			
		||||
@ -91,7 +91,7 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </form>
 | 
			
		||||
 | 
			
		||||
        <form class="detailflex">
 | 
			
		||||
        <form class="detailflex" method="POST" th:action="@{/user/settings/changeAdSettings}">
 | 
			
		||||
            <div>
 | 
			
		||||
                <h2> Werbung </h2>
 | 
			
		||||
            </div>
 | 
			
		||||
@ -106,13 +106,13 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </form>
 | 
			
		||||
 | 
			
		||||
        <form class="detailflex">
 | 
			
		||||
        <form class="detailflex" method="POST" th:action="@{/user/settings/changePaymentInfo}">
 | 
			
		||||
            <div>
 | 
			
		||||
                <h2> Zahlungsinformation</h2>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
                <div class="input-icon">
 | 
			
		||||
                    <input class="full-width" type="text" name="payment-card" th:value="${user.defaultPayment.creditCardNumber}" required/>
 | 
			
		||||
                    <input class="full-width" type="text" name="creditCardNumber" th:value="${user.defaultPayment.creditCardNumber}" required/>
 | 
			
		||||
                    <button> Kreditkartennummer ändern</button>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user