コード例 #1
0
def contact():
    title = "Contact"
    IPStore(title)
    footer = "Forms are created using WTForms combined with Bootstrap 4 classes."
    mail = Mail()
    form = ContactForm()
    if request.method == 'POST':
        if form.validate() == False:
            return render_template('pages/contact.html',
                                   title=title,
                                   footer=footer,
                                   form=form)
        else:
            msg = Message(form.subject.data,
                          sender=app.config['MAIL_USERNAME'],
                          recipients=[app.config['CONTACT_EMAIL']])
            msg.body = ContactEmail(form.name.data, form.email.data,
                                    form.body.data)
            mail.send(msg)
            confirm = Message('Contact Confirmation',
                              sender=app.config['MAIL_USERNAME'],
                              recipients=[form.email.data])
            confirm.body = ConfirmationEmail(form.name.data)
            mail.send(confirm)
            return redirect(url_for('contact'))
    elif request.method == 'GET':
        return render_template('pages/contact.html',
                               title=title,
                               footer=footer,
                               form=form)
コード例 #2
0
def contact():
    form = ContactForm()
    aboutparagraphs = About.query.order_by(About.id).all()
    sent = ''
    if request.method == 'POST':
        if form.validate() == False:
            flash('All fields are required.')
            return render_template('contact.html',
                                   form=form,
                                   aboutparagraphs=aboutparagraphs)
        else:
            msg = Message(form.subject.data,
                          sender='*****@*****.**',
                          recipients=['*****@*****.**'])
            msg.body = """
            From: %s <%s>

            %s
            """ % (form.name.data, form.email.data, form.message.data)
            mail.send(msg)
            sent = 'Your message has been sent!'
            return render_template('contact.html',
                                   form=form,
                                   sent=sent,
                                   aboutparagraphs=aboutparagraphs)

    elif request.method == 'GET':
        return render_template('contact.html',
                               form=form,
                               sent=sent,
                               aboutparagraphs=aboutparagraphs)
コード例 #3
0
def send_email(data):
	form = ContactForm(data=data)
	if form.validate():
		pass
	else:
		return form

	message = mail.EmailMessage()
	message.sender = "*****@*****.**"
	message.to = "*****@*****.**"
	message.subject = "Bericht van daanlebens.com"
	message.body = """
AFZENDER:
%s
%s
%s

BERICHT:
%s
	""" % (form.name.data, form.email.data, form.phone.data, form.message.data)

	try:
		message.send()
	except:
		exc_type, exc_value, exc_traceback = sys.exc_info()
		lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
		logging.error(''.join('!! ' + line for line in lines))
	finally:
		return None
コード例 #4
0
ファイル: views.py プロジェクト: betheluniversity/classifieds
    def submit_contact(self):
        storage = request.form
        form = ContactForm(storage)
        is_external = (storage['external'] == 'True')
        if is_external:
            submitters_username = storage['email']
        else:
            submitters_username = session['username']
        contact_in_db = contact_exists_in_db(submitters_username)

        is_valid = form.validate()
        if not is_valid:
            return render_template('forms/contact.html',
                                   form=form,
                                   external=is_external,
                                   new=not contact_in_db)

        if is_external:
            if contact_in_db:
                edit_contact(submitters_username, storage['first_name'],
                             storage['last_name'], storage['email'],
                             storage['phone_number'])
                message = 'External contact information successfully edited!'
            else:
                add_contact(submitters_username, storage['first_name'],
                            storage['last_name'], storage['email'],
                            storage['phone_number'])
                message = 'External contact information successfully added!'
        else:
            edit_contact(submitters_username, storage['first_name'],
                         storage['last_name'], storage['email'],
                         storage['phone_number'])
            message = 'Contact information successfully updated!'
        return render_template('confirmation_page.html', message=message)
コード例 #5
0
 def test_form(self):
     with app.test_request_context():
         form = ContactForm(
             MultiDict([('nom', 'jerry'), ('email', '*****@*****.**')]))
         self.assertEqual(form.validate(), False)
         self.assertListEqual(form.errors['message'],
                              ['Tapez votre message'])
