- Add birth_date, created_at/updated_at to Employee; remove username field - Introduce EmployeeAction for tracking HR events and is_actually_active/status properties - Create BotSubscriber model (OneToOne relation) for TG/WA binding - Implement Aiogram-based Telegram bot: • request contact to bind by phone or @username • department selection keyboard from DEPARTMENTS dict • async ORM via sync_to_async, custom filters for bound & active employees - Update profile view & template: • show “Bind Telegram/WhatsApp” button only when not already bound • preview avatar on upload - Remove registration tokens in favor of contact-based auth - Clean up templates, forms and add avatar validation mixin
16 lines
581 B
Python
16 lines
581 B
Python
from django.shortcuts import render, redirect
|
|
from django.contrib.auth.decorators import login_required
|
|
import secrets
|
|
|
|
@login_required
|
|
def generate_messenger_token(request):
|
|
user = request.user
|
|
user.registration_token = secrets.token_hex(16)
|
|
user.save(update_fields=['registration_token'])
|
|
telegram_link = f"https://t.me/your_bot?start={user.registration_token}"
|
|
# Можно также вернуть QR-код
|
|
return render(request, 'users/messenger_token.html', {
|
|
'telegram_link': telegram_link,
|
|
'token': user.registration_token,
|
|
})
|