code cleanup
This commit is contained in:
		@ -1,26 +1,23 @@
 | 
			
		||||
package org.hso.ecommerce.action.user;
 | 
			
		||||
 | 
			
		||||
import com.sun.xml.bind.v2.TODO;
 | 
			
		||||
import org.hibernate.sql.Update;
 | 
			
		||||
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){
 | 
			
		||||
    public UpdateUserSettingsAction(User user, UserRepository repository) {
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.repository = repository;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UpdateResult updateEmail(String newMail){
 | 
			
		||||
    public UpdateResult updateEmail(String newMail) {
 | 
			
		||||
        UpdateResult result = new UpdateResult(false);
 | 
			
		||||
        if(!newMail.contains("@")){
 | 
			
		||||
        if (!newMail.contains("@")) {
 | 
			
		||||
            result.errorString = "Ändern der Email-Addresse nicht möglich. Bitte versuchen Sie es erneut.";
 | 
			
		||||
        }else{
 | 
			
		||||
        } else {
 | 
			
		||||
            this.user.email = newMail;
 | 
			
		||||
            this.repository.save(this.user);
 | 
			
		||||
            result.updated = true;
 | 
			
		||||
@ -28,28 +25,27 @@ public class UpdateUserSettingsAction {
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UpdateResult updatePassword(String oldPassword, String password1, String password2){
 | 
			
		||||
    public UpdateResult updatePassword(String oldPassword, String password1, String password2) {
 | 
			
		||||
        UpdateResult result = new UpdateResult(false);
 | 
			
		||||
        if(this.user.validatePassword(oldPassword))
 | 
			
		||||
        {
 | 
			
		||||
            if(password1.equals(password2)){
 | 
			
		||||
                if(!password1.equals(oldPassword)){
 | 
			
		||||
        if (this.user.validatePassword(oldPassword)) {
 | 
			
		||||
            if (password1.equals(password2)) {
 | 
			
		||||
                if (!password1.equals(oldPassword)) {
 | 
			
		||||
                    this.user.setPassword(password1);
 | 
			
		||||
                    this.repository.save(this.user);
 | 
			
		||||
                    result.updated = true;
 | 
			
		||||
                }else {
 | 
			
		||||
                } else {
 | 
			
		||||
                    result.errorString = "Die neuen Passwörter entsprechen dem alten Passwort.";
 | 
			
		||||
                }
 | 
			
		||||
            }else{
 | 
			
		||||
            } else {
 | 
			
		||||
                result.errorString = "Die beiden neuen Passwörter stimmen nicht überein. Bitte versuchen Sie es erneut.";
 | 
			
		||||
            }
 | 
			
		||||
        }else{
 | 
			
		||||
        } else {
 | 
			
		||||
            result.errorString = "Das eingegebene alte Passwort stimmt nicht mit dem momentan gespeicherten Passwort überein. Bitte versuchen Sie es erneut.";
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UpdateResult updateShippingInfo(String salutation, String name, String address){
 | 
			
		||||
    public UpdateResult updateShippingInfo(String salutation, String name, String address) {
 | 
			
		||||
        this.user.salutation = salutation;
 | 
			
		||||
        this.user.name = name;
 | 
			
		||||
        this.user.defaultDeliveryAddress.addressString = address;
 | 
			
		||||
@ -57,28 +53,28 @@ public class UpdateUserSettingsAction {
 | 
			
		||||
        return new UpdateResult(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UpdateResult updatePaymentInfo(String creditCardNumber){
 | 
			
		||||
    public UpdateResult updatePaymentInfo(String creditCardNumber) {
 | 
			
		||||
        UpdateResult result = new UpdateResult(false);
 | 
			
		||||
        if(creditCardNumber.matches("[0-9]+")){
 | 
			
		||||
        if (creditCardNumber.matches("[0-9]+")) {
 | 
			
		||||
            this.user.defaultPayment.creditCardNumber = creditCardNumber;
 | 
			
		||||
            this.repository.save(this.user);
 | 
			
		||||
            result.updated = true;
 | 
			
		||||
        }else{
 | 
			
		||||
        } else {
 | 
			
		||||
            result.errorString = "Kreditkartennummer darf nur Zahlen enthalten. Bitte versuchen Sie es erneut.";
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class UpdateResult{
 | 
			
		||||
    public class UpdateResult {
 | 
			
		||||
        public boolean updated;  //if true worked, if false not worked
 | 
			
		||||
        public String errorString;
 | 
			
		||||
 | 
			
		||||
        public UpdateResult(boolean updated, String errorString){
 | 
			
		||||
        public UpdateResult(boolean updated, String errorString) {
 | 
			
		||||
            this.updated = updated;
 | 
			
		||||
            this.errorString = errorString;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public UpdateResult(boolean updated){
 | 
			
		||||
        public UpdateResult(boolean updated) {
 | 
			
		||||
            this.updated = updated;
 | 
			
		||||
            this.errorString = "";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -24,7 +24,7 @@ public class User {
 | 
			
		||||
    @Column(unique = true)
 | 
			
		||||
    public String email;
 | 
			
		||||
 | 
			
		||||
    @Column(insertable=false, updatable = false)
 | 
			
		||||
    @Column(insertable = false, updatable = false)
 | 
			
		||||
    public String name;
 | 
			
		||||
 | 
			
		||||
    public String salutation;
 | 
			
		||||
@ -44,10 +44,6 @@ public class User {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEmail(String email) {
 | 
			
		||||
        this.email = email;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean validatePassword(String password) {
 | 
			
		||||
        return BCrypt.checkpw(password, passwordHash);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -13,5 +13,4 @@ public interface CustomerOrderRepository extends JpaRepository<CustomerOrder, Lo
 | 
			
		||||
    @Query("SELECT co FROM CustomerOrder co WHERE co.customer.id = :userId")
 | 
			
		||||
    List<CustomerOrder> getOrdersByUserId(long userId);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user