コード例 #6
0
def contacts():
    form = ContactForm()
    if request.method == 'POST':
        if form.validate() == False:
            flash(
                'One or more fields is either blank or filled out incorrectly. Please try again'
            )
            return render_template('contacts.html', form=form)
        else:
            msg = Message(form.subject.data,
                          sender='*****@*****.**',
                          recipients=[
                              '*****@*****.**',
                              '*****@*****.**',
                              '*****@*****.**'
                          ])
            msg.body = """
            From: %s <%s>
            %s
            """ % (form.name.data, form.email.data, form.message.data)
            mail.send(msg)
            return 'Form posted.'

    elif request.method == 'GET':
        return render_template('contacts.html', form=form)
コード例 #7
0
 def test_validate_invalid_data_is_not_submitted(self):
     """Test that the contact form does not take empty fields"""
     form = ContactForm(
         sender_name="",
         sender_email="*****@*****.**",
         sender_message="Some long message"
     )
     self.assertFalse(form.validate())
コード例 #8
0
 def test_validate_all_fields_are_filled(self):
     """Tests to check data is not submitted with empty fields"""
     form = ContactForm(
         sender_name="Virginia",
         sender_email="*****@*****.**",
         sender_message="Some long message"
     )
     self.assertTrue(form.validate())
コード例 #9
0
def contactsNew():
    form = ContactForm(request.form)
    if request.is_xhr:
        # ajax request
        data = form.data
        try:
            # search contact doc
            contact = db.contacts.find_one({
                'firstname':
                request.form['firstname'],
                'email':
                request.form['email']
            })
            if contact:
                # add article to contact
                db.contacts.update(
                    {
                        'firstname': request.form['firstname'],
                        'email': request.form['email']
                    }, {'$addToSet': {
                        'articles': request.form["article_id"]
                    }},
                    upsert=True)
                return jsonify(status=1,
                               msg='Article added to contact document')
            else:
                # no contact found: create a new one and insert article
                data['articles'] = [request.form["article_id"]]
                data['preferences'] = {'articles_notify': 'default'}
                data['notify_queue'] = []
                db.contacts.insert_one(data)
                return jsonify(status=1, msg='New contact added')
        except PyMongoError as e:
            print(e)
            #data['articles'] = [request.form["article_id"]]
            #db.contacts.insert_one(data)
            return jsonify(status=0, msg='Error:' + e)

    elif request.method == "POST" and form.validate():
        # post request
        db.contacts.replace_one(
            {
                'firstname': request.form['firstname'],
                'email': request.form['email']
            },
            form.data,
            upsert=True)
        flash('New contact  %s added' % (form.data['firstname']))
        return redirect('/contacts')
    else:
        return render_template('backend/contacts/edit.html',
                               form=form,
                               title='New contact')
