Search in sources :

Example 6 with PremiumUser

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();
}
Also used : Random(java.util.Random) PremiumUser(net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser) Date(java.util.Date)

Example 7 with PremiumUser

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";
}
Also used : SupporterDeviceSubscription(net.osmand.server.api.repo.DeviceSubscriptionsRepository.SupporterDeviceSubscription) Calendar(java.util.Calendar) PremiumUser(net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with PremiumUser

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";
}
Also used : SupporterDeviceSubscription(net.osmand.server.api.repo.DeviceSubscriptionsRepository.SupporterDeviceSubscription) UserFilesResults(net.osmand.server.controllers.pub.UserdataController.UserFilesResults) PremiumUser(net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PremiumUser (net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser)8 Date (java.util.Date)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 PremiumUserDevice (net.osmand.server.api.repo.PremiumUserDevicesRepository.PremiumUserDevice)3 Random (java.util.Random)2 SupporterDeviceSubscription (net.osmand.server.api.repo.DeviceSubscriptionsRepository.SupporterDeviceSubscription)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 UserFile (net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile)1 PremiumUsersRepository (net.osmand.server.api.repo.PremiumUsersRepository)1 UserFilesResults (net.osmand.server.controllers.pub.UserdataController.UserFilesResults)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1