Esempio n. 1
0
def create_user():
    form = RegistrationForm(request.form)
    if form.validate():
        user = User(username = form.email.data)
        user.set_and_encrypt_password(form.password.data)
        user.put()
        login(user)
        flash(u'Thanks for registering')
        return redirect(url_for('subscribe'))   
    return redirect(url_for('new_user'))
Esempio n. 2
0
def facebook_authorized(resp):
    if resp is None:
        flash(u'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        ))
        return redirect(url_for('home'))
    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    user = User.get_by_username(me.data['email'])
    if user is not None:
        login(user)
    else:
        user = User(username=me.data['email'], name=me.data['name'])
        user.put()
        login(user)
    flash(u"You've logged in with Facebook")
    return redirect(url_for('subscribe'))
Esempio n. 3
0
def account():
    user = User.load_current_user()
    stripe.api_key = STRIPE_SECRET
    try:
        customer = stripe.Customer.retrieve(user.stripe_customer_id)
    except:
        customer = False
    mail = MailingAddress.get_by_username(user.username)
    return render_template('account.html', customer=customer, mail=mail)
Esempio n. 4
0
def cancel_subscription():
    user = User.load_current_user()
    stripe.api_key = STRIPE_SECRET
    try:
        cu = stripe.Customer.retrieve(user.stripe_customer_id)
        cu.cancel_subscription()
        flash(u'Successfully Canceled')
    except:
        pass
    return redirect(url_for('account'))
Esempio n. 5
0
def login_view():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User.get_by_username(form.email.data)
        if user is not None:
            # Authenticate and log in!
            if user.authenticate(form.password.data):
                flash(u'Logged in')
                return redirect(url_for('subscribe'))
        return 'Failure :('
    return render_template('login.html', form=form)    
Esempio n. 6
0
def update_address():
    user = User.load_current_user()    
    form = AddressForm(request.form)
    m = MailingAddress.get_by_username(user.username)
    m.name = form.name.data
    m.address1 = form.address1.data
    m.address2 = form.address2.data
    m.zipcode = form.zipcode.data
    m.city = form.city.data
    m.state = form.state.data 
    m.country = form.country.data
    m.put()
    return redirect(url_for('account'))
Esempio n. 7
0
def subscribe():
    form = StripeSubscriptionForm(request.form)
    if request.method == 'POST':
        stripe.api_key = STRIPE_SECRET

        user = User.load_current_user()
        customer = stripe.Customer.create(
            card=form.stripeToken.data,
            plan="regular",
            email=user.username
        )
        user.stripe_customer_id = customer.id
        user.put()
        m = MailingAddress(username=user.username, name=form.name.data, address1 = form.address1.data,\
            address2=form.address2.data, zipcode=form.zipcode.data, city=form.city.data, state=form.state.data, country=form.country.data)
        m.put()
        return redirect(url_for('account'))
    return render_template('subscribe.html', form=form, pub_key=STRIPE_PUB_KEY)
Esempio n. 8
0
def subscribe():
    form = StripeSubscriptionForm(request.form)
    if request.method == 'POST':
        stripe.api_key = STRIPE_SECRET

        user = User.load_current_user()
        customer = stripe.Customer.create(
            card=form.stripeToken.data,
            plan="regular",
            email=user.username
        )
        user.stripe_customer_id = customer.id
        user.put()
        m = MailingAddress(username=user.username, name=form.name.data, address1 = form.address1.data,\
            address2=form.address2.data, zipcode=form.zipcode.data, city=form.city.data, state=form.state.data, country=form.country.data)
        m.put()
        context = dict()
        bodytext = render_template_string('emails/confirmation.txt', context=context)
        bodyhtml = render_template('emails/confirmation.html', context=context)
        mail.send_mail(sender="<*****@*****.**>", to=user.username,
                           subject="Welcome to the Club", body=bodytext, html=bodyhtml)
        return redirect(url_for('account'))
    return render_template('subscribe.html', form=form, pub_key=STRIPE_PUB_KEY)
Esempio n. 9
0
def inject_user():
    user = User.load_current_user()
    if user:
        return dict(user=user)
    return dict()
Esempio n. 10
0
def edit_address():
    user = User.load_current_user()
    mail = MailingAddress.get_by_username(user.username)
    form = AddressForm(obj=mail)
    return render_template('address_edit.html', form=form)