예제 #1
0
def report_broken_build():
    from datetime import date

    yesterday = date.today() - timedelta(days=1)
    failed = (db.session.query(Build).filter(
        Build.status == "FAILED",
        Build.created_at > yesterday).order_by(desc(Build.created_at)).first())
    if failed:
        message = "Build failure in application %s. Build id %s created at %s<br><br>%s" % (
            app.config["ENVIRONMENT"],
            failed.id,
            failed.created_at,
            failed.failure_reason,
        )
        message += (
            f"Acknowledge with:<br>"
            f"<strong><code>"
            f'heroku run "./manage.py acknowledge_build_issue --build_id {failed.id}" -a APP_NAME'
            f"</code></strong>")
        subject = "Build failure in application %s on %s" % (
            app.config["ENVIRONMENT"], date.today())
        recipients = db.session.query(User).filter(
            User.user_type == TypeOfUser.DEV_USER.name).all()
        for r in recipients:
            send_email(app.config["RDU_EMAIL"], r.email, message, subject)
        print(message)
    else:
        print("No failed builds today")
def report_stalled_build():
    from datetime import date

    half_an_hour_ago = datetime.now() - timedelta(minutes=30)
    stalled = (db.session.query(Build).filter(
        Build.status == "STARTED",
        func.DATE(Build.created_at) == date.today(),
        Build.created_at <= half_an_hour_ago).order_by(desc(
            Build.created_at)).first())

    if stalled:
        message = "Build stalled for more than 30 minutes in application %s. Build id %s created at %s" % (
            app.config["ENVIRONMENT"],
            stalled.id,
            stalled.created_at,
        )
        subject = "Build stalled in application %s on %s" % (
            app.config["ENVIRONMENT"], date.today())
        recipients = db.session.query(User).filter(
            User.user_type == TypeOfUser.DEV_USER.name).all()
        for r in recipients:
            send_email(app.config["RDU_EMAIL"], r.email, message, subject)
        print(message)
    else:
        print("No stalled builds")
예제 #3
0
 def send_password_reset_code(self):
     email = request.form["email"]
     user = User.query.filter_by(email=email)
     if user.count() > 0:
         reset_code = random.randint(1000, 9999)
         user = user.first()
         user.reset_code = reset_code
         user.reset_token = generate_password_hash(user.email +
                                                   user.fullname,
                                                   method="sha256")
         try:
             db.session.add(user)
             db.session.commit()
             send_email(
                 user,
                 "<h1>Your Password reset code is: " + str(reset_code) +
                 "</h1>",
             )
             return jsonify({
                 "isSent": True,
                 "message": "Password reset code sent to your email",
                 "reset_token": user.reset_token,
             })
         except Exception as e:
             return jsonify({
                 "isSent": True,
                 "message": "Password reset code sent to your email",
                 "reset_token": "reset_token",
             })
     else:
         return jsonify({
             "isSent": True,
             "message": "Password reset code sent to your email",
             "reset_token": "reset_token",
         })
예제 #4
0
    def send_confirmation_code(self):
        print(request.headers)
        user = AuthorizeRequest(request.headers)
        if not user:
            return jsonify({
                "isSent": False,
                "message": "Invalid details provided"
            })

        confirmation_code = random.randint(1000, 9999)
        user.confirmation_code = confirmation_code
        try:
            db.session.add(user)
            db.session.commit()
            send_email(
                user,
                "<h1>Your new confirmation code is: " +
                str(confirmation_code) + "</h1>",
            )
            return jsonify({
                "isSent": True,
                "message": "Confirmation code sent."
            })
        except Exception as e:
            return jsonify({
                "isSent":
                False,
                "message":
                "Error occurred in sending the confirmation code. Please try again.",
            })
예제 #5
0
    def index(self):
        form = BadgeRequestForm(request.form)

        if (request.method == "POST") and form.validate():
            user = form.member.data

            record = Badges(user.id, form.badge.data, 'Pending')
            db.session.add(record)
            db.session.commit()
            """
                Auto-activation:
                * The user has signed a waiver at the Smartwaiver kiosk.
                * User is admin it's the requester's own badge.

                Set to pending and e-mail admin for action:
                * The user has signed a waiver at the Smartwaiver kiosk.
                * NOT the requester's own badge and is NOT an admin
            """
            if ((current_user.is_admin()
                 or (current_user.email == user.email))):
                result = change_badge_status('Active', record)

                if "error" in result:
                    raise Exception("%s" % (result['error']))

                record.status = 'Active'
                db.session.commit()

                flash(
                    "Request Successful: %s's badge has been activated automatically."
                    % (user.full_name, ))
            else:
                message = '''
                    <p>%s's badge has been submitted by %s %s for activation.</p>
                    <p>This user has already signed a waiver.</p>
                    <a href='%s'>Approve</a>
                ''' % (user.full_name, current_user.first_name,
                       current_user.last_name,
                       url_for('badges.index_view',
                               flt0_status_equals='Pending',
                               _external=True))
                subject = 'Badge Pending - Already Signed Waiver'
                send_email(subject, message, user)

                flash(
                    "Request Successful: %s's badge has been submitted for admin approval."
                    % (user.full_name, ))

        return self.render('create.html', form=form)
