Beispiel #1
0
def sendActivationEmail(user):
  with app.app_context():
    dump = { 'id': user.id, 'email': user.email, 'activation':True }
    token = Serializer(app.config['JWT_SECRET_KEY']).dumps(dump).decode('ascii')
    msg = Message(ActivateUserSubject, sender = 'smarticket.support', recipients = [user.email])
    msg.html = "<a href='"+host+"/api/activate/user/"+token+"'>Activar</a>"
    mail.send(msg)
    def post(self):
        claims = get_jwt_claims()
        user = _db.session.query(User).filter_by(id=claims["id"]).first()

        if user is None:
            return make_response(jsonify({"error": "Invalid user id"}), 400)

        if user.appid is not None:
            return make_response(
                jsonify({"error": "The user already have a app-id"}), 400)

        if not user.active:
            return make_response(
                jsonify({"error": "The user is not activated"}), 400)

        user.generate_api_key()
        _db.session.commit()

        msg = Message("Hello",
                      sender=current_app.config["MAIL_USERNAME"],
                      recipients=[
                          user.email,
                      ])
        msg.html = current_app.config["API_KEY_TEMPLATE"].format(user.appid)
        mail.send(msg)
        return make_response(jsonify({"appid": user.appid}), 200)
Beispiel #3
0
    def post(self):
        args = self.reqparse.parse_args()
        if User.query.filter_by(username=args.get("username")).first():
            return UserDto(error="That username already exists"), 400

        if User.query.filter_by(email=args.get("email")).first():
            return UserDto(error="That email already exists"), 400

        new_user = User.create_user(args["username"], args["email"])
        new_user.set_password(args["password"])
        link = ConfirmationLink.create_link()
        new_user.links.append(link)

        _db.session.add(new_user)
        _db.session.commit()

        msg = Message(
            "Hello",
            sender="*****@*****.**",
            recipients=[
                new_user.email if not current_app.config.get("TEST_EMAIL") else
                current_app.config["TEST_EMAIL"]
            ])
        msg.html = current_app.config["REGISTER_TEMPLATE"].format(link.link)
        mail.send(msg)
        # send_async_email.delay(msg)
        dto = UserDto(username=str(new_user.username),
                      email=str(new_user.email),
                      id=new_user.id,
                      status=new_user.active)
        return dto, 201
Beispiel #4
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',sender='*****@*****.**',recipients=[user.email])
    msg.body = """ To reset your password, visit the following link:
{}
If you did not make this request then simply please ignore the message and no changes will be made
""".format(url_for('users.reset_token',token=token,_external=True))
    mail.send(msg)
Beispiel #5
0
def send_password_reset_email(user):
    token = user.get_password_reset_token()
    # msg = Message("Password Reset Request from Flask-Starter-App", sender='*****@*****.**', recipients=[user.email])
    msg = Message("Password Reset Request", recipients=[user.email])
    msg.body = f'''Visit the following link to reset your password:
    {url_for('auth.reset_password', token=token, _external=True)}
    If you did not make this request then simply ignore this email and nothing will be changed.
    '''
    mail.send(msg)
Beispiel #6
0
def send_reset_email(user):
    """function that generates a reset email message with reset token"""
    token = user.get_reset_token()
    msg = Message('Password Reset Request', sender='*****@*****.**', recipients=[user.email])
    msg.body = f'''To reset your password, visit the following link:
{url_for('users.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)
def send_reset_email(user):
    token = user.get_reset_token()
    message = Message('Password Reset Request',
                      sender='*****@*****.**',
                      recipients=[user.email])
    message.body = f'''To reset your Password
{url_for('users.reset_token', token=token, _external=True)}
If you did not request this, then simply ignore this.
'''
    mail.send(message)
Beispiel #8
0
def send_delete_account_email(user):

    msg = Message('Account Delete on Requisition and supply management system',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''Your account was deleted on Requisition and supply managment System. 
You account was deleted by {current_user.email} 
Please contact the admin if you think this was a mistake.

This is an auto generated mail. Please do not reply. 
    '''
    mail.send(msg)
