예제 #1
0
def change_email(firstname, new_email, current_email):

    # ----- create Token :

    payload = {
        'new_email': new_email,
        'current_email': current_email,
    }

    token = s.dumps(payload, salt='change_email')

    # ----- create validation link
    link = url_for('app_user.update_email', token=token, _external=True)

    # -----
    msg = Message('Confirm your new email address',
                  sender=(app.config['MAIL_DEFAULT_SENDER'],
                          app.config['MAIL_USERNAME']),
                  recipients=[new_email])

    msg.html = render_template('email_change_address.html',
                               name=firstname,
                               link=link,
                               logo=app.config['MAIL_LOGO'],
                               new_email=new_email)
    mail.send(msg)
예제 #2
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request', recipients=[user.email])
    msg.body = f'''To reset your password, visit the following link:
{url_for('main.reset_token', token=token, _external=True)}
If you did not make this request then simply ignore this email and no changes will be made.
'''
    mail.send(msg)
예제 #3
0
def send_mail(category_id, category_name):
    with app.app_context():
        category = Category(category_name)
        category.id = category_id
        message = Message("New category added",
                          recipients=['*****@*****.**'])
        message.body = render_template("category-create-email-text.html",
                                       category=category)
        message.html = render_template("category-create-email-html.html",
                                       category=category)
        mail.send(message)
예제 #4
0
def reset_password():
    # This Router is use when User Forgets the password.
    # It will send email with link to fronted to create new password
    try:
        encoded_jwt = retrive_data()['token']
        token = jwt.decode(encoded_jwt, app.config['SECRET_KEY'])

        current_user = Trava_Users.query.filter_by(
            email=token['email']).first()

        if not current_user:
            return jsonify({
                'message':
                'The email you’ve entered doesn’t match any account!',
                'state': 'error'
            }), 400

        # ----- create link to frontend
        link = f'{app.config["FRONTEND_BASE_URL"]}password/reset/token/?token={encoded_jwt}'

        # ----- send the email
        msg = Message('Password Reset',
                      sender=(app.config['MAIL_DEFAULT_SENDER'],
                              app.config['MAIL_USERNAME']),
                      recipients=[current_user.email])

        msg.html = render_template('email_reset_password.html',
                                   name=current_user.firstname,
                                   link=link,
                                   logo=app.config['MAIL_LOGO'])
        mail.send(msg)

        return jsonify({
            'message':
            f'An email with the password reset link was sent to {current_user.email}',
        })

    except ExpiredSignatureError:
        return jsonify({
            'message': 'Token has expired!',
            'state': 'error'
        }), 408

    except InvalidSignatureError:
        return jsonify({'message': 'Invalid Token!', 'state': 'error'}), 401
예제 #5
0
def send_activtion_link(email, firstname):

    token = s.dumps(email, salt='validate_email')

    # ----- create validation link
    link = url_for('app_user.validate_email', token=token, _external=True)

    # -----
    msg = Message('Email Confirmation',
                  sender=(app.config['MAIL_DEFAULT_SENDER'],
                          app.config['MAIL_USERNAME']),
                  recipients=[email])

    msg.html = render_template('email_validation.html',
                               name=firstname,
                               link=link,
                               logo=app.config['MAIL_LOGO'])
    mail.send(msg)
예제 #6
0
def send_mail(message):
    with app.app_context():
        mail.send(message)
def send_mail(message):
    with app.app_context():
        mail.send(message)
예제 #8
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
예제 #9
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)