public void createAccount(User user, String initialPassword)
throws EntityExistsException, DataBackendException
{
if(StringUtils.isEmpty(user.getName()))
{
throw new DataBackendException("Could not create "
+ "an user with empty name!");
}
if (accountExists(user))
{
throw new EntityExistsException("The account '" +
user.getName() + "' already exists");
}
user.setPassword(TurbineSecurity.encryptPassword(initialPassword));
try
{
// this is to mimic the old behavior of the method, the user
// should be new that is passed to this method. It would be
// better if this was checked, but the original code did not
// care about the user's state, so we set it to be appropriate
((Persistent) user).setNew(true);
((Persistent) user).setModified(true);
((Persistent) user).save();
}
catch (Exception e)
{
throw new DataBackendException("Failed to create account '" +
user.getName() + "'", e);
}
}