Refactor AccountManager to remove dependency on webapp.util.UIUtil.

git-svn-id: http://scm.dspace.org/svn/repo/trunk@1962 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Mark Diggory
2007-05-23 18:36:35 +00:00
parent 9e96b0dfdb
commit 22e15ada14
2 changed files with 10 additions and 12 deletions

View File

@@ -46,7 +46,6 @@ import java.util.Calendar;
import java.util.Locale; import java.util.Locale;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
@@ -57,7 +56,6 @@ import org.dspace.core.I18nUtil;
import org.dspace.core.Utils; import org.dspace.core.Utils;
import org.dspace.storage.rdbms.DatabaseManager; import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow; import org.dspace.storage.rdbms.TableRow;
import org.dspace.app.webui.util.UIUtil;
/** /**
* Methods for handling registration by email and forgotten passwords. When * Methods for handling registration by email and forgotten passwords. When
@@ -96,11 +94,11 @@ public class AccountManager
* @param email * @param email
* Email address to send the registration email to * Email address to send the registration email to
*/ */
public static void sendRegistrationInfo(HttpServletRequest request, Context context, String email) public static void sendRegistrationInfo(Context context, String email)
throws SQLException, IOException, MessagingException, throws SQLException, IOException, MessagingException,
AuthorizeException AuthorizeException
{ {
sendInfo(request, context, email, true, true); sendInfo(context, email, true, true);
} }
/** /**
@@ -116,11 +114,11 @@ public class AccountManager
* @param email * @param email
* Email address to send the forgot-password email to * Email address to send the forgot-password email to
*/ */
public static void sendForgotPasswordInfo(HttpServletRequest request, Context context, String email) public static void sendForgotPasswordInfo(Context context, String email)
throws SQLException, IOException, MessagingException, throws SQLException, IOException, MessagingException,
AuthorizeException AuthorizeException
{ {
sendInfo(request, context, email, false, true); sendInfo(context, email, false, true);
} }
/** /**
@@ -222,7 +220,7 @@ public class AccountManager
* registration; otherwise, it is for forgot-password @param send If true, * registration; otherwise, it is for forgot-password @param send If true,
* send email; otherwise do not send any email * send email; otherwise do not send any email
*/ */
protected static TableRow sendInfo(HttpServletRequest request, Context context, String email, protected static TableRow sendInfo(Context context, String email,
boolean isRegister, boolean send) throws SQLException, IOException, boolean isRegister, boolean send) throws SQLException, IOException,
MessagingException, AuthorizeException MessagingException, AuthorizeException
{ {
@@ -255,7 +253,7 @@ public class AccountManager
if (send) if (send)
{ {
sendEmail(request, email, isRegister, rd); sendEmail(context, email, isRegister, rd);
} }
return rd; return rd;
@@ -279,7 +277,7 @@ public class AccountManager
* @exception IOException * @exception IOException
* If an error occurs while reading the email template. * If an error occurs while reading the email template.
*/ */
private static void sendEmail(HttpServletRequest request, String email, boolean isRegister, TableRow rd) private static void sendEmail(Context context, String email, boolean isRegister, TableRow rd)
throws MessagingException, IOException, SQLException throws MessagingException, IOException, SQLException
{ {
String base = ConfigurationManager.getProperty("dspace.url"); String base = ConfigurationManager.getProperty("dspace.url");
@@ -290,7 +288,7 @@ public class AccountManager
isRegister ? "register" : "forgot").append("?") isRegister ? "register" : "forgot").append("?")
.append("token=").append(rd.getStringColumn("token")) .append("token=").append(rd.getStringColumn("token"))
.toString(); .toString();
Locale locale = UIUtil.obtainContext(request).getCurrentLocale(); Locale locale = context.getCurrentLocale();
Email bean = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(locale, isRegister ? "register" Email bean = ConfigurationManager.getEmail(I18nUtil.getEmailFilename(locale, isRegister ? "register"
: "change_password")); : "change_password"));
bean.addRecipient(email); bean.addRecipient(email);

View File

@@ -291,7 +291,7 @@ public class RegisterServlet extends DSpaceServlet
try try
{ {
AccountManager.sendRegistrationInfo(request, context, email); AccountManager.sendRegistrationInfo(context, email);
} }
catch (javax.mail.SendFailedException e) catch (javax.mail.SendFailedException e)
{ {
@@ -403,7 +403,7 @@ public class RegisterServlet extends DSpaceServlet
log.info(LogManager.getHeader(context, log.info(LogManager.getHeader(context,
"sendtoken_forgotpw", "email=" + email)); "sendtoken_forgotpw", "email=" + email));
AccountManager.sendForgotPasswordInfo(request, context, email); AccountManager.sendForgotPasswordInfo(context, email);
JSPManager.showJSP(request, response, JSPManager.showJSP(request, response,
"/register/password-token-sent.jsp"); "/register/password-token-sent.jsp");