コード例 #10
0
def contact():
    """
    Allow the customers to contact our team for support and help
    Here is the contact us function
    This uses the parameters in the class app.forms.ContacttForm


    """

    if (current_user.is_authenticated):
        title = "Contact Us By User"
    else:
        title = "Contact Us"
    formLogout = LogoutForm()

    formContact = ContactForm()
    if formLogout.Logout.data and formLogout.is_submitted():
        return redirect(url_for('logout'))
    """
      This first if statement takes in the fromContact  all the information filled
      out by the user and organizes it in the message show below and send the the information
      to the a support email.
    """
    if request.method == 'POST':
        if formContact.validate() == False:
            flash('All fields are required.')
            return render_template('Contact.html',
                                   formContact=formContact,
                                   title=title)
        else:
            msg = Message(formContact.subject.data,
                          sender='*****@*****.**',
                          recipients=['*****@*****.**'])
            msg.body = f"""
                  From:              {formContact.name.data} 
                  Email:             {formContact.email.data} 
                  Phone Number:      {formContact.phone_number.data} 
                  Subject:           {formContact.subject.data} 
                  Message:           {formContact.message.data}
                  """
            mail.send(msg)

            return render_template('Contact.html', title=title, success=True)

    elif request.method == 'GET':
        return render_template("Contact.html",
                               title=title,
                               formContact=formContact,
                               formLogout=formLogout)
    """
コード例 #11
0
def contact():
    form = ContactForm()
    question = "Oslo"
    if request.method == 'POST' and form.validate():
        message = Message(
                subject="New message has been sent through your website",
                recipients=[credentials.get('username')])
        message.body = f"""From:{form.name.data} and from email
                        {form.email.data} and message {form.message.data}."""
        if form.question.data == question:
            mail.send(message)
        return render_template("thanks.html")
    else:
        return render_template("contact.html", title='Contact Page', form=form)
コード例 #12
0
def contact():
    form = ContactForm()
    if request.method == 'POST':
        if form.validate() == False:
            flash('All fields are required.')
            return render_template('contact.html', form = form)
        else:
            msg = Message(form.subject.data, sender = '*****@*****.**', recipients = [Config.MAIL_USERNAME])
            
            msg.body = """
                        From: %s <%s> %s
                       """ % (form.name.data, form.email.data, form.message.data)
            mail.send(msg)
            return render_template('contact.html', success=True)

    elif request.method == 'GET':
        return render_template('contact.html', form = form)
コード例 #13
0
ファイル: views.py プロジェクト: nandopedrosa/as_mais_lidas
def send_message():
    """
    Sends a contact message
    :return: a JSON file with status code (OK/ERROR). If an error occurs, the JSON file also has a list with the error
    messages and related fields
    """
    form = ContactForm(request.form)

    if form.validate():
        form.errors["error"] = False
        form.errors["status"] = gettext("Message successfully sent")
        send_email(form.name.data, form.email.data, form.message.data)
    else:
        form.errors["status"] = gettext("Your message could not be sent")
        form.errors["error"] = True

    return jsonify(form.errors)
コード例 #14
0
def contact():
    form = ContactForm()
    if request.method == 'POST':
        if form.validate() == False:
            flash('All fields are required.')
            return render_template('contact.html', form=form)
        else:
            msg = Message(form.object.data,
                          sender='Symeon',
                          recipients=['*****@*****.**'])
            msg.body = """
            From: %s <%s>
            %s
            """ % (form.name.data, form.email.data, form.message.data)
            mail.send(msg)

            return render_template('contact.html', success=True, form=form)
    elif request.method == 'GET':
        return render_template('contact.html', form=form)
コード例 #15
0
def contactsEdit(id):
    try:
        contact = db.contacts.find_one({'_id': ObjectId(id)})
        form = ContactForm(data=contact)
        if request.method == "POST" and form.validate():
            form = ContactForm(request.form)
            db.contacts.replace_one({'email': form.data['email']},
                                    form.data,
                                    upsert=True)
            return redirect('/admin/contacts')
        else:
            return render_template('backend/contacts/edit.html',
                                   form=form,
                                   title='Contact: ' + contact['firstname'])
    except Exception as e:
        flash("Couldn't update contact %s" % (form.data['firstname']))
        return render_template('backend/contacts/edit.html',
                               form=form,
                               title='New contact')
コード例 #16
0
def contact():

    form = ContactForm(request.form)
    if request.method == "POST":
        name = request.form["name"]
        email = request.form["email"]
        message = request.form["message"]

        if form.validate():
            msg = Message(
                subject="Heatmap feedback from {}".format(name),
                sender=email,
                recipients=[current_app.config["MAIL_USERNAME"]],
            )
            msg.body = message
            mail.send(msg)
            flash("Thank you, {}. Your message has been sent.".format(name), "info")

    return render_template("contact.html", form=form)
コード例 #17
0
def contact():
    form = ContactForm()
    if request.method == 'POST':
        if form.validate() == False:
            flash('All fields are required.')
            return render_template('contact.html', form=form)
        else:
            # Post request to mailgun API
            requests.post(mailgun_url,
                          auth=("api", mailgun_api),
                          data={
                              "from": "*****@*****.**",
                              "to": form.email.data,
                              "subject": form.subject.data,
                              "text": form.message.data
                          })
            return render_template('contact.html', success=True)

    elif request.method == 'GET':
        return render_template('contact.html', form=form, title='Contact Us')
コード例 #18
0
def index():
    schedule = Schedule.query.all()
    roster = Roster.query.order_by('name').all()

    mail.init_app(app)

    form = ContactForm(request.form)

    if request.method == 'POST' and form.validate():
        msg = Message("Message from " + form.name.data,
                      sender=MAIL_USERNAME,
                      recipients=[MAIL_USERNAME])
        msg.body = """
        From: %s <%s>
        %s
        """ % (form.name.data, form.email.data, form.message.data)
        mail.send(msg)
        return redirect(url_for("index"))

    return render_template("index.html",
                           schedule=schedule,
                           roster=roster,
                           form=form)
コード例 #19
0
ファイル: views.py プロジェクト: nandopedrosa/as_mais_lidas
def send_message():
    """
    Sends a contact message
    :return: a JSON file with status code (OK/ERROR). If an error occurs, the JSON file also has a list with the error
    messages and related fields
    """
    form = ContactForm(request.form)

    if form.validate():
        status_code = send_email(form.name.data, form.email.data,
                                 form.message.data)
        #200 codes, success
        if not str(status_code).startswith('20'):
            form.errors['error'] = True
            form.errors['status'] = gettext('Your message could not be sent')
        else:
            form.errors['error'] = False
            form.errors['status'] = gettext('Message successfully sent')
    else:
        form.errors['status'] = gettext('Your message could not be sent')
        form.errors['error'] = True

    return jsonify(form.errors)
コード例 #20
0
ファイル: routes.py プロジェクト: FeLoe/3bij3
def contact():
    form = ContactForm()
    if request.method == 'POST':
        if form.validate() == False:
            return 'Vul alstublieft alle velden in <p><a href="/contact">Probeer het opnieuw!!! </a></p>'
        else:
            name =  current_user.username
            id = str(current_user.id)
            email =  form.email.data
            if not email or email == []:
                email = 'no_address_given'
            msg = Message("Message from your visitor " + name + "with ID: " + id,
                          sender= email,
                          recipients= ['*****@*****.**'])
            msg.body = """
            From: %s <%s>,
            %s
            %s
            """ % (name, email, form.lead.data, form.message.data)
            mail.send(msg)
            return redirect(url_for('count_logins'))
    elif request.method == 'GET':
        return render_template('contact.html', form=form)
コード例 #21
0
def contact():
    if (current_user.is_authenticated):
        title = "Contact Us By User"
    else:
        title = "Contact Us"
    formLogout = LogoutForm()

    formContact = ContactForm()
    if formLogout.Logout.data and formLogout.is_submitted():
        flash('Logged out')
        return redirect(url_for('logout'))
    if request.method == 'POST':
        if formContact.validate() == False:
            flash('All fields are required.')
            return render_template('Contact.html',
                                   formContact=formContact,
                                   title=title)
        else:
            msg = Message(formContact.subject.data,
                          sender='*****@*****.**',
                          recipients=['*****@*****.**'])
            msg.body = f"""
                  From:              {formContact.name.data} 
                  Email:             {formContact.email.data} 
                  Phone Number:      {formContact.phone_number.data} 
                  Subject:           {formContact.subject.data} 
                  Message:           {formContact.message.data}
                  """
            mail.send(msg)

            return render_template('Contact.html', title=title, success=True)

    elif request.method == 'GET':
        return render_template("Contact.html",
                               title=title,
                               formContact=formContact,
                               formLogout=formLogout)
コード例 #22
0
ファイル: test_forms.py プロジェクト: professorlust/Hadithi
 def test_validate_invalid_email_format_is_not_submitted(self):
     """Test that the contact form does not take empty fields"""
     form = ContactForm(sender_name="Virginia",
                        sender_email="virginia",
                        sender_message="Some long message")
     self.assertFalse(form.validate())
コード例 #23
0
ファイル: test_forms.py プロジェクト: professorlust/Hadithi
 def test_validate_all_fields_are_filled(self):
     """Tests to check data is not submitted with empty fields"""
     form = ContactForm(sender_name="Virginia",
                        sender_email="*****@*****.**",
                        sender_message="Some long message")
     self.assertTrue(form.validate())
コード例 #24
0
ファイル: test_forms.py プロジェクト: professorlust/Hadithi
 def test_validate_empty_message_is_not_submitted(self):
     """Test that the contact form does not take empty fields"""
     form = ContactForm(sender_name="",
                        sender_email="*****@*****.**",
                        sender_message="")
     self.assertFalse(form.validate())