[cvs]
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj
DefaultUserInfo.java
JCorporate Ltd
jcorp at jcorp2.servlets.net
Wed Jun 23 01:26:53 PDT 2004
Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj
In directory jcorp2.servlets.net:/tmp/cvs-serv2491/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj
Modified Files:
DefaultUserInfo.java
Log Message:
split out logic for add() and update() check on email uniqueness
Index: DefaultUserInfo.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/DefaultUserInfo.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** DefaultUserInfo.java 23 Jun 2004 01:28:40 -0000 1.40
--- DefaultUserInfo.java 23 Jun 2004 08:26:51 -0000 1.41
***************
*** 71,76 ****
import com.jcorporate.expresso.core.cache.CachedObject;
import com.jcorporate.expresso.core.controller.ControllerRequest;
- import com.jcorporate.expresso.core.db.DBException;
import com.jcorporate.expresso.core.db.DBConnection;
import com.jcorporate.expresso.core.dbobj.DBField;
import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
--- 71,76 ----
import com.jcorporate.expresso.core.cache.CachedObject;
import com.jcorporate.expresso.core.controller.ControllerRequest;
import com.jcorporate.expresso.core.db.DBConnection;
+ import com.jcorporate.expresso.core.db.DBException;
import com.jcorporate.expresso.core.dbobj.DBField;
import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
***************
*** 204,207 ****
--- 204,210 ----
private static LRUMap nameToIdMap = new LRUMap(20);
+ private static final boolean IS_UPDATE = true;
+ private static final boolean IS_ADD = false;
+
/**
* Sets the uid of the userinfo object
***************
*** 273,277 ****
throws DBException {
! checkEmailAddrAlreadyUsed();
// At initial login, UserName == LoginName, Registation controllers can later modify this
--- 276,280 ----
throws DBException {
! checkEmailAddrAlreadyUsed(IS_ADD);
// At initial login, UserName == LoginName, Registation controllers can later modify this
***************
*** 1224,1228 ****
setCheckZeroUpdate(false);
! checkEmailAddrAlreadyUsed();
if (getField(FULL_NAME).equals("")) {
--- 1227,1231 ----
setCheckZeroUpdate(false);
! checkEmailAddrAlreadyUsed(IS_UPDATE);
if (getField(FULL_NAME).equals("")) {
***************
*** 1274,1279 ****
/**
* Check that another user with same email doesn't exist already
*/
! private void checkEmailAddrAlreadyUsed() throws DBException {
if (!getField(EMAIL_ADDRESS).equalsIgnoreCase("none")) {
--- 1277,1293 ----
/**
* Check that another user with same email doesn't exist already
+ * @param isUpdate boolean for true = update case, false = 'add' case
*/
! private void checkEmailAddrAlreadyUsed(boolean isUpdate) throws DBException {
!
! if ( isUpdate ) {
! // update case may be shortcircuited, thus requiring no db access
! String onlychanged = Setup.getValueUnrequired(getDataContext(), UPDATE_CHANGED_ONLY);
! if (StringUtil.toBoolean(onlychanged)) {
! // ok, setting says that this app only updates for changed fields; is our field changed?
! // if not, don't waste time checking for whether we are unique
! if ( !getDataField(EMAIL_ADDRESS).isChanged() ) return;
! }
! }
if (!getField(EMAIL_ADDRESS).equalsIgnoreCase("none")) {
***************
*** 1282,1290 ****
anotherUser.setEmail(getField(EMAIL_ADDRESS));
! // add() would just throw error on find() alone, but extra test for update() will still be ok for add()
! if (anotherUser.find() && (anotherUser.getUid() != getUid())) {
throw new DBException(
"Another user with the same email address \"" +
getField(EMAIL_ADDRESS) + "\" already exists");
}
}
--- 1296,1310 ----
anotherUser.setEmail(getField(EMAIL_ADDRESS));
! boolean foundEmail = anotherUser.find();
! if ( foundEmail && isUpdate && (anotherUser.getUid() != getUid())) {
! // update case: must also be diff. uid
throw new DBException(
"Another user with the same email address \"" +
getField(EMAIL_ADDRESS) + "\" already exists");
+ } else if ( foundEmail && !isUpdate ) {
+ // add case--just finding another with this email is enough to throw
+ throw new DBException("Another user with the same email address \"" +
+ getField(EMAIL_ADDRESS) + "\" already exists");
+
}
}
***************
*** 1308,1314 ****
anotherUser.setDBName(getDataContext());
anotherUser.setLoginName(getField(LOGIN));
! // add() would just throw error on find() alone, but extra test for update() will still be ok for add()
! if (anotherUser.find() && (anotherUser.getUid() != getUid())) {
throw new DBException("Another user with the same login \"" +
getField(LOGIN) +
--- 1328,1338 ----
anotherUser.setDBName(getDataContext());
anotherUser.setLoginName(getField(LOGIN));
+ boolean foundLogin = anotherUser.find();
! if (!isUpdate && foundLogin ) {
! throw new DBException("Another user with the same login \"" +
! getField(LOGIN) +
! "\" already exists");
! } else if ( isUpdate && foundLogin && (anotherUser.getUid() != getUid())) {
throw new DBException("Another user with the same login \"" +
getField(LOGIN) +
More information about the cvs
mailing list