Exemplo n.º 1
0
Arquivo: views.py Projeto: DickJ/fitu
def unsubscribe():
    """
    Process a request to unsubscribe and return the template
    """
    form = UnsubscribeForm()
    # If the form has been submitted
    if form.validate_on_submit():
        # Open db connection
        conn, cur = u_db.get_db_conn_and_cursor(app.config)

        # If all data is valid
        phone = u_views.is_valid_number(form.phone.data)
        print(phone)
        if phone:
            # If phone number does not already exist as a verified user
            cur.execute(
                'SELECT provider FROM verified WHERE phone=%s AND fname=%s and lname=%s;',
                [
                    phone,
                    form.fname.data.upper().rstrip(),
                    form.lname.data.upper().rstrip()
                ])
            user = cur.fetchone()
            if user:
                # Process unsubscribe request
                confcode = random.getrandbits(16)
                flashmsg = u_views.unsubscribe_user(cur, phone, confcode)
                subject = 'VT-3 Notifications'
                smstxt = "Click the link to unsubscribe. %s%s%d" \
                         % (app.config['BASE_URL'], '/unsubscribe/', confcode)
                # Send Text Message
                tc = TextClient(debug=app.config['DEBUG'])
                response = tc.send_message(phone, subject, smstxt, user[0])

                #flash(flashmsg)
                #return redirect('/')
            else:
                # Alert user this was an invalid unsubscribe request
                flashmsg = 'Data does not match anyone in our database. Please confirm name spelling and phone number.'

        else:
            flashmsg = 'Invalid phone number. Please try again.'
            form.phone.errors.append("Invalid format.")

        flash(flashmsg)
        conn.commit()
        print('committing')
        cur.close()
        conn.close()

    return render_template("unsubscribe.html", form=form)
Exemplo n.º 2
0
Arquivo: views.py Projeto: DickJ/fitu
def verify_unsubscribe(confcode):
    logging.debug({'func': 'verify_unsubscribe', 'confcode': confcode})

    conn, cur = u_db.get_db_conn_and_cursor(app.config)

    cur.execute("SELECT (phone) FROM unsubscribe WHERE confcode=%s",
                [confcode])
    d = cur.fetchone()
    if d:
        cur.execute('DELETE FROM verified WHERE phone=%s', [d[0]])
        cur.execute('DELETE FROM unsubscribe WHERE phone=%s', [d[0]])
        conn.commit()
        logging.info({
            'func': 'verify_unsubscribe',
            'phone': d[0],
            'msg': 'successfully unsubscribed'
        })
        msg = "You have been successfully unsubscribed."
    else:
        logging.info({
            'func': 'verify_unsubscribe',
            'confcode': confcode,
            'msg': 'invalid unsubscribe code'
        })
        msg = "ERROR: The supplied confirmation code is not valid."

    cur.close()
    conn.close()

    return render_template("unsubscribe.html", form=UnsubscribeForm(), msg=msg)
Exemplo n.º 3
0
def channels():
    channels = Channel.query.all()
    form_sub = SubscribeForm()
    form_unsub = UnsubscribeForm()
    return render_template('channels.html',
                           channels=channels,
                           form_sub=form_sub,
                           form_unsub=form_unsub)
Exemplo n.º 4
0
def unsubscribe():
    form = UnsubscribeForm()
    if form.validate_on_submit():
        sf_response = unsubscribe_user(form.email.data)
        previously = False
        if ('previously' in sf_response.keys()):
            previously = sf_response['previously']
        unsubscribe = Unsubscribe(email=form.email.data,
                                  address=form.address.data,
                                  sf_response=sf_response['status_code'],
                                  previously=previously)
        db.session.add(unsubscribe)
        db.session.commit()

        data = {'email': form.email.data, 'previously': previously}
        if sf_response['status_code'] == 200:
            return jsonify(data), 200
        else:
            return jsonify(data), 500
    else:
        return '', 500
Exemplo n.º 5
0
def index():
    script_id = 'home'
    if request.headers.getlist("X-Forwarded-For"):
        address = request.headers.getlist("X-Forwarded-For")[0].split(',')[0]
    else:
        address = request.remote_addr
    email = request.args.get('email')
    form = UnsubscribeForm(email=email, address=address)
    return render_template('home.html',
                           script_id=script_id,
                           email=email,
                           form=form,
                           address=address,
                           title="Unsubscribe")
Exemplo n.º 6
0
def unsubscribe():
    form = UnsubscribeForm()
    #    if form.validate_on_submit():
    channel = Channel.query.get(form.channel.data)
    if not channel:
        raise DownloadError('Channel \'{}\' not found'.format(
            form.channel.data))

    for video in Video.query.with_parent(channel).all():
        db.session.delete(video)

    db.session.delete(channel)
    db.session.commit()

    return redirect('/channels')
Exemplo n.º 7
0
def unsubscribe(request):
    if request.method == "POST":
        form = UnsubscribeForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            user_email = get_object_or_404(UserEmail, email=email)
            if user_email.verified:
                send_unsubscribe_email.delay(email, 0)
            user_email.verified = False
            user_email.save()
            CategoryNotification.objects.filter(user=user_email).delete()
            return render(
                request, 'subscribe.html', {
                    'icon': 'img/cry.svg',
                    'text': 'Schade! Wir sehen dich hoffentlich bald wieder.',
                    'showBack': True
                })
    else:
        form = UnsubscribeForm()

    return render(request, 'unsubscribe.html', {
        'form': form,
        'email': request.GET.get('email', '')
    })