Rejiggered delete to not actually delete the user, but instead make it

unaccessable and have a different name so that that username is freed up.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1215 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
eric
2003-09-04 02:40:00 +00:00
parent 92c4b6d108
commit 08bfecb01f
@@ -1,5 +1,5 @@
// //
// $Id: UserRepository.java,v 1.25 2003/08/15 22:35:57 mdb Exp $ // $Id: UserRepository.java,v 1.26 2003/09/04 02:40:00 eric Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -38,6 +38,7 @@ import com.samskivert.jdbc.JDBCUtil;
import com.samskivert.jdbc.JORARepository; import com.samskivert.jdbc.JORARepository;
import com.samskivert.jdbc.StaticConnectionProvider; import com.samskivert.jdbc.StaticConnectionProvider;
import com.samskivert.jdbc.jora.Cursor; import com.samskivert.jdbc.jora.Cursor;
import com.samskivert.jdbc.jora.FieldMask;
import com.samskivert.jdbc.jora.Session; import com.samskivert.jdbc.jora.Session;
import com.samskivert.jdbc.jora.Table; import com.samskivert.jdbc.jora.Table;
import com.samskivert.servlet.SiteIdentifier; import com.samskivert.servlet.SiteIdentifier;
@@ -293,7 +294,13 @@ public class UserRepository extends JORARepository
} }
/** /**
* Removes the user from the repository. * 'Delete' the users account such that they can no longer access it,
* however we do not delete the record from the db. The name is
* changed such that the original name has XX=FOO if the name were FOO
* originally. If we have to lop off any of the name to get our
* prefix to fit we use a minus sign instead of a equals side. The
* password field is set to be the empty string so that no one can log
* in (since nothing hashes to the empty string.
*/ */
public void deleteUser (final User user) public void deleteUser (final User user)
throws PersistenceException throws PersistenceException
@@ -302,9 +309,35 @@ public class UserRepository extends JORARepository
public Object invoke (Connection conn, DatabaseLiaison liaison) public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException throws PersistenceException, SQLException
{ {
_utable.delete(user); // create our modified fields mask
// nothing to return FieldMask mask = _utable.getFieldMask();
return null; mask.setModified("username");
mask.setModified("password");
// set the password to unusable
user.password = "";
String join = "=";
String newName = user.username;
if (newName.length() > 21) {
newName = newName.substring(0,21);
join = "-";
}
for (int ii = 0; ii < 100; ii++) {
try {
user.username = ii + join + newName;
_utable.update(user, mask);
return null; // nothing to return
} catch (SQLException se) {
if (!liaison.isDuplicateRowException(se)) {
throw se;
}
}
}
// ok we failed to rename the user, lets bust an error
throw new PersistenceException("Failed to 'delete' the user");
} }
}); });
} }