Beispiel #1
0
 def test_fails_no_content(self):
     mail = SendGrid()
     mail.api_key = app.config['SENDGRID_API_KEY']
     with self.assertRaises(ValueError):
         mail.send_email(subject='subject',
                         from_email='from',
                         to_email='to')
Beispiel #2
0
def send(self, from_email, to_email, subject, text):
    with current_app.app_context():
        sg = SendGrid(current_app)
        sg.send_email(
            from_email=from_email,
            to_email=to_email,
            subject=subject,
            text=text)
Beispiel #3
0
def invite_user(email):
    try:
        user = current_user._get_current_object()

        mail = SendGrid(app)

        mail.send_email(from_email=app.config['SENDGRID_DEFAULT_FROM'],
                        to_email=email,
                        subject='Come Join Quillio',
                        html=invite_html(user.email, email))

        flash('success Invitation Sent.')
    except Exception as e:
        flash('error Could not Create Invitation. {}'.format(e))

    return redirect(request.args.get('next') or url_for('meetings.home'))
Beispiel #4
0
def signup():
    """ Signs the Current User In """

    if request.method == 'GET':
        return render_template('auth/signup.html', form=SignupForm())

    form = SignupForm(request.form)

    if not form.validate():
        flash('error Invalid Email or Password')
        return redirect(url_for('auth.signup'))

    name = form.name.data
    email = form.email.data
    password = form.password.data

    try:
        # validate that the user does not already exist
        if User.objects(email__exact=email).count() != 0:
            flash('error An Account Is Already Using That Email.')
            return redirect(url_for('auth.login'))

        # generate activation token
        activation_token = secrets.token_urlsafe(32)
        mail = SendGrid(app)

        # send registration email
        mail.send_email(from_email=app.config['SENDGRID_DEFAULT_FROM'],
                        to_email=email,
                        subject='Welcome to Quillio',
                        html=activate_html(name, activation_token, email))

        # add user to the database
        user_datastore.create_user(
            email=email,
            name=name,
            password=hash_password(password),
            activation_hash=hash_password(activation_token),
            active=True,
            authenticated=False)

        flash('Please Check Your Email For An Activation Request.')
        return redirect(url_for('auth.login'))
    except Exception as e:
        print(str(e))
        flash('error An Error has Occured, Please Try Again!')
        return redirect(url_for('auth.signup'))
Beispiel #5
0
def forgot_password():
    """ Initializes a User's Request to Reset their Password """

    form = PasswordResetRequestForm(request.form)

    if request.method == 'GET':
        return render_template('auth/password_reset_request.html', form=form)

    if not form.validate():
        flash('error Could not Reset Password at this Time.')
        return redirect(url_for('auth.signup'))

    user = user_datastore.find_user(email=form.email.data)

    if user is None:
        flash('error Invalid Email. Please Create an Account.')
        return redirect(url_for('auth.signup'))

    # generate reset token
    reset_token = secrets.token_urlsafe(32)

    # update the user's password reset hash
    user.password_reset_hash = hash_password(reset_token)
    user.save()

    try:
        mail = SendGrid(app)

        # send the password reset email
        mail.send_email(from_email=app.config['SENDGRID_DEFAULT_FROM'],
                        to_email=user.email,
                        subject='Quillio Reset Password',
                        html=password_html(user.name, reset_token,
                                           form.email.data))

        flash('success Please Check Your Email For a Reset Confirmation.')
        return redirect(url_for('auth.login'))
    except Exception as e:
        print(str(e))
        flash('error Could Not Send Reset Request.')
        return redirect(url_for('auth.login'))
Beispiel #6
0
def start_meeting(data):
    meeting = Meeting.objects.with_id(data['room_id'])
    meeting.active = False
    meeting.save()
    emit('endMeeting', room=data['room_id'])
    update_grammar(data['room_id'])
    pt = ""
    for ts in meeting.transcript:
        pt += '{0}: {1}\\n'.format(ts.user.name, ts.transcription)
    meeting.transcriptText = pt
    meeting.save()

    try:
        # send the password reset email
        for member in meeting.members:
            mail = SendGrid(app)
            mail.send_email(from_email=app.config['SENDGRID_DEFAULT_FROM'],
                            to_email=member.email,
                            subject='Quillio Meeting Completed',
                            html=summary_html(member.name, meeting.name,
                                              meeting.get_summary()))
    except Exception as e:
        print(str(e))
Beispiel #7
0
from flask import Flask, render_template, request
from flask_sendgrid import SendGrid

key = open('/vault/secrets/api-key.txt').read()
i = key.find(":", 5)
j = key.find("]")
apikey = key[i + 1:j]

app = Flask(__name__)
app.config['SENDGRID_API_KEY'] = apikey
app.config['SENDGRID_DEFAULT_FROM'] = '*****@*****.**'
mail = SendGrid(app)


@app.route('/', methods=["POST", "GET"])
def index():
    if request.method == "POST":
        name = request.form.get("name")
        email = request.form.get("email")
        message = request.form.get("message")

        mail.send_email(to_email=email,
                        subject='Thank you for your Contact',
                        text=message)

        return render_template('index.html')

    else:
        return render_template('index.html')

Beispiel #8
0
from flask_sendgrid import SendGrid


sg = SendGrid()
Beispiel #9
0
import os

from flasgger import Swagger
from flask import Flask, render_template
from flask_login import LoginManager
from flask_sendgrid import SendGrid
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CsrfProtect

from config import config

db = SQLAlchemy()
mail = SendGrid()
csrf = CsrfProtect()

# Set up Flask-login
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'auth.signin'


def create_app(config_name):
    '''For to use dynamic environment'''
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    db.init_app(app)
    mail.init_app(app)
    csrf.init_app(app)
    login_manager.init_app(app)
Beispiel #10
0
 def setUp(self):
     self.mail = SendGrid(app)
Beispiel #11
0
__all__ = [
    'db', 'fjson', 'ip2loc', 'onedrive', 'redis', 'pat', 'sendgrid', 'sqlogger'
]

from flask_json import FlaskJSON
from flask_redis import FlaskRedis

from flask_sendgrid import SendGrid
from flask_sqlalchemy_ import SQLAlchemy
from ip2loc import IP2Loc
from onedrive import OneDrive
from pypat import Pat
from sqlalchemy_ import BaseModel
from sqlogger import SQLogger

db = SQLAlchemy(Model=BaseModel)
fjson = FlaskJSON()
ip2loc = IP2Loc()
onedrive = OneDrive()
pat = Pat()
redis = FlaskRedis()
sendgrid = SendGrid()
sqlogger = SQLogger()
Beispiel #12
0
def get_mail_context():
    """Fetch or generate SendGrid mailer object."""
    if "main" not in g:
        mail = SendGrid(current_app)
        g.mail = mail
    return g.mail
def create_mail_server(app: Flask):
    """ Setup flask mailing server """
    # Check for Testing state - set up Sendgrid if not
    if not app.config['TESTING']:
        app.mail = SendGrid(app)