mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Add some boilerplate to the password reset.
This commit is contained in:
parent
8d09ac39f2
commit
5a1f97abca
|
@ -174,6 +174,8 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
Date start = DateUtils.getMidnightBefore(_start, tz);
|
||||
Date monthStart = DateUtils.getStartOfMonth(_start, tz);
|
||||
BreakerGroup root = CollectionUtils.getFirst(config.getBreakerGroups());
|
||||
if (root == null)
|
||||
return;
|
||||
proxy.delete(BreakerGroupSummary.class, new DaoQuery("_id", BreakerGroupEnergy.toId(_accountId, root.getId(), EnergyBlockViewMode.MONTH, monthStart)));
|
||||
while (start.before(_end)) {
|
||||
Date dayEnd = DateUtils.getMidnightAfter(start, tz);
|
||||
|
@ -335,7 +337,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
|
||||
@Override
|
||||
public String addPasswordResetKey(String _email) {
|
||||
String key = aes.encryptToBase64(_email);
|
||||
String key = aes.encryptToUrlSafeBase64(_email);
|
||||
proxy.saveEntity("password_reset", new DaoEntity("_id", key));
|
||||
return key;
|
||||
}
|
||||
|
@ -356,6 +358,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
Account acct = getAccountByUsername(aes.decryptFromBase64ToString(_key));
|
||||
acct.setPassword(_password);
|
||||
putAccount(acct);
|
||||
proxy.delete("password_reset", new DaoQuery("_id", _key));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -412,6 +412,7 @@ public class BreakerGroupEnergy {
|
|||
_energyBlocks.put(block.getStart().getTime(), b);
|
||||
} else
|
||||
b.addJoules(block.getJoules());
|
||||
b.addCharge(block.getCharge());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class ResetPasswordServlet extends FreemarkerServlet {
|
|||
} else {
|
||||
DaoEntity payload = getRequestZipBson(_req);
|
||||
String email = DaoSerializer.getString(payload, "email");
|
||||
if (NullUtils.isNotEmpty(email)) {
|
||||
if (EmailValidator.getInstance().isValid(email)) {
|
||||
String key = Globals.dao.addPasswordResetKey(email);
|
||||
Email from = new Email("info@lanternsoftware.com");
|
||||
String subject = "Password Reset - Lantern Power Monitor";
|
||||
|
@ -79,9 +79,11 @@ public class ResetPasswordServlet extends FreemarkerServlet {
|
|||
zipBsonResponse(_resp, new DaoEntity("success", response.getStatusCode() == 200));
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Failed to send password reset email", ex);
|
||||
zipBsonResponse(_resp, new DaoEntity("success", false));
|
||||
}
|
||||
}
|
||||
_resp.setStatus(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
_resp.setStatus(400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user