Exemplo n.º 1
0
def payments_claim_initiate(request, user, email):
    payment = Payments.GetPayment(email=email)
    if payment is None:
        return False
    claim_code = Payments.GenerateClaimCode(user, payment)
    reclaim_url = request.build_absolute_uri(
        reverse("payments_claim_return", kwargs={"code": claim_code}))
    from tapiriik.web.email import generate_message_from_template, send_email
    message, plaintext_message = generate_message_from_template(
        "email/payment_reclaim.html", {"url": reclaim_url})
    send_email(email,
               "Reclaim your payment on tapiriik.com",
               message,
               plaintext_message=plaintext_message)
    return True
Exemplo n.º 2
0
def payments_claim_return(request, code):
    user, payment = Payments.ConsumeClaimCode(code.upper())
    if not payment:
        return render(request, "payments/claim_return_fail.html")
    User.AssociatePayment(user, payment)
    User.Login(
        user, request
    )  # In case they somehow managed to log out - they've proved their identity.
    return redirect("/#/payments/claimed")
Exemplo n.º 3
0
    def RefreshPaymentState(self):
        from tapiriik.services import ServiceRecord
        from tapiriik.payments import Payments
        from tapiriik.auth import User

        external_ids = requests.get(MOTIVATO_PREMIUM_USERS_LIST_URL).json()
        connections = [
            ServiceRecord(x) for x in db.connections.find({
                "Service": "motivato",
                "ExternalID": {
                    "$in": external_ids
                }
            })
        ]
        users = list(
            db.users.find({
                "ConnectedServices.ID": {
                    "$in": [x._id for x in connections]
                }
            }))
        payments = []

        # Pull relevant payment objects and associate with users
        for user in users:
            my_connection = [
                x for x in connections
                if x._id in [y["ID"] for y in user["ConnectedServices"]]
            ][0]
            pmt = Payments.EnsureExternalPayment(self.ID,
                                                 my_connection.ExternalID,
                                                 duration=None)
            payments.append(pmt)
            User.AssociateExternalPayment(user, pmt, skip_deassoc=True)

        # Bulk-remove these payments from users who don't own them (more or less - it'll leave anyone who switched remote accounts)
        db.users.update({"_id": {
            "$nin": [x["_id"] for x in users]
        }}, {
            "$pull": {
                "ExternalPayments": {
                    "_id": {
                        "$in": [x["_id"] for x in payments]
                    }
                }
            }
        },
                        multi=True)
Exemplo n.º 4
0
def payments_claim_wait_ajax(request):
    if request.user is None:
        return HttpResponse(status=404)
    return HttpResponse(json.dumps(
        {"claimed": not Payments.HasOutstandingClaimCode(request.user)}),
                        content_type="application/json")
Exemplo n.º 5
0
def payments_promo_claim(user, code):
    promo = Payments.GetAndActivatePromo(code)
    if not promo:
        return False
    User.AssociatePromo(user, promo)
    return True