hi *!
when i tried to use the currently "hidden" admin.changePassword usecase,
i realized it is quite hard to use, because it will throw a very nasty
exception if one does not also set the userId parameter. this is
unintuitive imho: if userId is not set explicitly, it should default to
changing the password of the currently active user.
the attached patch tries to accomplish this. could you please review it?
it seems to me that my way to get the currently active user id is
overcomplicated... there must be a shortcut somewhere, but since i could
not find any documentation about what information is available in the
context of a usecase, i basically grepped for static methods in the api
and worked my way up :'(
best,
jörn
--
"Open source takes the bullshit out of software."
- Charles Ferguson on TechnologyReview.com
--
Jörn Nettingsmeier, EDV-Administrator
Institut für Politikwissenschaft
Universität Duisburg-Essen, Standort Duisburg
Mail: [EMAIL PROTECTED], Telefon: 0203/379-2736
Index: src/java/org/apache/lenya/cms/ac/usecases/UserPassword.java
===================================================================
--- src/java/org/apache/lenya/cms/ac/usecases/UserPassword.java (revision 411441)
+++ src/java/org/apache/lenya/cms/ac/usecases/UserPassword.java (working copy)
@@ -17,7 +17,15 @@
package org.apache.lenya.cms.ac.usecases;
import org.apache.lenya.ac.User;
+import org.apache.lenya.ac.Identity;
+import java.util.Map;
+
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+
+
/**
* Usecase to change a user's password.
*/
@@ -29,6 +37,8 @@
protected static final String CHECK_PASSWORD = "checkPassword";
+ private User user;
+
/**
* Ctor.
*/
@@ -41,7 +51,17 @@
*/
protected void doCheckExecutionConditions() throws Exception {
super.doCheckExecutionConditions();
-
+ if (this.user == null) { // the usecase was called without userId set, assume current user:
+ // there surely is a simpler way. or is there?
+ Map objectModel = ContextHelper.getObjectModel(getContext());
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ this.user = Identity.getIdentity(request.getSession(true)).getUser();
+ }
+/*
+ if (this.user == null) {
+ addErrorMessage("Implementation error: you must set the \"userId\" parameter when calling this usecase.");
+ }
+*/
String checkOldPassword = getParameterAsString(CHECK_PASSWORD);
if (checkOldPassword != null && checkOldPassword.equals(Boolean.toString(true))) {
String oldPassword = getParameterAsString(OLD_PASSWORD);
@@ -50,7 +70,6 @@
addErrorMessage("The old password is not correct.");
}
}
-
checkNewPassword(this);
}
@@ -62,7 +81,6 @@
this.user.setPassword(getParameterAsString(NEW_PASSWORD));
}
- private User user;
/**
* @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.Object)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]