예제 #1
0
    def send_email(self, order, helsinki_profile_user: HelsinkiProfileUser):
        email = helsinki_profile_user.email if helsinki_profile_user else None

        # If the profile doesn't have an associated email
        # or if it has an example.com address, set it as failed
        if is_valid_email(email):
            try:
                approve_order(order, email, self.due_date,
                              helsinki_profile_user, self.request)
                self.successful_orders.append(order.id)
            except (
                    AnymailError,
                    OSError,
                    ValidationError,
                    VenepaikkaGraphQLError,
            ) as e:
                logger.exception(e)
                self.fail_order(order, str(e))
        else:
            self.fail_lease(order.lease,
                            _("Missing customer email"),
                            dont_count=True)
            self.fail_order(order,
                            _("Missing customer email"),
                            dont_count=True)
예제 #2
0
def dashboard():
    if request.method == "GET":
        team_solves = ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge).where(ChallengeSolve.team == g.team)
        team_adjustments = ScoreAdjustment.select().where(ScoreAdjustment.team == g.team)
        team_score = sum([i.challenge.points for i in team_solves] + [i.value for i in team_adjustments])
        first_login = False
        if g.team.first_login:
            first_login = True
            g.team.first_login = False
            g.team.save()
        return render_template("dashboard.html", team_solves=team_solves, team_adjustments=team_adjustments, team_score=team_score, first_login=first_login)

    elif request.method == "POST":
        if g.redis.get("ul{}".format(session["team_id"])):
            flash("You're changing your information too fast!")
            return redirect(url_for('dashboard'))

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        affiliation = request.form["affiliation"].strip()
        team_elig = "team_eligibility" in request.form

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return redirect(url_for('dashboard'))

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return redirect(url_for('dashboard'))

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        email_changed = (team_email != g.team.email)

        g.team.name = team_name
        g.team.email = team_email
        g.team.affiliation = affiliation
        if not g.team.eligibility_locked:
            g.team.eligible = team_elig

        g.redis.set("ul{}".format(session["team_id"]), str(datetime.now()), 120)

        if email_changed:
            if not email.is_valid_email(team_email):
                flash("You're lying")
                return redirect(url_for('dashboard'))

            g.team.email_confirmation_key = misc.generate_confirmation_key()
            g.team.email_confirmed = False

            email.send_confirmation_email(team_email, g.team.email_confirmation_key, g.team.key)
            flash("Changes saved. Please check your email for a new confirmation key.")
        else:
            flash("Changes saved.")
        g.team.save()


        return redirect(url_for('dashboard'))
예제 #3
0
파일: app.py 프로젝트: page2me/ctf-platform
def register():
    if not config.registration:
        if "admin" in session and session["admin"]:
            pass
        else:
            return "Registration is currently disabled. Email [email protected] to create an account."

    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        error, message = captcha.verify_captcha()
        if error:
            flash(message)
            return render_template("register.html")

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        team_elig = "team_eligibility" in request.form
        affiliation = request.form["affiliation"].strip()

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return render_template("register.html")

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return render_template("register.html")

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        if not email.is_valid_email(team_email):
            flash("You're lying")
            return render_template("register.html")

        team_key = misc.generate_team_key()
        confirmation_key = misc.generate_confirmation_key()

        team = Team.create(name=team_name,
                           email=team_email,
                           eligible=team_elig,
                           affiliation=affiliation,
                           key=team_key,
                           email_confirmation_key=confirmation_key)
        TeamAccess.create(team=team, ip=misc.get_ip(), time=datetime.now())

        email.send_confirmation_email(team_email, confirmation_key, team_key)

        session["team_id"] = team.id
        flash("Team created.")
        return redirect(url_for('dashboard'))
예제 #4
0
파일: app.py 프로젝트: TJCSec/ctf-platform
def register():
    if not config.registration:
        if "admin" in session and session["admin"]:
            pass
        else:
            return "Registration is currently disabled. Email [email protected] to create an account."

    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        error, message = captcha.verify_captcha()
        if error:
            flash(message)
            return render_template("register.html")

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        team_elig = "team_eligibility" in request.form
        affiliation = request.form["affiliation"].strip()

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return render_template("register.html")

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return render_template("register.html")

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        if not email.is_valid_email(team_email):
            flash("You're lying")
            return render_template("register.html")

        team_key = misc.generate_team_key()
        confirmation_key = misc.generate_confirmation_key()

        team = Team.create(name=team_name, email=team_email, eligible=team_elig, affiliation=affiliation, key=team_key,
                           email_confirmation_key=confirmation_key)
        TeamAccess.create(team=team, ip=misc.get_ip(), time=datetime.now())

        email.send_confirmation_email(team_email, confirmation_key, team_key)

        session["team_id"] = team.id
        flash("Team created.")
        return redirect(url_for('dashboard'))
예제 #5
0
def send_berth_switch_offer(
    offer,
    due_date: date,
) -> None:
    if due_date:
        offer.due_date = due_date
        offer.save()

    # Update offer and application status
    offer.set_status(OfferStatus.OFFERED)

    from .notifications import NotificationType

    language = (offer.application.language
                if offer.application else settings.LANGUAGE_CODE)

    email = offer.customer_email or offer.application.email

    if not is_valid_email(email):
        raise ValidationError(_("Missing customer email"))

    notification_type = NotificationType.BERTH_SWITCH_OFFER_APPROVED

    context = {
        "subject": get_email_subject(notification_type),
        "offer": offer,
        "accept_url": get_offer_customer_url(offer, language, True),
        "cancel_url": get_offer_customer_url(offer, language, False),
        "due_date": format_date(offer.due_date, locale=language),
    }

    send_notification(email, notification_type.value, context, language)

    if offer.customer_phone:
        sms_service = SMSNotificationService()
        sms_service.send(
            NotificationType.SMS_BERTH_SWITCH_NOTICE,
            context,
            offer.customer_phone,
            language=language,
        )
