Esempio n. 1
0
def _report_failure_to_admin(deploy_id, report):

    email = session["user_email"]
    from_email = "*****@*****.**"

    link = url_for("result", deploy_id=deploy_id, _external=True)
    body_html = """ <html>
                        <head></head>
                        <body>
                          <p>Error ocurred for deployment (%(deploy_id)s) for user %(email)s<p>
                          <pre>%(report)s</pre>
                          <p>Check it in:</p>
                          <ul>
                            <li>%(link)s</li>
                          </ul>
                          <p>Best regards,</p>
                          <p>wCloud system</p>
                        </body>
                      </html>""" % dict(
        link=link, deploy_id=deploy_id, email=email, report=report
    )
    print (body_html)
    body = """Error ocurred in wCloud."""
    subject = "wCloud failure"

    utils.send_email(app, body, subject, from_email, app.config["ADMINISTRATORS"], body_html)
Esempio n. 2
0
def _report_failure_to_admin(deploy_id, report):

    email = session['user_email']
    from_email = '*****@*****.**'

    link = url_for('result', deploy_id=deploy_id, _external=True)
    body_html = """ <html>
                        <head></head>
                        <body>
                          <p>Error ocurred for deployment (%(deploy_id)s) for user %(email)s<p>
                          <pre>%(report)s</pre>
                          <p>Check it in:</p>
                          <ul>
                            <li>%(link)s</li>
                          </ul>
                          <p>Best regards,</p>
                          <p>wCloud system</p>
                        </body>
                      </html>""" % dict(
        link=link, deploy_id=deploy_id, email=email, report=report)
    print(body_html)
    body = """Error ocurred in wCloud."""
    subject = 'wCloud failure'

    utils.send_email(app, body, subject, from_email,
                     app.config['ADMINISTRATORS'], body_html)
Esempio n. 3
0
def register():
    form = RegistrationForm(request.form)

    if not app.config['RECAPTCHA_ENABLED']:
        del form.recaptcha

    if request.method == 'POST' and form.validate():
        #Exract data from the form
        full_name = form.full_name.data
        email     = form.email.data
        password  = form.password.data
        
        #create user
        user = User(email, hashlib.sha1(password).hexdigest())
        user.full_name = full_name
        user.active = False
        
        #add to database
        token = Token(str(uuid.uuid4()), datetime.datetime.now())
        user.token = token
        db.session.add(user)
        db.session.commit()
        
        #create email
        from_email = '*****@*****.**'

        link = url_for('confirm', email=email, token=token.token, _external = True)
        body_html = """ <html>
                            <head></head>
                            <body>
                              <p>Welcome!<p>
                              <p>This is the wcloud system, which creates new WebLab-Deusto instances.
                              Your account is ready, and you can activate it:</p>
                              <ul>
                                <li><a href="%(link)s">%(link)s</a>.</li>
                              </ul>
                              <p>If you didn't register, feel free to ignore this e-mail.</p>
                              <p>Best regards,</p>
                              <p>WebLab-Deusto team</p>
                            </body>
                          </html>""" % dict(link=link)
        print(body_html)
        body = """Welcome to wcloud. Click %s to confirm your registration.""" % link
        subject = 'wCloud registration'
        
        # Send email
        try:
            utils.send_email(app, body, subject, from_email, user.email, body_html)
            flash("Mail sent to %s from %s with subject '%s'. Check your SPAM folder if you don't receive it." % (user.email, from_email, subject), 'success') 
        except:
            db.session.delete(token)
            db.session.delete(user)
            db.session.commit()
            flash("There was an error sending the e-mail. This might be because of a invalid e-mail address. Please re-check it.", "error")
            return render_template('register.html', form=form)

        flash("""Thanks for registering. You have an
              email with the steps to confirm your account""", 'success')
        return redirect(url_for('login'))
    
    return render_template('register.html', form=form)
