diff --git a/Main/migrations/0038_auto_20220516_1836.py b/Main/migrations/0038_auto_20220516_1836.py new file mode 100644 index 0000000..df0faa2 --- /dev/null +++ b/Main/migrations/0038_auto_20220516_1836.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.4 on 2022-05-16 15:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('Main', '0037_alter_userinfo_telegram_chat_id'), + ] + + operations = [ + migrations.AddField( + model_name='userinfo', + name='notification_email', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='userinfo', + name='notification_telegram', + field=models.BooleanField(default=False), + ), + ] diff --git a/Main/models/userinfo.py b/Main/models/userinfo.py index 483808d..c788bc5 100644 --- a/Main/models/userinfo.py +++ b/Main/models/userinfo.py @@ -26,6 +26,8 @@ class UserInfo(models.Model): notification_solution_result = models.BooleanField(default=False) notification_friends = models.BooleanField(default=False) notification_messages = models.BooleanField(default=False) + notification_telegram = models.BooleanField(default=False) + notification_email = models.BooleanField(default=False) code = models.IntegerField(null=True, blank=True) verified = models.BooleanField(default=False) teacher = models.BooleanField(default=False) diff --git a/Main/views/AccountView.py b/Main/views/AccountView.py index 6bf5e4b..0789a7e 100644 --- a/Main/views/AccountView.py +++ b/Main/views/AccountView.py @@ -84,6 +84,11 @@ class AccountView(BaseView): self.request.user.userinfo.save() return "/account" + def post_add_email(self): + self.request.user.email = self.request.POST['email'] + self.request.user.save() + return "/account" + def post_notifications(self): for attr in dir(self.request.user.userinfo): if attr.startswith("notification"): diff --git a/daemons/management/commands/notification_manager.py b/daemons/management/commands/notification_manager.py index b5844af..a4c7152 100644 --- a/daemons/management/commands/notification_manager.py +++ b/daemons/management/commands/notification_manager.py @@ -16,9 +16,9 @@ class Command(MessagingSupport): f"Результат: {solution.result}\n" \ f"Очки решения: {Progress.by_solution(solution).score}\n" \ f"Текущий рейтинг: {solution.user.userinfo.rating}" - if user.userinfo.telegram_chat_id is not None: + if user.userinfo.notification_telegram is not None: yield "telegram", {"chat_id": user.userinfo.telegram_chat_id, "text": message} - if user.email: + if user.userinfo.notification_email: yield "email", {"subject": "Тестирование завершено", "message": message, "email": user.email} def handle_friends_add(self, payload): @@ -26,9 +26,9 @@ class Command(MessagingSupport): from_user = User.objects.get(id=payload['from_user_id']) if user.userinfo.notification_friends: message = f"Пользователь {from_user.username} хочет добавить тебя в друзья" - if user.userinfo.telegram_chat_id: + if user.userinfo.notification_telegram: yield "telegram", {"chat_id": user.userinfo.telegram_chat_id, "text": message} - if user.email: + if user.userinfo.notification_email: yield "email", {"subject": "Новая заявка в друзья", "message": message, "email": user.email} def handle_friends_accept(self, payload): @@ -39,9 +39,9 @@ class Command(MessagingSupport): message = f"Пользователь {from_user} одобрил заявку в друзья" else: message = f"Пользователь {from_user} отклонил заявку в друзья" - if user.userinfo.telegram_chat_id: + if user.userinfo.notification_telegram: yield "telegram", {"chat_id": user.userinfo.telegram_chat_id, "text": message} - if user.email: + if user.userinfo.notification_email: yield "email", {"subject": "Новая заявка в друзья", "message": message, "email": user.email} def process(self, payload: dict): diff --git a/templates/account.html b/templates/account.html index 632999d..557dca4 100644 --- a/templates/account.html +++ b/templates/account.html @@ -126,6 +126,15 @@ {% endif %} + + +

+ +
+ +

{{ account.email }}

+ + {% endif %} @@ -133,12 +142,70 @@ {% if owner %} + {% if not account.email %} +
+
+

Прикрепи почту к своему аккаунту

+ +
+
+ {% csrf_token %} +
+ + +
+
+
+
+ {% endif %}

Уведомления

{% csrf_token %} + + {% if account.userinfo.telegram_chat_id %} + + + + + {% endif %} + {% if account.email %} + + + + + {% endif %} +
+ Уведомления в телеграм + + +
+ Уведомления по почте + + +
+