Package org.dspace.eperson
Class AccountServiceImpl
- java.lang.Object
-
- org.dspace.eperson.AccountServiceImpl
-
- All Implemented Interfaces:
AccountService
public class AccountServiceImpl extends Object implements AccountService
Methods for handling registration by email and forgotten passwords. When someone registers as a user, or forgets their password, the sendRegistrationInfo or sendForgotPasswordInfo methods can be used to send an email to the user. The email contains a special token, a long string which is randomly generated and thus hard to guess. When the user presents the token back to the system, the AccountManager can use the token to determine the identity of the eperson. *NEW* now ignores expiration dates so that tokens never expire- Version:
- $Revision$
- Author:
- Peter Breton
-
-
Field Summary
Fields Modifier and Type Field Description protected EPersonServiceePersonServiceprotected RegistrationDataServiceregistrationDataService
-
Constructor Summary
Constructors Modifier Constructor Description protectedAccountServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeleteToken(Context context, String token)Delete token.StringgetEmail(Context context, String token)Return the e-mail address referred to by a token, or null if email address can't be found ignores expiration of tokenEPersongetEPerson(Context context, String token)Return the EPerson corresponding to token, where token was emailed to the person by either the sendRegistrationInfo or sendForgotPasswordInfo methods.protected voidsendEmail(Context context, String email, boolean isRegister, RegistrationData rd)Send a DSpace message to the given email address.voidsendForgotPasswordInfo(Context context, String email)Email forgot password info to the given email address.protected RegistrationDatasendInfo(Context context, String email, boolean isRegister, boolean send)THIS IS AN INTERNAL METHOD.voidsendRegistrationInfo(Context context, String email)Email registration info to the given email address.
-
-
-
Field Detail
-
ePersonService
@Autowired(required=true) protected EPersonService ePersonService
-
registrationDataService
@Autowired(required=true) protected RegistrationDataService registrationDataService
-
-
Method Detail
-
sendRegistrationInfo
public void sendRegistrationInfo(Context context, String email) throws SQLException, IOException, javax.mail.MessagingException, AuthorizeException
Email registration info to the given email address. Potential error conditions: Cannot create registration data in database (throws SQLException) Error sending email (throws MessagingException) Error reading email template (throws IOException) Authorization error (throws AuthorizeException)- Specified by:
sendRegistrationInfoin interfaceAccountService- Parameters:
context- DSpace contextemail- Email address to send the registration email to- Throws:
SQLExceptionIOExceptionjavax.mail.MessagingExceptionAuthorizeException
-
sendForgotPasswordInfo
public void sendForgotPasswordInfo(Context context, String email) throws SQLException, IOException, javax.mail.MessagingException, AuthorizeException
Email forgot password info to the given email address. Potential error conditions: No EPerson with that email (returns null) Cannot create registration data in database (throws SQLException) Error sending email (throws MessagingException) Error reading email template (throws IOException) Authorization error (throws AuthorizeException)- Specified by:
sendForgotPasswordInfoin interfaceAccountService- Parameters:
context- DSpace contextemail- Email address to send the forgot-password email to- Throws:
SQLExceptionIOExceptionjavax.mail.MessagingExceptionAuthorizeException
-
getEPerson
public EPerson getEPerson(Context context, String token) throws SQLException, AuthorizeException
Return the EPerson corresponding to token, where token was emailed to the person by either the sendRegistrationInfo or sendForgotPasswordInfo methods.
If the token is not found return null.
- Specified by:
getEPersonin interfaceAccountService- Parameters:
context- DSpace contexttoken- Account token- Returns:
- The EPerson corresponding to token, or null.
- Throws:
SQLException- If the token or eperson cannot be retrieved from the database.AuthorizeException
-
getEmail
public String getEmail(Context context, String token) throws SQLException
Return the e-mail address referred to by a token, or null if email address can't be found ignores expiration of token- Specified by:
getEmailin interfaceAccountService- Parameters:
context- DSpace contexttoken- Account token- Returns:
- The email address corresponding to token, or null.
- Throws:
SQLException
-
deleteToken
public void deleteToken(Context context, String token) throws SQLException
Delete token.- Specified by:
deleteTokenin interfaceAccountService- Parameters:
context- DSpace contexttoken- The token to delete- Throws:
SQLException- If a database error occurs
-
sendInfo
protected RegistrationData sendInfo(Context context, String email, boolean isRegister, boolean send) throws SQLException, IOException, javax.mail.MessagingException, AuthorizeException
THIS IS AN INTERNAL METHOD. THE SEND PARAMETER ALLOWS IT TO BE USED FOR TESTING PURPOSES. Send an info to the EPerson with the given email address. If isRegister is TRUE, this is registration email; otherwise, it is forgot-password email. If send is TRUE, the email is sent; otherwise it is skipped. Potential error conditions:- Parameters:
context- DSpace contextemail- Email address to send the forgot-password email toisRegister- If true, this is for registration; otherwise, it is for forgot-passwordsend- If true, send email; otherwise do not send any email- Returns:
- null if no EPerson with that email found
- Throws:
SQLException- Cannot create registration data in databasejavax.mail.MessagingException- Error sending emailIOException- Error reading email templateAuthorizeException- Authorization error
-
sendEmail
protected void sendEmail(Context context, String email, boolean isRegister, RegistrationData rd) throws javax.mail.MessagingException, IOException, SQLException
Send a DSpace message to the given email address. If isRegister istrue, this is registration email; otherwise, it is a forgot-password email.- Parameters:
context- The relevant DSpace Context.email- The email address to mail toisRegister- If true, this is registration email; otherwise it is forgot-password email.rd- The RDBMS row representing the registration data.- Throws:
javax.mail.MessagingException- If an error occurs while sending emailIOException- A general class of exceptions produced by failed or interrupted I/O operations.SQLException- An exception that provides information on a database access error or other errors.
-
-