Esempio n. 4
0
def register():
    """
    Endpoint for registering a new user. Depending on the configuration, mail confirmation
    will be required or not.
    """
    form = RegistrationForm(request.form)

    if not app.config["RECAPTCHA_ENABLED"]:
        del form.recaptcha

    if request.method == "POST" and form.validate():
        # Extract data from the form
        full_name = form.full_name.data
        email = form.email.data
        password = form.password.data

        # Create user
        user = User(email, unicode(hashlib.sha1(password).hexdigest()), full_name)
        user.active = False
        user.creation_date = datetime.datetime.now()
        user.ip_address = request.headers.get("HTTP_X_FORWARDED_FOR", request.remote_addr)

        mail_confirmation = app.config["MAIL_CONFIRMATION_ENABLED"]

        # Add to database
        token = Token(str(uuid.uuid4()), datetime.datetime.now())
        user.token = token

        if not mail_confirmation:
            user.active = True

        db.session.add(user)
        db.session.commit()

        try:
            from_email = "*****@*****.**"

            body_html = (
                """ <html>
                                <head></head>
                                <body>
                                  <p>New registered user in wCloud: %s</p>
                                </body>
                              </html>"""
                % email
            )
            body = "New registered user: %s" % email
            subject = "New registration"

            utils.send_email(app, body, subject, from_email, app.config["ADMINISTRATORS"], body_html)
        except:
            traceback.print_exc()

        if mail_confirmation:
            # Create email
            from_email = "*****@*****.**"

            link = url_for("confirm", email=email, token=token.token, _external=True)
            body_html = """ <html>
                                <head></head>
                                <body>
                                  <p>Welcome!<p>
                                  <p>This is the wcloud system, which creates new WebLab-Deusto instances.
                                  Your account is ready, and you can activate it:</p>
                                  <ul>
                                    <li><a href="%(link)s">%(link)s</a>.</li>
                                  </ul>
                                  <p>If you didn't register, feel free to ignore this e-mail.</p>
                                  <p>Best regards,</p>
                                  <p>WebLab-Deusto team</p>
                                </body>
                              </html>""" % dict(
                link=link
            )
            print (body_html)
            body = """Welcome to wcloud. Click %s to confirm your registration.""" % link
            subject = "wCloud registration"

            # Send email
            try:
                utils.send_email(app, body, subject, from_email, user.email, body_html)
            except:
                db.session.delete(token)
                db.session.delete(user)
                db.session.commit()
                flash(
                    "There was an error sending the e-mail. This might be because of a invalid e-mail address. Please re-check it.",
                    "error",
                )
                return render_template("register.html", form=form)
            else:
                flash(
                    "Mail sent to %s from %s with subject '%s'. Check your SPAM folder if you don't receive it."
                    % (user.email, from_email, subject),
                    "success",
                )

            flash(
                """Thanks for registering. You have an
                  email with the steps to confirm your account""",
                "success",
            )

        # No mail confirmation.
        else:
            flash("""Thanks for registering. Your account is ready. Please, login.""", "success")

        return redirect(url_for("login"))

    return render_template("register.html", form=form)
Esempio n. 5
0
def register():
    """
    Endpoint for registering a new user. Depending on the configuration, mail confirmation
    will be required or not.
    """
    form = RegistrationForm(request.form)

    if not app.config['RECAPTCHA_ENABLED']:
        del form.recaptcha

    if request.method == 'POST' and form.validate():
        # Extract data from the form
        full_name = form.full_name.data
        email = form.email.data
        password = form.password.data

        # Create user
        user = User(email, unicode(hashlib.sha1(password).hexdigest()),
                    full_name)
        user.active = False
        user.creation_date = datetime.datetime.now()
        user.ip_address = request.headers.get('HTTP_X_FORWARDED_FOR',
                                              request.remote_addr)

        mail_confirmation = app.config["MAIL_CONFIRMATION_ENABLED"]

        # Add to database
        token = Token(str(uuid.uuid4()), datetime.datetime.now())
        user.token = token

        if not mail_confirmation:
            user.active = True

        db.session.add(user)
        db.session.commit()

        try:
            from_email = '*****@*****.**'

            body_html = """ <html>
                                <head></head>
                                <body>
                                  <p>New registered user in wCloud: %s</p>
                                </body>
                              </html>""" % email
            body = "New registered user: %s" % email
            subject = 'New registration'

            utils.send_email(app, body, subject, from_email,
                             app.config['ADMINISTRATORS'], body_html)
        except:
            traceback.print_exc()

        if mail_confirmation:
            # Create email
            from_email = '*****@*****.**'

            link = url_for('confirm',
                           email=email,
                           token=token.token,
                           _external=True)
            body_html = """ <html>
                                <head></head>
                                <body>
                                  <p>Welcome!<p>
                                  <p>This is the wcloud system, which creates new WebLab-Deusto instances.
                                  Your account is ready, and you can activate it:</p>
                                  <ul>
                                    <li><a href="%(link)s">%(link)s</a>.</li>
                                  </ul>
                                  <p>If you didn't register, feel free to ignore this e-mail.</p>
                                  <p>Best regards,</p>
                                  <p>WebLab-Deusto team</p>
                                </body>
                              </html>""" % dict(link=link)
            print(body_html)
            body = """Welcome to wcloud. Click %s to confirm your registration.""" % link
            subject = 'wCloud registration'

            # Send email
            try:
                utils.send_email(app, body, subject, from_email, user.email,
                                 body_html)
            except:
                db.session.delete(token)
                db.session.delete(user)
                db.session.commit()
                flash(
                    "There was an error sending the e-mail. This might be because of a invalid e-mail address. Please re-check it.",
                    "error")
                return render_template('register.html', form=form)
            else:
                flash(
                    "Mail sent to %s from %s with subject '%s'. Check your SPAM folder if you don't receive it."
                    % (user.email, from_email, subject), 'success')

            flash(
                """Thanks for registering. You have an
                  email with the steps to confirm your account""", 'success')

        # No mail confirmation.
        else:
            flash(
                """Thanks for registering. Your account is ready. Please, login.""",
                'success')

        return redirect(url_for('login'))

    return render_template('register.html', form=form)