src/com/vehiclerental/logicLayer/implementations/UserServiceImpl.java
/**
     * Creates a new user account with the given properties
     *
     * @param contract the given account properties
     * @return the newly created account
     * @throws EmailAlreadyInUseException if the email is already in use
     * @throws InvalidPropertyException if one of the properties is invalid
     */
Creates a new user account with the given properties
@param contract the given account properties
@return the newly created account
@throws EmailAlreadyInUseException if the email is already in use
@throws InvalidPropertyException if one of the properties is invalid
Creates a new user account with the given properties @param contract the given account properties @return the newly created account @throws EmailAlreadyInUseException if the email is already in use @throws InvalidPropertyException if one of the properties is invalid
@Override
    public User createUser(CreateAccountRequestContract contract) throws EmailAlreadyInUseException, InvalidPropertyException {
        User user = new User();
        if (contract.fullName == null || contract.fullName.isEmpty()) {
            throw new InvalidPropertyException("Full name is invalid");
        }
        user.setFullName(contract.fullName);
        if (contract.emailAddress == null || contract.emailAddress.isEmpty() || contract.emailAddress.contains(":")) {
            throw new InvalidPropertyException("Email address is invalid");
        }
        User userWithSameEmail = getUser(contract.emailAddress);
        if (userWithSameEmail != null) {
            throw new EmailAlreadyInUseException();
        }
        user.setEmailAddress(contract.emailAddress);
        user.setIsStaff(false);
        if (contract.phoneNumber == null || contract.phoneNumber.isEmpty()) {
            throw new InvalidPropertyException("Phone number is invalid");
        }
        user.setPhoneNumber(contract.phoneNumber);
        if (contract.address_street == null || contract.address_street.isEmpty()) {
            throw new InvalidPropertyException("Street is invalid");
        }
        user.setAddress_street(contract.address_street);
        if (contract.address_city == null || contract.address_city.isEmpty()) {
            throw new InvalidPropertyException("City is invalid");
        }
        user.setAddress_city(contract.address_city);
        if (contract.address_postalCode == null || contract.address_postalCode.isEmpty()) {
            throw new InvalidPropertyException("Postal code is invalid");
        }
        user.setAddress_postalCode(contract.address_postalCode);
        if (contract.address_country == null || contract.address_country.isEmpty()) {
            throw new InvalidPropertyException("Country is invalid");
        }
        user.setAddress_country(contract.address_country);
        if (contract.password == null || contract.password.isEmpty()) {
            throw new InvalidPropertyException("Password is invalid");
        }
        try {
            user.setHashedPassword(CryptoUtils.Sha256Hash(contract.password));
        } catch (NoSuchAlgorithmException e) {
            return null;
        } catch (UnsupportedEncodingException e) {
            return null;
        }
        user.encrypt();
        userDao.create(user);
        user.decrypt();
        return user;
    }
@ Override public User createUser ( CreateAccountRequestContract contract ) throws EmailAlreadyInUseException , InvalidPropertyException { User user = new User ( ) ; if ( contract . fullName == null || contract . fullName . isEmpty ( ) ) { throw new InvalidPropertyException ( "Full name is invalid" ) ; } user . setFullName ( contract . fullName ) ; if ( contract . emailAddress == null || contract . emailAddress . isEmpty ( ) || contract . emailAddress . contains ( ":" ) ) { throw new InvalidPropertyException ( "Email address is invalid" ) ; } User userWithSameEmail = getUser ( contract . emailAddress ) ; if ( userWithSameEmail != null ) { throw new EmailAlreadyInUseException ( ) ; } user . setEmailAddress ( contract . emailAddress ) ; user . setIsStaff ( false ) ; if ( contract . phoneNumber == null || contract . phoneNumber . isEmpty ( ) ) { throw new InvalidPropertyException ( "Phone number is invalid" ) ; } user . setPhoneNumber ( contract . phoneNumber ) ; if ( contract . address_street == null || contract . address_street . isEmpty ( ) ) { throw new InvalidPropertyException ( "Street is invalid" ) ; } user . setAddress_street ( contract . address_street ) ; if ( contract . address_city == null || contract . address_city . isEmpty ( ) ) { throw new InvalidPropertyException ( "City is invalid" ) ; } user . setAddress_city ( contract . address_city ) ; if ( contract . address_postalCode == null || contract . address_postalCode . isEmpty ( ) ) { throw new InvalidPropertyException ( "Postal code is invalid" ) ; } user . setAddress_postalCode ( contract . address_postalCode ) ; if ( contract . address_country == null || contract . address_country . isEmpty ( ) ) { throw new InvalidPropertyException ( "Country is invalid" ) ; } user . setAddress_country ( contract . address_country ) ; if ( contract . password == null || contract . password . isEmpty ( ) ) { throw new InvalidPropertyException ( "Password is invalid" ) ; } try { user . setHashedPassword ( CryptoUtils . Sha256Hash ( contract . password ) ) ; } catch ( NoSuchAlgorithmException e ) { return null ; } catch ( UnsupportedEncodingException e ) { return null ; } user . encrypt ( ) ; userDao . create ( user ) ; user . decrypt ( ) ; return user ; }
Creates a new user account with the given properties
 @param contract the given account properties
 @return the newly created account
 @throws EmailAlreadyInUseException if the email is already in use
 @throws InvalidPropertyException if one of the properties is invalid
Creates a new user account with the given properties @param contract the given account properties @return the newly created account @throws EmailAlreadyInUseException if the email is already in use @throws InvalidPropertyException if one of the properties is invalid
// The colon is not accepted here because of the basic auth system (email_address:password) //We need to encrypt the user before adding it into the database //Now we decrypt before returning it