""" Django settings for smoothlyseo project. Generated by 'django-admin startproject' using Django 5.2. For more information on this file, see https://docs.djangoproject.com/en/5.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.2/ref/settings/ """ from pathlib import Path import os from decouple import config import dj_database_url from dotenv import load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent load_dotenv(dotenv_path=BASE_DIR / '.env') # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = config('SECRET_KEY') # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Application definition INSTALLED_APPS = [ 'webapp', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.postgres', 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.google', 'markdown_deux', ] SITE_ID = 1 # Asegúrate de que el ID del sitio esté configurado AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'allauth.account.auth_backends.AuthenticationBackend', ) SOCIALACCOUNT_PROVIDERS = { 'google': { 'SCOPE': ['profile', 'email'], 'AUTH_PARAMS': { 'access_type': 'online', 'prompt': 'select_account' }, 'OAUTH_PKCE_ENABLED': True, 'APP': { 'client_id': config('GOOGLE_CLIENT_ID'), 'secret': config('GOOGLE_CLIENT_SECRET'), 'key': '' } } } ACCOUNT_SIGNUP_FIELDS = ['email*', 'password1*', 'password2*'] ACCOUNT_LOGIN_METHODS = {'email'} ACCOUNT_EMAIL_VERIFICATION = 'mandatory' ACCOUNT_USER_MODEL_USERNAME_FIELD = None ACCOUNT_LOGIN_ON_PASSWORD_RESET = True ACCOUNT_PASSWORD_RESET_REDIRECT_URL = '/accounts/password/reset/done/' # Configuración de sesión SESSION_EXPIRE_AT_BROWSER_CLOSE = True # Cierra sesión al cerrar el navegador por defecto SESSION_COOKIE_AGE = 1209600 # 2 semanas en segundos (opcional, para "Recuérdame") AUTH_USER_MODEL = 'webapp.Usuario' ACCOUNT_ADAPTER = 'webapp.adapters.CustomAccountAdapter' MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'allauth.account.middleware.AccountMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'smoothlyseo.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'smoothlyseo.wsgi.application' # Database DATABASES = { 'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'), conn_max_age=600, conn_health_checks=True) } if 'DATABASE_URL' in os.environ else { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ.get('PGDATABASE'), 'USER': os.environ.get('PGUSER'), 'PASSWORD': os.environ.get('PGPASSWORD'), 'HOST': os.environ.get('PGHOST'), 'PORT': os.environ.get('PGPORT'), 'OPTIONS': {'sslmode': 'require'}, } } # Password validation AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization LANGUAGE_CODE = 'es-es' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) STATIC_URL = '/static/' STATICFILES_DIRS = [BASE_DIR / "static"] STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # Media files (for PDFs) MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / "mediafiles" # Default primary key field type DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # API Keys WOORANK_API_KEY = config('WOORANK_API_KEY') DEEPSEEK_API_KEY = config('DEEPSEEK_API_KEY') STRIPE_API_KEY = config('STRIPE_API_KEY') STRIPE_PUBLIC_KEY = config('STRIPE_PUBLIC_KEY') STRIPE_PRICE_FREE = config('STRIPE_PRICE_FREE') STRIPE_PRICE_STANDARD = config('STRIPE_PRICE_STANDARD') STRIPE_PRICE_PRO = config('STRIPE_PRICE_PRO') STRIPE_WEBHOOK_SECRET = config('STRIPE_WEBHOOK_SECRET') # Configuración adicional de Django CSRF_COOKIE_SECURE = True # Para desarrollo local CSRF_TRUSTED_ORIGINS = ['https://smoothlyseo.endinahosting.com', 'https://www.smoothlyseo.endinahosting.com'] # Añadir logging para correos LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'class': 'logging.StreamHandler', }, 'file': { 'class': 'logging.FileHandler', 'filename': 'debug.log', }, 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', }, }, 'loggers': { '': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': True, }, 'allauth': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': True, }, 'django': { 'handlers': ['console', 'file', 'mail_admins'], 'level': 'ERROR', 'propagate': True, }, }, } SOCIALACCOUNT_PROVIDERS = { 'google': { 'SCOPE': ['profile', 'email'], 'AUTH_PARAMS': { 'access_type': 'online', 'prompt': 'select_account' # Fuerza la selección de cuenta }, 'OAUTH_PKCE_ENABLED': True, # Habilita PKCE para mayor seguridad 'CLIENT_ID': '361348347077-ucnnd20n1cq9j42900stvll32fc3bd36.apps.googleusercontent.com', 'SECRET': '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', } } SOCIALACCOUNT_LOGIN_ON_GET = True # Redirige directamente a Google sin confirmación LOGIN_REDIRECT_URL = '/overview/' # Redirección por defecto para login manual SOCIALACCOUNT_LOGIN_REDIRECT_URL = '/overview/' # Redirección por defecto para login social ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https' # Para desarrollo LOGIN_URL = '/auth/' ACCOUNT_LOGIN_URL = '/auth/' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' # Verifica que sea correcto EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = 'alejandro.rodriguez1900@gmail.com' # Tu email de Gmail EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD') DEFAULT_FROM_EMAIL = 'alejandro.rodriguez1900@gmail.com' DOMAIN = config('DOMAIN', default='127.0.0.1:8000') # SECURITY WARNING: don't run with debug turned on in production! # Configuración para manejar errores personalizados DEBUG = config('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = ['smoothlyseo.endinahosting.com', 'www.smoothlyseo.endinahosting.com'] # Configuración de manejo de errores personalizados handler404 = 'webapp.views.custom_404' # Ruta a la vista personalizada (ver Paso 3)