Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final String encryptedToken = req.getParameter("token");
- if (encryptedToken == null || encryptedToken.length() == 0 || encryptedToken.length() > 2048) {
- throw new Exception("Invalid Token");
- }
- final String encryption_phrase = Settings.instance().getString("email_validation_token_password");
- final String token;
- try {
- token = MyWallet.decrypt(encryptedToken, encryption_phrase, MyWallet.DefaultPBKDF2Iterations);
- } catch (Exception e) {
- throw new Exception("Error de-serializing token");
- }
- final JSONParser parser = new JSONParser();
- final JSONObject tokenObj;
- try {
- tokenObj = (JSONObject) parser.parse(token);
- } catch (Exception e) {
- throw new Exception("Token invalid JSON");
- }
- final String email_code = tokenObj.get("email_code").toString();
- final String rguid = tokenObj.get("guid").toString();
- final long time = Long.valueOf(tokenObj.get("time").toString());
- validateGUIDorThrow(rguid);
- if (System.currentTimeMillis() - time > 3600000) {
- throw new Exception("Verification Link Expired");
- }
- //Limit retries
- Integer retries = (Integer)Cache.get(rguid + VERIFICATION_RETRIES_KEY);
- if (retries == null)
- retries = 0;
- if (retries >= 10) {
- throw new ExceptionLowSeverity(strings.getWallet_app().getErrors().getVerification_retry_limit_reached());
- }
- {
- if (verifyEmailCode(rguid, email_code)) {
- logAction(rguid, "verify email", getRealIP(req), req.getHeader("User-Agent"));
- req.setAttribute("initial_success", strings.getWallet_app().getSuccess().getEmail_verified());
- } else {
- Connection conn = DatabaseManager.userConn();
- try {
- generateAndUpdateEmailCode(conn, rguid);
- } finally {
- DatabaseManager.close(conn);
- }
- Cache.put(rguid + VERIFICATION_RETRIES_KEY, retries+1, 86400);
- logAction(rguid, "error verifying email", getRealIP(req), req.getHeader("User-Agent"));
- req.setAttribute("initial_error", strings.getWallet_app().getErrors().getEmail_code_incorrect());
- }
- }
- forwardToIndexPage(req, res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement