Skip to content

Commit

Permalink
feat: generate invite handler for godmode
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Dec 27, 2024
1 parent f13b9e1 commit ffc4d00
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
3 changes: 2 additions & 1 deletion club/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from common.feature_flags import feature_switch
from invites.views import show_invite, list_invites, activate_invite
from landing.views import landing, docs, godmode_network_settings, godmode_digest_settings, godmode_settings, \
godmode_invite
godmode_invite, godmode_generate_invite_code
from misc.fun import badge_generator, mass_note
from misc.views import stats, network, robots, generate_ical_invite, generate_google_invite, show_achievement
from rooms.views import redirect_to_room_chat, list_rooms, toggle_room_subscription, toggle_room_mute
Expand Down Expand Up @@ -202,6 +202,7 @@
path("godmode/network/", godmode_network_settings, name="godmode_network_settings"),
path("godmode/digest/", godmode_digest_settings, name="godmode_digest_settings"),
path("godmode/invite/", godmode_invite, name="godmode_invite"),
path("godmode/generate_invite_code/", godmode_generate_invite_code, name="godmode_generate_invite_code"),
path("godmode/dev_login/", debug_dev_login, name="debug_dev_login"),
path("godmode/random_login/", debug_random_login, name="debug_random_login"),
path("godmode/login/<str:user_slug>/", debug_login, name="debug_login"),
Expand Down
2 changes: 1 addition & 1 deletion frontend/html/invites/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<br>

<p>
Секретная ссылка, чтобы подарить её другу 👇
Секретная ссылка, чтобы скопировать и подарить её другу 👇
</p>

<p>
Expand Down
7 changes: 7 additions & 0 deletions frontend/html/invites/list_invites.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<button type="submit" class="button">🎁 Купить инвайт-код</button>
</form>

{% if request.me.is_god %}
<br>
<form action="{% url "godmode_generate_invite_code" %}" method="post">
<button class="button">💣 Сгенерировать инвайт</button>
</form>
{% endif %}

<div class="invites-list">
{% for invite in invites %}
<a href="{% url "show_invite" invite.code %}" class="block invites-list-item zoom-on-hover">
Expand Down
8 changes: 4 additions & 4 deletions frontend/html/invites/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

{% block content %}
<div class="content user-edit">
<div class="form-title">🎁<br>Вам подарили 1 год в Клубе</div>
<div class="form-title"><strong class="text-200">🎁</strong><br>Вам подарили 1 год в Клубе</div>

<div class="block">
<div class="block-description block-description-center">
<p>
Ого! Пользователь <strong>{{ invite.user.full_name }}</strong> подарил вам 1 год в Вастрик Клубе. Должно быть, вы это заслужили! 🥳
Ого! <strong>{{ invite.user.full_name }}</strong> подарил вам 1 год подписки на Вастрик Клуб. Должно быть, вы это заслужили! 🥳
</p>

{% if request.me %}
Expand All @@ -30,7 +30,8 @@
</form>
{% else %}
<p>
Введите адрес своей электронной почты, чтобы мы накинули на него подарочных дней. Если у вас уже есть аккаунт в Клубе — укажите email, который к нему привязан, либо сначала <a href="{% url "login" %}"><strong>войдите</strong></a>.
Введите адрес своей электронной почты, чтобы создать аккаунт.
А если вы уже в Клубе — укажите email существующего аккаунта, либо сначала <a href="{% url "login" %}"><strong>войдите</strong></a> в него.
</p>

<br>
Expand All @@ -49,7 +50,6 @@
</form>
{% endif %}
</div>

</div>
</div>
{% endblock %}
2 changes: 2 additions & 0 deletions frontend/static/css/components/invites.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
gap: 20px;
justify-content: space-between;
}
Expand All @@ -29,5 +30,6 @@
}

.badge-invite-used, .badge-invite-expired {
color: var(--opposite-text-color);
background-color: var(--opposite-block-bg-color);
}
25 changes: 25 additions & 0 deletions landing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

from authn.decorators.auth import require_auth
from club.exceptions import AccessDenied
from invites.models import Invite
from landing.forms import GodmodeNetworkSettingsEditForm, GodmodeDigestEditForm, GodmodeInviteForm
from landing.models import GodSettings
from notifications.email.invites import send_invited_email, send_account_renewed_email
from notifications.telegram.common import send_telegram_message, ADMIN_CHAT
from payments.models import Payment
from payments.products import PRODUCTS
from users.models.user import User
from utils.strings import random_string

EXISTING_DOCS = [
os.path.splitext(f)[0] # get only filenames
Expand Down Expand Up @@ -147,3 +151,24 @@ def godmode_invite(request):
form = GodmodeInviteForm()

return render(request, "admin/simple_form.html", {"form": form})


@require_auth
def godmode_generate_invite_code(request):
if request.method != "POST":
raise Http404()

if not request.me.is_god:
raise AccessDenied()

Invite.objects.create(
user=request.me,
payment=Payment.create(
reference="god-" + random_string(length=16),
user=request.me,
product=PRODUCTS["club1_invite"],
status=Payment.STATUS_SUCCESS,
)
)

return redirect("invites")

0 comments on commit ffc4d00

Please sign in to comment.