예제 #6
0
    def signup(self):
        form = request.form
        for field in form:
            if form[field] == "" or form[field] == None:
                return jsonify({
                    "isRegistered": False,
                    "message": "All fields are required"
                })

        checkUser = User.query.filter_by(email=form["email"]).count()
        if checkUser > 0:
            return jsonify({
                "isRegistered": False,
                "message": "The email is already taken."
            })

        confirmation_code = random.randint(1000, 9999)
        hashed_password = generate_password_hash(form["password"],
                                                 method="sha256")
        token = generate_password_hash(form["password"] + form["fullname"],
                                       method="sha256")
        new_user = User(
            fullname=form["fullname"],
            email=form["email"],
            age=form["age"],
            gender=form["gender"],
            country=form["country"],
            continent=form["continent"],
            password=hashed_password,
            token=token,
            confirmation_code=confirmation_code,
        )
        try:
            db.session.add(new_user)
            db.session.commit()
            send_email(
                new_user.email,
                "<h1> Confirmation code is: " + str(confirmation_code) +
                "</h1>",
            )
            return jsonify({
                "isRegistered": True,
                "message":
                "Regsiteration successful, A confirmation code is sent to your email",
                "user": UserSchema(many=False).dump(new_user),
            })
        except Exception as e:
            print(e)
            return jsonify({"isRegistered": False, "message": str(e)})
예제 #7
0
def forgot():
    form = EmailForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first_or_404()

        subject = "Password reset requested"

        # Here we use the URLSafeTimedSerializer
        token = ts.dumps(user.email, salt='recover-key')

        reset_url = url_for('reset_with_token', token=token, _external=True)

        html = render_template('email/reset.html', reset_url=reset_url)

        send_email(user.email, subject, html)

        return redirect(url_for('index'))

    return render_template('auth/forgot.html', forgot_form=form)
예제 #8
0
def report_stalled_build():
    from datetime import date

    half_an_hour_ago = datetime.now() - timedelta(minutes=30)
    stalled = (db.session.query(Build).filter(
        Build.status == BuildStatus.STARTED,
        func.DATE(Build.created_at) == date.today(),
        Build.created_at <= half_an_hour_ago,
    ).order_by(desc(Build.created_at)).first())

    if stalled:
        message = (
            f"Build stalled for more than 30 minutes in application {app.config['ENVIRONMENT']}.<br>"
            f"Build id {stalled.id} created at {stalled.created_at}<br><br>"
            f"Acknowledge with:<br>"
            f"<strong><code>"
            f'heroku run "./manage.py acknowledge_build_issue --build_id {stalled.id}" -a APP_NAME'
            f"</code></strong>")
        subject = "Build stalled in application %s on %s" % (
            app.config["ENVIRONMENT"], date.today())
        recipients = db.session.query(User).filter(
            User.user_type == TypeOfUser.DEV_USER.name).all()
        for r in recipients:
            send_email(app.config["RDU_EMAIL"], r.email, message, subject)
        print(message)

        # Do a little dance to send this exception to Sentry, if configured, otherwise just let it bubble up.
        try:
            raise StalledBuildException(
                f"Build {stalled.id} has stalled. Acknowledge with:\n\n"
                f'heroku run "./manage.py acknowledge_build_issue --build_id {stalled.id}" -a APP_NAME'
            )

        except StalledBuildException as e:
            if "sentry" in app.extensions:
                app.extensions["sentry"].captureException()
            else:
                raise e

    else:
        print("No stalled builds")
def report_broken_build():
    from datetime import date

    yesterday = date.today() - timedelta(days=1)
    failed = (db.session.query(Build).filter(
        Build.status == "FAILED",
        Build.created_at > yesterday).order_by(desc(Build.created_at)).first())
    if failed:
        message = "Build failure in application %s. Build id %s created at %s\n\n%s" % (
            app.config["ENVIRONMENT"],
            failed.id,
            failed.created_at,
            failed.failure_reason,
        )
        subject = "Build failure in application %s on %s" % (
            app.config["ENVIRONMENT"], date.today())
        recipients = db.session.query(User).filter(
            User.user_type == TypeOfUser.DEV_USER.name).all()
        for r in recipients:
            send_email(app.config["RDU_EMAIL"], r.email, message, subject)
        print(message)
    else:
        print("No failed builds today")