Files
dj52/restore_user_setup.sh
Beyhan Oğur ec28a2024d first commit
2026-04-26 22:22:29 +03:00

66 lines
1.6 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Restore sonrası kullanıcı oluşturma scripti
cd /Users/beyhan/Projeler/Python/dj52
echo "==================================="
echo "RESTORE SONRASI KULLANICI OLUŞTURMA"
echo "==================================="
# Mevcut kullanıcıları kontrol et
python manage.py shell -c "
from accounts.models import CustomUser
users = CustomUser.objects.all()
print(f'\nToplam {users.count()} kullanıcı var')
for user in users:
print(f' - {user.email} (Staff: {user.is_staff}, Superuser: {user.is_superuser})')
"
echo ""
echo "Yeni superuser oluşturmak ister misiniz? (y/n)"
read -r answer
if [ "$answer" = "y" ]; then
echo "Email:"
read -r email
echo "Şifre:"
read -rs password
python manage.py shell -c "
from accounts.models import CustomUser
try:
user = CustomUser.objects.create_superuser(email='$email', password='$password')
print(f'\n✓ Superuser oluşturuldu: {user.email}')
except Exception as e:
print(f'\n✗ Hata: {e}')
"
fi
echo ""
echo "Mevcut bir kullanıcının şifresini değiştirmek ister misiniz? (y/n)"
read -r answer2
if [ "$answer2" = "y" ]; then
echo "Kullanıcı email:"
read -r user_email
echo "Yeni şifre:"
read -rs new_password
python manage.py shell -c "
from accounts.models import CustomUser
try:
user = CustomUser.objects.get(email='$user_email')
user.set_password('$new_password')
user.save()
print(f'\n✓ Şifre değiştirildi: {user.email}')
except CustomUser.DoesNotExist:
print('\n✗ Kullanıcı bulunamadı')
except Exception as e:
print(f'\n✗ Hata: {e}')
"
fi
echo ""
echo "İşlem tamamlandı!"