Hi,
The following Patch provides more debugging information in case of
problems while creating a new user. Furthermore the creation date of a
user is inserted into the database.
I hope my modifications fit into the design of Turbine...
BTW: Could anybody explain me the idea behind:
private static final String successScreen = "admin.Main";
Right now this screen is not defined, which resultes in an
exception right after adding a new user.
Where this "admin.Main" screen is supposed to be defined? I mean
Is this a normal screen which will be implemented later or does the
naming "Main" have some special purpose here?
Have fun!
t. Bernie
---
Index: NewUser.java
===================================================================
RCS file:
/products/cvs/turbine/turbine/src/java/org/apache/turbine/actions/admin/NewUser.java,v
retrieving revision 1.1
diff -c -r1.1 NewUser.java
*** NewUser.java 1999/12/28 05:13:21 1.1
--- NewUser.java 2000/01/19 14:18:48
***************
*** 6,11 ****
--- 6,12 ----
// Turbine/Village/ECS Imports
import org.apache.turbine.modules.*;
import org.apache.turbine.util.*;
+ import org.apache.turbine.util.access.*;
/**
* Action for adding a new user to the system.
***************
*** 21,31 ****
private static final String successScreen = "admin.Main";
//Message is a field is missing
! private static final String INCOMPLETE_FORM = "Incomplete form. Please complete
all fields";
!
//Message if passwords don't match
private static final String BAD_PASSWORDS = "Passwords don't match. Please try
again.";
public void build( RunData data ) throws Exception
{
--- 22,37 ----
private static final String successScreen = "admin.Main";
//Message is a field is missing
! private static final String INCOMPLETE_FORM_A = "Incomplete form: ";
! private static final String INCOMPLETE_FORM_B = " missing. Please complete all
fields.";
!
//Message if passwords don't match
private static final String BAD_PASSWORDS = "Passwords don't match. Please try
again.";
+ //Message if user exists already
+ private static final String USER_EXISTS_A = "Sorry, a user \'";
+ private static final String USER_EXISTS_B = " \'exists already. Please choose
+another username.";
+
public void build( RunData data ) throws Exception
{
***************
*** 46,80 ****
username = data.parameters.getString("username", null);
if ( username == null )
{
! reDirect(data,INCOMPLETE_FORM,failScreen);
return;
}
fname = data.parameters.getString("fname", null);
if ( fname == null )
{
! reDirect(data,INCOMPLETE_FORM, failScreen);
return;
}
lname = data.parameters.getString("lname", null);
if ( lname == null )
{
! reDirect(data,INCOMPLETE_FORM, failScreen);
return;
}
password = data.parameters.getString("password", null);
if ( password == null )
{
! reDirect(data,INCOMPLETE_FORM, failScreen);
return;
}
confirm = data.parameters.getString("confirm", null);
if ( confirm == null )
{
! reDirect(data,INCOMPLETE_FORM, failScreen);
return;
}
--- 52,95 ----
username = data.parameters.getString("username", null);
if ( username == null )
{
! reDirect(data,INCOMPLETE_FORM_A + "Username" + INCOMPLETE_FORM_B
,failScreen);
return;
+
}
+
+ // Check whether Username exists in the database
+ if ( UserFactory.getUser(username) != null )
+ {
+ reDirect(data,USER_EXISTS_A + username + USER_EXISTS_B, failScreen);
+ return;
+ }
+
fname = data.parameters.getString("fname", null);
if ( fname == null )
{
! reDirect(data,INCOMPLETE_FORM_A + "First name" + INCOMPLETE_FORM_B
,failScreen);
return;
}
lname = data.parameters.getString("lname", null);
if ( lname == null )
{
! reDirect(data,INCOMPLETE_FORM_A + "Last name" + INCOMPLETE_FORM_B
,failScreen);
return;
}
password = data.parameters.getString("password", null);
if ( password == null )
{
! reDirect(data,INCOMPLETE_FORM_A + "Password" + INCOMPLETE_FORM_B
,failScreen);
return;
}
confirm = data.parameters.getString("confirm", null);
if ( confirm == null )
{
! reDirect(data,INCOMPLETE_FORM_A + "Confirm" + INCOMPLETE_FORM_B
,failScreen);
return;
}
***************
*** 83,98 ****
reDirect(data,BAD_PASSWORDS,failScreen);
return;
}
!
//If we're this far everything must be cool!
Criteria newdata = new Criteria();
newdata.add(TurbineUserPeer.USERNAME, username);
newdata.add(TurbineUserPeer.PASSWORD, password);
newdata.add(TurbineUserPeer.FIRST_NAME, fname);
newdata.add(TurbineUserPeer.LAST_NAME, lname);
!
! //FIX THIS - This is creating a 2002 year on my system!?
! //newdata.add(TurbineUserPeer.CREATED, new Date());
try
{
--- 98,111 ----
reDirect(data,BAD_PASSWORDS,failScreen);
return;
}
!
//If we're this far everything must be cool!
Criteria newdata = new Criteria();
newdata.add(TurbineUserPeer.USERNAME, username);
newdata.add(TurbineUserPeer.PASSWORD, password);
newdata.add(TurbineUserPeer.FIRST_NAME, fname);
newdata.add(TurbineUserPeer.LAST_NAME, lname);
! newdata.add(TurbineUserPeer.CREATED, new java.util.Date());
try
{
***************
*** 119,122 ****
data.setMessage(message);
data.setScreen(screen);
}
! }
\ No newline at end of file
--- 132,135 ----
data.setMessage(message);
data.setScreen(screen);
}
! }
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]