Index: greenstone3/trunk/src/java/org/greenstone/gsdl3/service/Authentication.java
===================================================================
--- greenstone3/trunk/src/java/org/greenstone/gsdl3/service/Authentication.java	(revision 14347)
+++ greenstone3/trunk/src/java/org/greenstone/gsdl3/service/Authentication.java	(revision 14349)
@@ -175,10 +175,9 @@
 	Element service_node = this.doc.createElement(GSXML.SERVICE_ELEM);
 	authen_node.appendChild(service_node);
-	// add the authentication procedure to the service node
 	service_node.setAttribute("aup",aup);
-	// the user recordes got from the users table
+	// user's info 
 	UserQueryResult userQueryResult=null;
 
-	// check the usersDb database, if it isn't existing, create one and add a "admin" user
+	// check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the  user database and add a "admin" user
 	String usersDB_dir = this.site_home + File.separatorChar + "etc" + File.separatorChar + "usersDB";
 	DerbyWrapper derbyWrapper=new DerbyWrapper();
@@ -202,16 +201,16 @@
 	// Action: login
 	if (aup.equals("Login")){
-	    if (uan.equals("")){
-	    service_node.setAttribute("info","Login");
-	    derbyWrapper.closeDatabase();
-	    return result;
-	    }
-	
-	// if the current procedure requires authentication(uan=1),but the user hasn't been authenticated(asn=0),will ask the user to login first
+	    if (uan.equals("")){ //return a login page, if the user's name is not given
+		service_node.setAttribute("info","Login");
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
+	
+	// if the authentication(uan=1) is required,but the user hasn't been authenticated(asn=0),the user is asked to login first
 	    if ((uan.equals("1") && asn.equals("0"))) {
 		if ((un.length()==0) && (pw.length()==0)){
 		    service_node.setAttribute("asn","0");
 		    service_node.setAttribute("info","Login");
-		     derbyWrapper.closeDatabase();
+		    derbyWrapper.closeDatabase();
 		    return result;
 		}
@@ -223,14 +222,11 @@
 		    return result;
 		}else{  
-		    userQueryResult=derbyWrapper.findUser(un,pw);
-		    derbyWrapper.closeDatabase();
+		    userQueryResult=derbyWrapper.findUser(un,pw);//looking for the user from the users table
 		    service_node.setAttribute(GSXML.NAME_ATT,"Authentication");
-		    
 		    service_node.setAttribute("un",un);
-		    //  service_node.setAttribute("asn",asn);
 		    if (userQueryResult==null){
-			asn="0";//the user isn't a vaild user
-			service_node.setAttribute("asn","0");// either unsername or password is wrong
-			service_node.setAttribute("err","un-pw-err");
+			//the user isn't a vaild user
+			service_node.setAttribute("asn","0");
+			service_node.setAttribute("err","un-pw-err");// either unsername or password is wrong
 			service_node.setAttribute("info","Login");
 			derbyWrapper.closeDatabase();
@@ -241,12 +237,17 @@
 			String groups=((UserTermInfo)userInfo.get(0)).groups_;
 			String accountstatus=((UserTermInfo)userInfo.get(0)).accountstatus_;
+			if (accountstatus.trim().equals("false")){
+			    service_node.setAttribute("asn","0");
+			    service_node.setAttribute("err","as-false");//the account status is false
+			    service_node.setAttribute("info","Login");
+			    derbyWrapper.closeDatabase();
+			    return result;
+			}
 			String[] groups_array=groups.split(",");
 			for (int i=0; i<groups_array.length;i++){
-			    if ((groups_array[i].trim().toLowerCase()).equals("administrator")){
-				if (accountstatus.trim().equals("true")){
-				    asn="1";
-				    service_node.setAttribute("asn","1");
-				    break;
-				}
+			    if ((groups_array[i].trim().toLowerCase()).equals("administrator")){// check whether the user is in the administrator group
+				asn="1";
+				service_node.setAttribute("asn","1");
+				break;
 			    }
 			}
@@ -258,11 +259,5 @@
 		}
 	    }
-	    //asn=0 couldn't find the user
-	    if (asn.equals("0")){
-		service_node.setAttribute("info","Login");
-		service_node.setAttribute("err","not-authen");
-		derbyWrapper.closeDatabase();
-		return result;
-	    }
+
 	    //asn!=0 This is a valid user 
 	    if (!asn.equals("0")){
@@ -283,5 +278,5 @@
 	    }
 
-	   //valid users can't list all users because they aren't in the administrator group(asn=2)
+	   //valid users but not in the administrator group(asn=2), they cannot list all users
 	    if (asn.equals("2")){
 		service_node.setAttribute("info","Login");
@@ -292,5 +287,5 @@
 		return result;
 	    }
-	    //valid users are in the administrator group, they can list all users(asn=1)
+	    //valid users belong to the administrator group(asn=1), they can list all users
 	    if (asn.equals("1")){
 		userQueryResult=derbyWrapper.findUser(null,null);
@@ -316,4 +311,9 @@
 	//Action : adduder
 	if (aup.equals("AddUser")){
+	    if (asn.equals("") && un.equals("")){
+		service_node.setAttribute("info","Login");
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
 	    //valid users can't add a new user because they aren't in the administrator group(asn=2)
 	    if (asn.equals("2")){
@@ -541,56 +541,55 @@
 	    }
 
-	     if (!pw.equals(umpw) && umpw.length()>0){
-		 service_node.setAttribute("info","modify_interface");
-		 service_node.setAttribute("err","pw-umpw-nm-err");//if the original password is not match
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }
+	    if (!pw.equals(umpw) && umpw.length()>0){
+		service_node.setAttribute("info","modify_interface");
+		service_node.setAttribute("err","pw-umpw-nm-err");//if the original password is not match
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
 	     
-	     if ((umpw1.length()==0) || (umpw2.length()==0)){
-		 service_node.setAttribute("info","modify_interface");
-		 service_node.setAttribute("err","umpw1-umpw2-null-err");//if one of the password strings is none,return the err info back
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }
-
-	     if(!umpw1.equals(umpw2)){
-		 service_node.setAttribute("info","modify_interface");
-		 service_node.setAttribute("err","umpw1-umpw2-nm-err");//if one of the password strings is none,return the err info back
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }
-
-	     if (umpw.length()==0){
-		 service_node.setAttribute("info","modify_interface");
-		 service_node.setAttribute("err","umpw-null-err");//if one of the password strings is none,return the err info back
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }
-	     //check the new password and the retyped password
-	     if ((umpw1==null) || (umpw1.length()<3) || (umpw1.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw1)))){
-		 service_node.setAttribute("info","modify_interface");
-		 service_node.setAttribute("err","umpw1-err");// the new password is illegal
-		 derbyWrapper.closeDatabase();
-		 return result;
+	    if ((umpw1.length()==0) || (umpw2.length()==0)){
+		service_node.setAttribute("info","modify_interface");
+		service_node.setAttribute("err","umpw1-umpw2-null-err");//if one of the password strings is none,return the err info back
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
+
+	    if(!umpw1.equals(umpw2)){
+		service_node.setAttribute("info","modify_interface");
+		service_node.setAttribute("err","umpw1-umpw2-nm-err");//if one of the password strings is none,return the err info back
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
+	    
+	    if (umpw.length()==0){
+		service_node.setAttribute("info","modify_interface");
+		service_node.setAttribute("err","umpw-null-err");//if one of the password strings is none,return the err info back
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
+	    //check the new password and the retyped password
+	    if ((umpw1==null) || (umpw1.length()<3) || (umpw1.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw1)))){
+		service_node.setAttribute("info","modify_interface");
+		service_node.setAttribute("err","umpw1-err");// the new password is illegal
+		derbyWrapper.closeDatabase();
+		return result;
+	    }  
+	    
+	    if ((umpw2==null) || (umpw2.length()<3) || (umpw2.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw2)))){
+		service_node.setAttribute("info","modify_interface");
+		service_node.setAttribute("err","umpw2-err"); // the retyped password is illegal
+		derbyWrapper.closeDatabase();
+		return result;
 	     }  
-
-	     if ((umpw2==null) || (umpw2.length()<3) || (umpw2.length()>8) || (!(Pattern.matches("[\\p{ASCII}]+",umpw2)))){
-		 service_node.setAttribute("info","modify_interface");
-		 service_node.setAttribute("err","umpw2-err"); // the retyped password is illegal
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }  
-	     String modify_user_info=derbyWrapper.modifyUserInfo(un,umpw1,null,null,null);
-	     if (modify_user_info.equals("succeed")){
-		 service_node.setAttribute("err","");// the passsword has been changed successfully
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }else{
-		 service_node.setAttribute("err",modify_user_info);// return the error message of the pasword couldn't be modified 
-		 derbyWrapper.closeDatabase();
-		 return result;
-	     }
-
+	    String modify_user_info=derbyWrapper.modifyUserInfo(un,umpw1,null,null,null);
+	    if (modify_user_info.equals("succeed")){
+		service_node.setAttribute("err","");// the passsword has been changed successfully
+		derbyWrapper.closeDatabase();
+		return result;
+	    }else{
+		service_node.setAttribute("err",modify_user_info);// return the error message of the pasword couldn't be modified 
+		derbyWrapper.closeDatabase();
+		return result;
+	    }
 	}
 
