78 lines
2.4 KiB
Java
78 lines
2.4 KiB
Java
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 = "";
|
|
}
|
|
}
|
|
}
|