fix token redeem

This commit is contained in:
_Bastler 2021-11-11 19:23:37 +01:00
parent cd05e008ae
commit fad01fc0d7
7 changed files with 61 additions and 32 deletions

View File

@ -280,13 +280,18 @@ public class PermissionManager implements UserDataProvider {
Instant permissionStarts = starts;
Instant permissionsExpires = expires;
if (permissionMapping.isLifetimeRound()) {
permissionStarts = InstantHelper.truncate(permissionStarts,
permissionMapping.getLifetimeUnit());
}
if (permissionsExpires == null) {
permissionsExpires = InstantHelper.plus(
permissionStarts == null ? Instant.now() : permissionStarts,
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
}
boolean additional = true;
boolean additional = permissionMapping.isAddon();
for (JsonElement anwser : answers) {
if (anwser.isJsonObject()

View File

@ -143,7 +143,7 @@ public class UserController extends BaseController {
}
if (!register) {
throw new EntityResponseStatusException(HttpStatus.UNAUTHORIZED);
throw new EntityResponseStatusException(HttpStatus.LOCKED);
}
userModelValidator.validate(userModel, errors);

View File

@ -100,7 +100,7 @@ public class TokenSessionManager {
}
permissions.addAll(permissionManager.getForItem(userId, item,
orderPosition.get("answers").getAsJsonArray(), null, null));
orderPosition.get("answers").getAsJsonArray(),lastPaymentDate, null));
}
} catch (Exception e) {
// ignore
@ -180,7 +180,7 @@ public class TokenSessionManager {
}
permissionManager.applyItem(userId, item,
position.get("answers").getAsJsonArray(), null, null);
position.get("answers").getAsJsonArray(), lastPaymentDate, null);
permissionMappings.addAll(permissionMappingManager.getAllByItem(item));
quotaManager.applyItem(userId, item);
quotaMappings.addAll(quotaMappingManager.getAllByItem(item));

View File

