use of net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser in project OsmAnd-tools by osmandapp.
the class UserdataController method webUserRegister.
public ResponseEntity<String> webUserRegister(@RequestParam(name = "email", required = true) String email) throws IOException {
// allow to register only with small case
email = email.toLowerCase().trim();
if (!email.contains("@")) {
return error(ERROR_CODE_EMAIL_IS_INVALID, "email is not valid to be registered");
}
PremiumUser pu = usersRepository.findByEmail(email);
if (pu == null) {
return error(ERROR_CODE_EMAIL_IS_INVALID, "email is not registered");
}
String errorMsg = checkOrderIdPremium(pu.orderid);
if (errorMsg != null) {
return error(ERROR_CODE_NO_VALID_SUBSCRIPTION, errorMsg);
}
pu.tokendevice = TOKEN_DEVICE_WEB;
pu.token = (new Random().nextInt(8999) + 1000) + "";
pu.tokenTime = new Date();
usersRepository.saveAndFlush(pu);
emailSender.sendOsmAndCloudWebEmail(pu.email, pu.token);
return ok();
}
use of net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser in project OsmAnd-tools by osmandapp.
the class AdminController method registerPromo.
@PostMapping(path = { "/register-promo" })
public String registerPromo(Model model, @RequestParam(required = true) String comment, final RedirectAttributes redirectAttrs) throws JsonProcessingException {
SupporterDeviceSubscription deviceSub = new SupporterDeviceSubscription();
deviceSub.sku = "promo_website";
deviceSub.orderId = UUID.randomUUID().toString();
deviceSub.kind = "promo";
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
deviceSub.timestamp = c.getTime();
deviceSub.starttime = c.getTime();
deviceSub.valid = true;
deviceSub.purchaseToken = comment;
c.add(Calendar.YEAR, 1);
deviceSub.expiretime = c.getTime();
subscriptionsRepository.save(deviceSub);
if (emailSender.isEmail(comment)) {
String email = comment;
PremiumUser existingUser = usersRepository.findByEmail(email);
if (existingUser == null) {
PremiumUser pu = new PremiumUsersRepository.PremiumUser();
pu.email = email;
pu.regTime = new Date();
pu.orderid = deviceSub.orderId;
usersRepository.saveAndFlush(pu);
deviceSub.purchaseToken += " (email sent & registered)";
emailSender.sendOsmAndCloudPromoEmail(comment, deviceSub.orderId);
} else {
deviceSub.purchaseToken += " (ERROR: email is already registered)";
}
}
redirectAttrs.addFlashAttribute("subscriptions", Collections.singleton(deviceSub));
return "redirect:info#audience";
}
use of net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser in project OsmAnd-tools by osmandapp.
the class AdminController method searchSubscription.
@PostMapping(path = { "/search-subscription" })
public String searchSubscription(Model model, @RequestParam(required = true) String orderId, final RedirectAttributes redirectAttrs) throws JsonProcessingException {
SupporterDeviceSubscription deviceSub = new SupporterDeviceSubscription();
deviceSub.sku = "not found";
deviceSub.orderId = "none";
deviceSub.valid = false;
if (emailSender.isEmail(orderId)) {
PremiumUser pu = usersRepository.findByEmail(orderId);
if (pu != null) {
deviceSub.sku = orderId + " (pro email)";
List<SupporterDeviceSubscription> ls = subscriptionsRepository.findByOrderId(pu.orderid);
if (ls != null && ls.size() > 0) {
deviceSub = ls.get(0);
}
if (deviceSub != null) {
UserFilesResults ufs = userDataController.generateFiles(pu.id, null, null, true, false);
ufs.allFiles.clear();
ufs.uniqueFiles.clear();
deviceSub.payload = gson.toJson(ufs);
}
}
} else {
List<SupporterDeviceSubscription> ls = subscriptionsRepository.findByOrderId(orderId);
if (ls != null && ls.size() > 0) {
deviceSub = ls.get(0);
}
}
redirectAttrs.addFlashAttribute("subscriptions", Collections.singleton(deviceSub));
return "redirect:info#audience";
}
Aggregations