예제 #6
0
def send_payment_notification(
    order: Order,
    request: HttpRequest,
    email: str = None,
    phone_number: str = None,
    has_services: bool = True,
    has_payment_urls: bool = True,
):
    from payments.providers import get_payment_provider

    from .notifications import NotificationType

    order_email = email or order.customer_email
    order_phone = phone_number or order.customer_phone

    if not is_valid_email(order_email):
        raise ValidationError(_("Missing customer email"))

    language = get_notification_language(order)

    payment_url = None
    cancel_url = None

    if has_payment_urls:
        payment_url = get_payment_provider(
            request,
            ui_return_url=settings.VENE_UI_RETURN_URL).get_payment_email_url(
                order, lang=language)

        cancel_url = get_payment_provider(
            request, ui_return_url=settings.VENE_UI_RETURN_URL
        ).get_cancellation_email_url(order, lang=language)

    notification_type = get_order_notification_type(order)
    context = get_context(order, notification_type, has_services, payment_url,
                          cancel_url)
    send_notification(order_email, notification_type.value, context, language)

    if order_phone and notification_type not in (
            NotificationType.ORDER_CANCELLED,
            NotificationType.ORDER_REFUNDED,
    ):
        if hasattr(order, "product") and order.product:
            product_name = order.product.name
        else:
            product_name = ", ".join([
                str(ProductServiceType(order_line.product.service).label)
                for order_line in order.order_lines.all()
            ])

        sms_context = {
            "product_name": product_name,
            "due_date": format_date(order.due_date, locale=language),
            "payment_url": payment_url,
        }
        sms_service = SMSNotificationService()
        sms_service.send(
            NotificationType.SMS_INVOICE_NOTICE,
            sms_context,
            order_phone,
            language=language,
        )
예제 #7
0
def dashboard():
    if request.method == "GET":
        team_solves = ChallengeSolve.select(
            ChallengeSolve,
            Challenge).join(Challenge).where(ChallengeSolve.team == g.team)
        team_adjustments = ScoreAdjustment.select().where(
            ScoreAdjustment.team == g.team)
        team_score = sum([i.challenge.points for i in team_solves] +
                         [i.value for i in team_adjustments])
        first_login = False
        if g.team.first_login:
            first_login = True
            g.team.first_login = False
            g.team.save()
        return render_template("dashboard.html",
                               team_solves=team_solves,
                               team_adjustments=team_adjustments,
                               team_score=team_score,
                               first_login=first_login)

    elif request.method == "POST":
        if g.redis.get("ul{}".format(session["team_id"])):
            flash("You're changing your information too fast!")
            return redirect(url_for('dashboard'))

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        affiliation = request.form["affiliation"].strip()
        team_elig = "team_eligibility" in request.form

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return redirect(url_for('dashboard'))

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return redirect(url_for('dashboard'))

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        email_changed = (team_email != g.team.email)

        g.team.name = team_name
        g.team.email = team_email
        g.team.affiliation = affiliation
        if not g.team.eligibility_locked:
            g.team.eligible = team_elig

        g.redis.set("ul{}".format(session["team_id"]), str(datetime.now()),
                    120)

        if email_changed:
            if not email.is_valid_email(team_email):
                flash("You're lying")
                return redirect(url_for('dashboard'))

            g.team.email_confirmation_key = misc.generate_confirmation_key()
            g.team.email_confirmed = False

            email.send_confirmation_email(team_email,
                                          g.team.email_confirmation_key,
                                          g.team.key)
            flash(
                "Changes saved. Please check your email for a new confirmation key."
            )
        else:
            flash("Changes saved.")
        g.team.save()

        return redirect(url_for('dashboard'))
예제 #8
0
def terminate_lease(
    lease: Union[BerthLease, WinterStorageLease],
    end_date: date = None,
    profile_token: str = None,
    send_notice: bool = True,
) -> Union[BerthLease, WinterStorageLease]:
    from .models import BerthLease
    from .notifications import NotificationType

    if lease.status not in TERMINABLE_STATUSES:
        raise ValidationError(
            _(
                f"Only leases in paid, error or offered status can be terminated, current status is {lease.status}"
            )
        )

    for order in lease.orders.all():
        if order.status in OrderStatus.get_waiting_statuses():
            order.set_status(OrderStatus.CANCELLED, _("Lease was terminated"))

    lease.status = LeaseStatus.TERMINATED

    if isinstance(lease, BerthLease):
        default_date = calculate_berth_lease_start_date()
    else:  # WinterStorageLease
        default_date = calculate_winter_storage_lease_start_date()
    lease.end_date = end_date or default_date

    lease.save()

    if send_notice:
        language = (
            lease.application.language
            if lease.application
            else settings.LANGUAGES[0][0]
        )

        email = None

        if profile_token:
            profile_service = ProfileService(profile_token=profile_token)
            profile = profile_service.get_profile(lease.customer.id)
            email = profile.email

        if not email and lease.application:
            email = lease.application.email

        if not email:
            raise ValidationError(
                _("The lease has no email and no profile token was provided")
            )

        if not is_valid_email(email):
            raise ValidationError(_("Missing customer email"))

        notification_type = (
            NotificationType.BERTH_LEASE_TERMINATED_LEASE_NOTICE
            if isinstance(lease, BerthLease)
            else NotificationType.WINTER_STORAGE_LEASE_TERMINATED_LEASE_NOTICE
        )

        send_notification(
            email,
            notification_type,
            {
                "subject": notification_type.label,
                "cancelled_at": format_date(today(), locale=language),
                "lease": lease,
            },
            language=language,
        )

    return lease