From 08bfecb01f28a9dfe7524fb2a67d88395f7d3254 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 4 Sep 2003 02:40:00 +0000 Subject: [PATCH] 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 --- .../servlet/user/UserRepository.java | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/servlet/user/UserRepository.java b/projects/samskivert/src/java/com/samskivert/servlet/user/UserRepository.java index 76612eed..ebb19995 100644 --- a/projects/samskivert/src/java/com/samskivert/servlet/user/UserRepository.java +++ b/projects/samskivert/src/java/com/samskivert/servlet/user/UserRepository.java @@ -1,9 +1,9 @@ // -// $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 // Copyright (C) 2001 Michael Bayne -// +// // This library is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation; either version 2.1 of the License, or @@ -38,6 +38,7 @@ import com.samskivert.jdbc.JDBCUtil; import com.samskivert.jdbc.JORARepository; import com.samskivert.jdbc.StaticConnectionProvider; import com.samskivert.jdbc.jora.Cursor; +import com.samskivert.jdbc.jora.FieldMask; import com.samskivert.jdbc.jora.Session; import com.samskivert.jdbc.jora.Table; 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) throws PersistenceException @@ -302,9 +309,35 @@ public class UserRepository extends JORARepository public Object invoke (Connection conn, DatabaseLiaison liaison) throws PersistenceException, SQLException { - _utable.delete(user); - // nothing to return - return null; + // create our modified fields mask + FieldMask mask = _utable.getFieldMask(); + 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"); } }); }