Beispiel #9
0
def send_reset_email(user):
    token = user.get_reset_token()

    msg = Message('Password reset request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password visit the following link
{url_for('reset_token', token = token, _external = True)}
If you did not make this request then simply ignore this email and no changes will be made
This url will expire in 30 min.

This is an auto generated mail. Please do not reply. 
    '''
    mail.send(msg)
Beispiel #10
0
def send_create_user_email(user, password):

    msg = Message('Password for requisition and supply management system',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''Your account has been created on Requsition and supply management system. 
You have been added as a user by {current_user.email} 
You can login using the below credentials 
Email : {user.email}
Password : {password}
Feel free to change the password after login in. 

This is an auto generated mail. Please do not reply. 
    '''
    mail.send(msg)
Beispiel #11
0
def send_reset_password_email(user):
    token = user.get_password_reset_token()
    message = Message('Sraideanna! - Password Reset Request',
                      sender='*****@*****.**',
                      recipients=[user.email])
    message.body = f"""Hi, {user.username}. 

It seems you've requested a password change. Please visit the following link: 

{url_for('reset_password_token', token=token, _external=True)}

If you did not request a password change, then ignore this email.

Le gach dea-ghuí,
Sraideanna!
"""
    mail.send(message)
Beispiel #12
0
def sendResetEmail(user):
    """
    Send password reset request to user's email address if request.

    :type user: user
    :param user: user details such as email address and token.
    """

    # get user token
    token = user.getResetToken()

    # message from and recipients
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])

    # message body with absolute url path
    msg.body = f'''To reset your password, visit the following link:
{url_for('user.resetToken', token=token, _external=True)}
    
If you did not make this request then simply ignore this email.
'''
    # send email
    mail.send(msg)
Beispiel #13
0
def SyncSendMsg(app, msg):
    with app.app_context():
        mail.send(msg)
Beispiel #14
0
def send_async_email(App, msg):
    with App.App_context():
        mail.send(msg)
Beispiel #15
0
    def post(self):
        _json = buyConfirmation.parse_args()
        tickets = json.loads(_json["tickets"])
        event = DB.Event.get(_json["event"])

        print(event["thumbnail"])
        image = ast.literal_eval(event["thumbnail"])
        trs = ""
        for i in range(len(tickets)):
            trs += '<tr>\
            <td style="width: 25%;">\
              <a href="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' + tickets[
                i]["ethereumHash"] + '">\
                <img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=' + tickets[
                    i]["ethereumHash"] + '" alt="">\
              </a>\
            </td>\
            <td>\
              <h4> <b>Zona</b> ' + tickets[i]["zone"] + '</h4>\
              <h4> <b>Asiento</b> ' + tickets[i]["seat"] + '</h4>\
              Hash: ' + tickets[i]["ethereumHash"] + '\
            </td>\
          </tr>'

        str = '\
<html lang="en">\
  <head>\
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">\
    <style>\
      #customers {font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;border-collapse: collapse;width: 100%;}\
      #customers td, #customers th { border: 1px solid #ddd;padding: 8px;}\
      #customers tr:nth-child(even){background-color: #f2f2f2;}\
      #customers tr:hover {background-color: #ddd;}\
      #customers th {padding-top: 12px;padding-bottom: 12px;text-align: left;background-color: #039be5;color: white;}\
    </style>\
  </head>\
  <body>\
    <table id="customers">\
        <tr>\
            <th><a href="' + host + '"><h1 style="text-align: center;">SmarTicket</h1></a></th>\
        </tr>\
    </table>\
    <table>\
        <tr>\
          <td>\
            <div class="col s2" style="padding:30px;">\
              <a href="' + host + '/MostrarEvento/"' + event["_id"] + '>\
                <img style="display:block; width:150px; height:150px" id="base64image"\
                src="data:' + image["filetype"] + '+;base64,' + image[
            "value"] + '" />\
              </a>\
            </div>\
          </td>\
          <td>\
            <div class="col s8">\
              <h5>' + event["name"] + '</h5>\
              <h5> <b> Lugar: </b> ' + event["place"] + '</h5> <br> \
              <h5> <b> Fecha y hora: </b> ' + event["date"] + '</h5> <br>\
              <h5> <b> ID: </b> ' + event["_id"] + '</h5> <br>\
            </div>\
          </td>\
        </tr>\
    </table>\
      <table id="customers">' + trs + '</table>\
    </div>\
  </body>\
</html>'

        msg = Message("Confirmación de pago",
                      sender='smarticket.support',
                      recipients=[_json["email"]])
        msg.html = str
        mail.send(msg)
        return {"success": True, "message": "sent"}, 200
Beispiel #16
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
Beispiel #17
0
def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    mail.send(msg)