@ -18,6 +18,7 @@ import org.springframework.util.Assert;
import com.google.common.collect.Lists;
import de.bstly.we.controller.support.TokenSessionManager;
import de.bstly.we.security.token.LocalSecondFactorAuthenticationToken;
/**
@ -28,6 +29,8 @@ public class FormAuthenticationSuccessHandler
@Autowired
protected RememberMeServices rememberMeServices;
@Autowired
protected TokenSessionManager tokenSessionManager;
private String totpRedirectUrl;
private String rememberMeParameter;

View File

@ -118,8 +118,11 @@ public class MembershipManager {
int membershipId = Integer.valueOf(membershipIdAnswer.get("answer").getAsInt());
if (internalMembershipId == membershipId) {
writeMembershipId = false;
logger.trace("Order '" + orderPosition.get("order").getAsString()
+ "' already processed, membership id: '" + membershipId + "'");
logger.trace("Order '"
+ orderPosition.get("order").getAsString()
+ "' already processed, membership id: '"
+ membershipId
+ "'");
}
}
@ -137,9 +140,10 @@ public class MembershipManager {
JsonObject payload = new JsonObject();
payload.add("answers", answers);
logger.debug(
"Write membershipId for '" + orderPosition.get("order").getAsString()
+ "': " + internalMembershipId);
logger.debug("Write membershipId for '"
+ orderPosition.get("order").getAsString()
+ "': "
+ internalMembershipId);
pretixManager.request(
String.format("/api/v1/organizers/%s/events/%s/orderpositions/%s/",
@ -178,8 +182,10 @@ public class MembershipManager {
payload.add("answers", answers);
logger.debug("Create membershipId for '" + orderPosition.get("order").getAsString()
+ "': " + nextMembershipId);
logger.debug("Create membershipId for '"
+ orderPosition.get("order").getAsString()
+ "': "
+ nextMembershipId);
pretixManager
.request(
@ -261,7 +267,8 @@ public class MembershipManager {
if (membershipId == 0) {
logger.warn("No membership number found for '"
+ membershipOrderPosition.get("order").getAsString() + "'!");
+ membershipOrderPosition.get("order").getAsString()
+ "'!");
continue;
}
@ -270,7 +277,8 @@ public class MembershipManager {
if (membershipStart == null) {
logger.warn("No last payment found for '"
+ membershipOrderPosition.get("order").getAsString() + "'!");
+ membershipOrderPosition.get("order").getAsString()
+ "'!");
continue;
}
@ -307,11 +315,13 @@ public class MembershipManager {
HttpMethod.PATCH, payload);
logger.debug("Write active state for '"
+ membershipOrderPosition.get("order").getAsString() + "': "
+ membershipOrderPosition.get("order").getAsString()
+ "': "
+ activeAnswer);
} else {
logger.trace("Order active state for '"
+ membershipOrderPosition.get("order").getAsString() + "' already set: "
+ membershipOrderPosition.get("order").getAsString()
+ "' already set: "
+ activeAnswer);
}
}
@ -383,8 +393,11 @@ public class MembershipManager {
.isBefore(Instant.now())) {
expireMemberships.add(membershipOrderPosition);
} else {
logger.trace("Membership '" + membershipOrderPosition.get("order").getAsString()
+ "' not expiring in next " + membershipfeeOrderDays + " days.");
logger.trace("Membership '"
+ membershipOrderPosition.get("order").getAsString()
+ "' not expiring in next "
+ membershipfeeOrderDays
+ " days.");
}
}
@ -428,7 +441,8 @@ public class MembershipManager {
if (membershipId == 0) {
logger.warn("No membership number found for '"
+ membershipOrderPosition.get("order").getAsString() + "'!");
+ membershipOrderPosition.get("order").getAsString()
+ "'!");
continue;
}
@ -456,11 +470,11 @@ public class MembershipManager {
membershipFeeOrderPositionAnswers.add(membershipFeeReferenceAnswer);
JsonObject membershipFeeCodeAnswer = new JsonObject();
membershipFeeCodeAnswer.addProperty("question",
membershipFeeCodeQuestion);
membershipFeeCodeAnswer.addProperty("question", membershipFeeCodeQuestion);
membershipFeeCodeAnswer.add("options", new JsonArray());
membershipFeeCodeAnswer.add("option_identifiers", new JsonArray());
membershipFeeCodeAnswer.addProperty("answer", membershipOrderPosition.get("order").getAsString());
membershipFeeCodeAnswer.addProperty("answer",
membershipOrderPosition.get("order").getAsString());
membershipFeeOrderPositionAnswers.add(membershipFeeCodeAnswer);
membershipFeeOrderPosition.add("answers", membershipFeeOrderPositionAnswers);
@ -477,6 +491,12 @@ public class MembershipManager {
membershipFeeOrder.add("payment_provider", payment.get("provider"));
}
Instant expires = InstantHelper.minus(InstantHelper.truncate(
InstantHelper.plus(Instant.now(), 1, ChronoUnit.YEARS), ChronoUnit.YEARS),
1, ChronoUnit.DAYS);
membershipFeeOrder.addProperty("expires",
pretixDateFormat.format(Date.from(expires)));
membershipFeeOrder.addProperty("send_email", orderSendmail);
membershipFeeOrder.addProperty("testmode", orderTestmode);
membershipFeeOrder.addProperty("simulate", orderSimulate);
@ -484,14 +504,12 @@ public class MembershipManager {
membershipFeeOrder = pretixManager.createOrder(membershipFeeOrder);
JsonObject expire = new JsonObject();
Instant expires = InstantHelper.minus(InstantHelper.truncate(
InstantHelper.plus(Instant.now(), 1, ChronoUnit.YEARS), ChronoUnit.YEARS),
1, ChronoUnit.DAYS);
expire.addProperty("expires", pretixDateFormat.format(Date.from(expires)));
membershipFeeOrder = pretixManager
.extendOrder(membershipFeeOrder.get("code").getAsString(), expire);
logger.debug("Create membership fee order: " + membershipFeeOrder.toString());
logger.debug("Create membership fee order: "
+ membershipFeeOrder.toString());
} else
// send reminder mail for membership fee order
if (membershipfeeReminderDays > 0 && membershipfeeReminderQuestion > 0
@ -687,7 +705,8 @@ public class MembershipManager {
active = date.toInstant();
} catch (ParseException e) {
logger.error("Error on parsing active date for '"
+ orderPosition.get("order").getAsString() + "'!", e);
+ orderPosition.get("order").getAsString()
+ "'!", e);
}
}
}
@ -810,7 +829,9 @@ public class MembershipManager {
return pretixDateFormat.parse(answer.get("answer").getAsString()).toInstant();
} catch (ParseException e) {
logger.error("Error on parsing active date for '"
+ orderPosition.get("order").getAsString() + "' in question '" + question
+ orderPosition.get("order").getAsString()
+ "' in question '"
+ question
+ "'!", e);
}
}

View File

@ -12,7 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<revision>1.3.2-SNAPSHOT</revision>
<revision>1.4.0-SNAPSHOT</revision>
</properties>
<parent>