use of org.b3log.solo.util.Randoms in project solo by b3log.
the class LoginProcessor method sendResetUrl.
/**
* Sends the password resetting URL with a random token.
*
* @param userEmail the given email
* @param jsonObject return code and message object
* @throws JSONException the JSONException
* @throws ServiceException the ServiceException
* @throws IOException the IOException
* @throws RepositoryException the RepositoryException
*/
private void sendResetUrl(final String userEmail, final JSONObject jsonObject) throws JSONException, ServiceException, IOException, RepositoryException {
final JSONObject preference = preferenceQueryService.getPreference();
final String token = new Randoms().nextStringWithMD5();
final String adminEmail = preference.getString(Option.ID_C_ADMIN_EMAIL);
final String mailSubject = langPropsService.get("resetPwdMailSubject");
final String mailBody = langPropsService.get("resetPwdMailBody") + " " + Latkes.getServePath() + "/forgot?token=" + token + "&login=" + userEmail;
final MailService.Message message = new MailService.Message();
final JSONObject option = new JSONObject();
option.put(Keys.OBJECT_ID, token);
option.put(Option.OPTION_CATEGORY, "passwordReset");
option.put(Option.OPTION_VALUE, System.currentTimeMillis());
final Transaction transaction = optionRepository.beginTransaction();
optionRepository.add(option);
transaction.commit();
message.setFrom(adminEmail);
message.addRecipient(userEmail);
message.setSubject(mailSubject);
message.setHtmlBody(mailBody);
mailService.send(message);
jsonObject.put("succeed", true);
jsonObject.put("to", Latkes.getServePath() + "/login?from=forgot");
jsonObject.put(Keys.MSG, langPropsService.get("resetPwdSuccessSend"));
LOGGER.log(Level.DEBUG, "Sent a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", new Object[] { mailSubject, mailBody, userEmail });
}
Aggregations