notifications and email
This commit is contained in:
parent
86cd832f6e
commit
95cd6d06c7
23
Main/migrations/0038_auto_20220516_1836.py
Normal file
23
Main/migrations/0038_auto_20220516_1836.py
Normal file
@ -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),
|
||||
),
|
||||
]
|
@ -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)
|
||||
|
@ -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"):
|
||||
|
@ -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):
|
||||
|
@ -126,6 +126,15 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<h2><i class="fa fa-at"></i></h2>
|
||||
</td>
|
||||
<td><div style="width: 20px;"></div></td>
|
||||
<td>
|
||||
<p style="padding-top: 8px; font-size: 24px;">{{ account.email }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
@ -133,12 +142,70 @@
|
||||
</div>
|
||||
</div>
|
||||
{% if owner %}
|
||||
{% if not account.email %}
|
||||
<div class="card border-0 shadow mb-4">
|
||||
<div class="card-body">
|
||||
<h1 class="h4">Прикрепи почту к своему аккаунту</h1>
|
||||
<script>
|
||||
function checkEmail() {
|
||||
const username = document.getElementById('email');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/check_new',
|
||||
data: {"email": username.value, "csrfmiddlewaretoken": document.getElementsByName('csrfmiddlewaretoken')[0].value, "action": "check_email"},
|
||||
statusCode: {
|
||||
200: function() {
|
||||
username.style.backgroundColor = '#00FF00AA';
|
||||
data['email'] = true;
|
||||
},
|
||||
400: function() {
|
||||
username.style.backgroundColor = '#FF0000AA';
|
||||
data['email'] = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<h5>
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="email" class="form" name="email" onchange="checkEmail();" id="email" placeholder="email"><br>
|
||||
<input type="hidden" name="action" value="add_email">
|
||||
<button type="submit" class="btn btn-info mt-3">Сохранить</button>
|
||||
</form>
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="card border-0 shadow mb-4">
|
||||
<div class="card-body">
|
||||
<h1 class="h4">Уведомления</h1>
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="notifications">
|
||||
<table>
|
||||
{% if account.userinfo.telegram_chat_id %}
|
||||
<tr>
|
||||
<td style="width: 200px;">
|
||||
Уведомления в телеграм
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" name="notification_telegram" {% if user.userinfo.notification_solution_result %}checked{% endif %}>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if account.email %}
|
||||
<tr>
|
||||
<td style="width: 200px;">
|
||||
Уведомления по почте
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" name="notification_email" {% if user.userinfo.notification_solution_result %}checked{% endif %}>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
<hr>
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 200px;">
|
||||
|
Loading…
Reference in New Issue
Block a user