Files
chunyu_project/_temp_set_user.py
T
2026-08-05 23:59:15 +08:00

33 lines
880 B
Python

import django
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chunyu_project.settings')
django.setup()
from django.core.cache import caches
from user.models import FUser
from rest_framework_simplejwt.tokens import RefreshToken
cache = caches['default']
email = 'test@testbug.com'
# Check if user exists
user = FUser.objects.filter(email=email).first()
if not user:
user = FUser.objects.create_user(
email=email,
username=email,
nickname='测试用户',
is_active=True
)
print(f'Created user: {user.email}')
# Set verification code in cache
key = f'register_{email}'
cache.set(key, '88888888', timeout=600)
val = cache.get(key)
print(f'Verification code "{val}" set with key "{key}"')
# Generate token
refresh = RefreshToken.for_user(user)
print(f'ACCESS_TOKEN: {refresh.access_token}')
print(f'REFRESH_TOKEN: {refresh}')