示例#1
0
文件: views.py 项目: luckypupil/foodo
def profile(id):
    rest = Rest.query.get_or_404(id)
    form = SubscribeForm()
    othercomments, foodcomments = getLatestComm(id)
    if form.validate_on_submit():
        if not db.session.query(User).\
                filter(User.email == form.data['email']).first():
            u = User(form.data['email'], form.data['zipcd'],
                     form.data['first_name'], form.data['last_name'])
            db.session.add(u)
            db.session.commit()
            flash('Thanks for your submission!')
        else:
            flash('Looks like we already have your email on our list!')
    try:
        pass
        ###Need to add session so geo of user persits to profile page
        #rest.dist = getDist(fromLat=session.lat,fromLng=session.lng,toLat=rest.lat,toLng=rest.lng)
    except:
        pass
    return render_template('profile.html',
                           rest=rest,
                           foodcomments=foodcomments,
                           othercomments=othercomments,
                           form=form)
示例#2
0
def subscribe():
    subscribe_form = SubscribeForm()

    # Checks if the form has been submited
    if subscribe_form.validate_on_submit():
        first_name = subscribe_form.first_name.data
        last_name = subscribe_form.last_name.data
        email = subscribe_form.email.data
        expertise = subscribe_form.expertise.data

        fieldnames = ['first_name', 'last_name', 'email', 'expertise']
        with open('data/mailingList.csv', 'a+') as inFile:
            writer = csv.DictWriter(inFile, fieldnames=fieldnames)
            writer.writerow({
                'first_name': first_name,
                'last_name': last_name,
                'email': email,
                'expertise': expertise
            })
        flash('Thanks for Subscribing!', 'success')
        return redirect(url_for('home'))

    return render_template('subscribe.html',
                           subscribe_form=subscribe_form,
                           name=current_user)
示例#3
0
def subscribe():
    form = SubscribeForm()
    if form.validate_on_submit():
        email = form.email.data
        flash('Welcome on board!')
        send_email('Subscribe Success!', email,
                   'Hello, thank you for subscribing Flask Weekly!')
        return 'Subscribe Success!'
    return render_template('subscribe.html', form=form)
示例#4
0
文件: app.py 项目: baihtjs/MyFlask
def subscribe():
    form = SubscribeForm()
    if form.validate_on_submit():
        email = form.email.data
        name = form.name.data
        send_subscribe_mail('hello subscribe', email, name=name)
        flash('Send the subscribe email!')
        return redirect(url_for('index'))
    return render_template('subscribe.html', form=form)
示例#5
0
def subscribe():
    form = SubscribeForm()
    if form.validate_on_submit():
        to = form.to.data
        subject = form.subject.data
        body = form.body.data
        send_mail(subject, to, name=body)
        flash("Subscribe success!")
        return redirect(url_for('index'))
    return render_template('subscribe_form.html', form=form)
示例#6
0
文件: views.py 项目: luckypupil/foodo
def subscribe():
    form = SubscribeForm()
    if form.validate_on_submit():
        if not db.session.query(User).\
                filter(User.email == form.data['email']).first():
            u = User(form.data['email'], form.data['zipcd'],
                     form.data['first_name'], form.data['last_name'])
            db.session.add(u)
            db.session.commit()
            flash('Thanks for your submission!')
        else:
            flash('Looks like we already have your email on our list!')
    return render_template('subscribe.html', form=form)
示例#7
0
def subscribe():
    form = SubscribeForm()  # creating an instance of SubscribeForm
    if form.validate_on_submit():

        # The message that will be sent in the email
        message = "Thank you for visiting the One Piece Character Introduction Site! You have successfully been subscribed to the newsletter and will receive updates on One Piece."
        # Creating the gmail server
        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.starttls()
        # The gmail account that will be used to send the email (email and password to log in)
        server.login("*****@*****.**", "PASSWORD")
        words = 'Subject: {}\n\n{}'.format('One Piece Newsletter', message)
        server.sendmail("*****@*****.**", form.email.data, words)
        server.quit()
        flash(
            'Thank you {} for subscribing to the newsletter! An email has been sent to your account'
            .format(form.name.data), 'success')
        return redirect('/Subscribe')
    return render_template('Subscribe.html', form=form)
示例#8
0
def subscribe():
    form = SubscribeForm(request.form, csrf_enabled=False)

    if form.validate_on_submit():
        subscriber = Subscriber.objects(email=form.email.data).first()

        if not subscriber:
            subscriber = Subscriber(email=form.email.data, name=form.name.data)
            subscriber.save()

        else:
            if subscriber.name != form.name.data:
                subscriber.update(set__name=form.name.data)

        subscriber.mark_subscribed()

        if request_wants_json():
            return jsonify(errors=False)
    else:
        if request_wants_json():
            errors = {n: v[0] for n, v in form.errors.items()}
            return jsonify(errors=errors)

    return redirect(request.args.get('next') or url_for('site.index'))