componentsDjangoType 2.1.7__tar.gz → 2.1.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {componentsdjangotype-2.1.7/componentsDjangoType.egg-info → componentsdjangotype-2.1.14}/PKG-INFO +1 -1
- componentsdjangotype-2.1.14/componentsDjangoType/management/commands/__pycache__/createApp.cpython-312.pyc +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/management/commands/createApp.py +10 -5
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14/componentsDjangoType.egg-info}/PKG-INFO +1 -1
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType.egg-info/SOURCES.txt +1 -6
- componentsdjangotype-2.1.14/services/authentication/auth.py +80 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/authenticator_configurator.py +139 -74
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/copy_source.py +7 -10
- componentsdjangotype-2.1.14/services/media/users/usuario.png +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/views/layouts/index.html +6 -9
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/setup.py +3 -1
- componentsdjangotype-2.1.7/componentsDjangoType/management/commands/__pycache__/createApp.cpython-312.pyc +0 -0
- componentsdjangotype-2.1.7/services/authentication/auth.py +0 -76
- componentsdjangotype-2.1.7/services/utils/__init__.py +0 -0
- componentsdjangotype-2.1.7/services/utils/css/aside.css +0 -41
- componentsdjangotype-2.1.7/services/utils/views/aside.html +0 -32
- componentsdjangotype-2.1.7/services/utils/views/login.html +0 -37
- componentsdjangotype-2.1.7/services/utils/views/signup.html +0 -43
- componentsdjangotype-2.1.7/services/utils/views/user.html +0 -4
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/LICENSE +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/MANIFEST.in +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/README.md +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/__init__.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/__pycache__/__init__.cpython-312.pyc +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/management/__init__.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/management/__pycache__/__init__.cpython-312.pyc +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/management/commands/__init__.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/management/commands/__pycache__/__init__.cpython-312.pyc +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType/management/commands/createcomponent.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType.egg-info/dependency_links.txt +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType.egg-info/requires.txt +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType.egg-info/top_level.txt +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/__init__.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/authentication/__init__.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/authentication/forms.py +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/css/authentication.css +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/js/alertErrors.js +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/views/home.html +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/views/logged.html +0 -0
- {componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/setup.cfg +0 -0
Binary file
|
@@ -6,26 +6,31 @@ class Command(BaseCommand):
|
|
6
6
|
help = 'Crea una aplicación llamada Home, estructura de carpetas y configura urls automáticamente en el proyecto especificado'
|
7
7
|
|
8
8
|
def handle(self, *args, **kwargs):
|
9
|
-
# Nombre de la aplicación a crear
|
10
9
|
app_name = "Home"
|
11
|
-
|
10
|
+
app_accounts_name = "accounts"
|
11
|
+
|
12
12
|
# Paso 1: Solicitar el nombre de la aplicación principal al usuario
|
13
13
|
project_name = input(
|
14
14
|
"Por favor, ingresa el nombre de la aplicación principal del proyecto: ")
|
15
15
|
|
16
|
-
creation = DjangoProjectManager(app_name=app_name, project_name=project_name
|
16
|
+
creation = DjangoProjectManager(app_name=app_name, project_name=project_name,
|
17
|
+
app_accounts_name=app_accounts_name)
|
17
18
|
|
18
|
-
# Paso 2: Crear
|
19
|
-
creation.
|
19
|
+
# Paso 2: Crear las aplicaciónes "Home y accounts" si no existe
|
20
|
+
creation.create_apps()
|
20
21
|
|
21
22
|
# Agregar automáticamente 'Home' a INSTALLED_APPS
|
22
23
|
creation.installed_app()
|
24
|
+
|
25
|
+
creation.add_settings_modifications()
|
23
26
|
|
24
27
|
# Paso 3: Crear el archivo urls.py en la aplicación "Home" si no existe
|
25
28
|
creation.create_urls(self.stdout)
|
26
29
|
|
27
30
|
# Paso 4: Crear la carpeta services y el archivo authentication.py en Home
|
28
31
|
creation.creation_auth(self.stdout)
|
32
|
+
|
33
|
+
creation.create_profile_model()
|
29
34
|
|
30
35
|
# Paso 5: crea el urls.py y modifica el archivo views.py
|
31
36
|
creation.create_views_urls(self.stdout)
|
{componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/componentsDjangoType.egg-info/SOURCES.txt
RENAMED
@@ -22,14 +22,9 @@ services/copy_source.py
|
|
22
22
|
services/authentication/__init__.py
|
23
23
|
services/authentication/auth.py
|
24
24
|
services/authentication/forms.py
|
25
|
-
services/
|
26
|
-
services/utils/css/aside.css
|
25
|
+
services/media/users/usuario.png
|
27
26
|
services/utils/css/authentication.css
|
28
27
|
services/utils/js/alertErrors.js
|
29
|
-
services/utils/views/aside.html
|
30
28
|
services/utils/views/home.html
|
31
29
|
services/utils/views/logged.html
|
32
|
-
services/utils/views/login.html
|
33
|
-
services/utils/views/signup.html
|
34
|
-
services/utils/views/user.html
|
35
30
|
services/utils/views/layouts/index.html
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import logging
|
2
|
+
from django.shortcuts import render, redirect
|
3
|
+
from django.contrib.auth import login, logout, authenticate
|
4
|
+
from django.db import IntegrityError
|
5
|
+
from services.authentication.forms import customUserCreationform
|
6
|
+
from django.contrib.auth.decorators import login_required
|
7
|
+
|
8
|
+
logger = logging.getLogger(__name__)
|
9
|
+
|
10
|
+
class Authentication:
|
11
|
+
@staticmethod
|
12
|
+
def register(request):
|
13
|
+
if request.user.is_authenticated:
|
14
|
+
return redirect('logged')
|
15
|
+
|
16
|
+
if request.method == 'GET':
|
17
|
+
user_creation_form = customUserCreationform()
|
18
|
+
return render(request, 'registration/register.html', {'form': user_creation_form})
|
19
|
+
|
20
|
+
elif request.method == 'POST':
|
21
|
+
form = customUserCreationform(data=request.POST, files=request.FILES)
|
22
|
+
if form.is_valid():
|
23
|
+
try:
|
24
|
+
user = form.save()
|
25
|
+
user = authenticate(username=form.cleaned_data['username'],
|
26
|
+
password=form.cleaned_data['password1'])
|
27
|
+
if user is not None:
|
28
|
+
login(request, user)
|
29
|
+
return redirect('logged')
|
30
|
+
else:
|
31
|
+
return render(request, 'registration/register.html', {
|
32
|
+
'form': form,
|
33
|
+
'error': 'User could not be authenticated after registration.'
|
34
|
+
})
|
35
|
+
except IntegrityError:
|
36
|
+
logger.error("Integrity error during user registration", exc_info=True)
|
37
|
+
return render(request, 'registration/register.html', {
|
38
|
+
'form': form,
|
39
|
+
'error': 'Unable to register. Please try again later.'
|
40
|
+
})
|
41
|
+
except Exception as e:
|
42
|
+
logger.exception("Unexpected error during registration")
|
43
|
+
return render(request, 'registration/register.html', {
|
44
|
+
'form': form,
|
45
|
+
'error': f'An unexpected error occurred: {str(e)}'
|
46
|
+
})
|
47
|
+
else:
|
48
|
+
return render(request, 'registration/register.html', {
|
49
|
+
'form': form,
|
50
|
+
'error': 'Please correct the errors below.'
|
51
|
+
})
|
52
|
+
|
53
|
+
@staticmethod
|
54
|
+
def exit(request):
|
55
|
+
logout(request)
|
56
|
+
return redirect('home')
|
57
|
+
|
58
|
+
@staticmethod
|
59
|
+
@login_required
|
60
|
+
def logged(request):
|
61
|
+
return render(request, 'logged.html')
|
62
|
+
|
63
|
+
|
64
|
+
""" @staticmethod
|
65
|
+
def get_signing(request):
|
66
|
+
if request.method == 'GET':
|
67
|
+
return render(request, 'registerlogin.html', {
|
68
|
+
'form': AuthenticationForm()
|
69
|
+
})
|
70
|
+
elif request.method == 'POST':
|
71
|
+
form = AuthenticationForm(data=request.POST)
|
72
|
+
if form.is_valid():
|
73
|
+
user = form.get_user()
|
74
|
+
login(request, user)
|
75
|
+
return redirect('logged')
|
76
|
+
else:
|
77
|
+
return render(request, 'login.html', {
|
78
|
+
'form': form,
|
79
|
+
'error': 'Invalid username or password. Please try again.'
|
80
|
+
}) """
|
{componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/authenticator_configurator.py
RENAMED
@@ -1,19 +1,22 @@
|
|
1
1
|
import os
|
2
2
|
from django.core.management import call_command
|
3
3
|
from services.authentication import auth, forms
|
4
|
+
from services.accounts import model
|
4
5
|
from services.copy_source import copy_static_file
|
5
|
-
import importlib.resources as pkg_resources
|
6
6
|
|
7
7
|
class DjangoProjectManager:
|
8
|
-
def __init__(self, app_name, project_name):
|
8
|
+
def __init__(self, app_name, project_name, app_accounts_name):
|
9
9
|
self.app_name = app_name
|
10
10
|
self.project_name = project_name
|
11
|
+
self.app_accounts = app_accounts_name
|
11
12
|
|
12
|
-
def
|
13
|
+
def create_apps(self):
|
13
14
|
"""
|
14
15
|
Crea una aplicación de Django con el nombre especificado si no existe.
|
15
16
|
"""
|
16
17
|
app_name = self.app_name
|
18
|
+
app_accounts = self.app_accounts
|
19
|
+
|
17
20
|
if not os.path.exists(app_name):
|
18
21
|
print(f"Creando la aplicación '{app_name}'...")
|
19
22
|
call_command('startapp', app_name)
|
@@ -23,20 +26,30 @@ class DjangoProjectManager:
|
|
23
26
|
print(f"Error: No se pudo crear la aplicación '{app_name}'.")
|
24
27
|
else:
|
25
28
|
print(f"La aplicación '{app_name}' ya existe.")
|
29
|
+
|
30
|
+
if not os.path.exists(app_accounts):
|
31
|
+
print(f"Creando la aplicación '{app_accounts}'...")
|
32
|
+
call_command('startapp', app_accounts)
|
33
|
+
if os.path.exists(app_accounts):
|
34
|
+
print(f"La aplicación '{app_accounts}' fue creada exitosamente.")
|
35
|
+
else:
|
36
|
+
print(f"Error: No se pudo crear la aplicación '{app_accounts}'.")
|
37
|
+
else:
|
38
|
+
print(f"La aplicación '{app_accounts}' ya existe.")
|
26
39
|
|
27
40
|
def installed_app(self):
|
28
41
|
"""
|
29
|
-
Agrega
|
30
|
-
si no
|
42
|
+
Agrega las aplicaciones al archivo settings.py en la lista INSTALLED_APPS
|
43
|
+
si no están ya presentes. Asegura que se mantenga el formato adecuado.
|
31
44
|
"""
|
32
45
|
settings_path = os.path.join(self.project_name, 'settings.py')
|
33
46
|
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
apps_to_add = [self.app_name, self.app_accounts]
|
48
|
+
|
49
|
+
try:
|
50
|
+
with open(settings_path, 'r') as file:
|
51
|
+
settings_content = file.read()
|
37
52
|
|
38
|
-
# Comprobar si la aplicación ya está en INSTALLED_APPS
|
39
|
-
if f"'{self.app_name}'" not in settings_content:
|
40
53
|
# Buscar la línea donde está la lista INSTALLED_APPS
|
41
54
|
installed_apps_start = settings_content.find("INSTALLED_APPS = [")
|
42
55
|
installed_apps_end = settings_content.find("]", installed_apps_start) + 1
|
@@ -44,23 +57,62 @@ class DjangoProjectManager:
|
|
44
57
|
# Extraer la lista INSTALLED_APPS
|
45
58
|
installed_apps_content = settings_content[installed_apps_start:installed_apps_end]
|
46
59
|
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
60
|
+
# Añadir cada aplicación si no está ya presente
|
61
|
+
for app in apps_to_add:
|
62
|
+
if f"'{app}'" not in installed_apps_content:
|
63
|
+
# Insertar la aplicación dentro de la lista
|
64
|
+
installed_apps_content = installed_apps_content[:-1] + f" '{app}',\n]"
|
51
65
|
|
52
|
-
|
53
|
-
|
66
|
+
# Reemplazar el bloque INSTALLED_APPS con la nueva lista
|
67
|
+
new_settings_content = settings_content[:installed_apps_start] + installed_apps_content + settings_content[installed_apps_end:]
|
54
68
|
|
55
|
-
|
56
|
-
|
57
|
-
|
69
|
+
# Escribir los cambios de vuelta en settings.py
|
70
|
+
with open(settings_path, 'w') as file:
|
71
|
+
file.write(new_settings_content)
|
58
72
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
print(f"
|
73
|
+
print(f"Las aplicaciones {', '.join(apps_to_add)} fueron agregadas a INSTALLED_APPS.")
|
74
|
+
except FileNotFoundError:
|
75
|
+
print(f"El archivo settings.py no se encontró en el proyecto '{self.project_name}'.")
|
76
|
+
except Exception as e:
|
77
|
+
print(f"Error al modificar INSTALLED_APPS: {e}")
|
78
|
+
|
79
|
+
def add_settings_modifications(self):
|
80
|
+
"""
|
81
|
+
Agrega la importación de 'os' y las variables de redirección
|
82
|
+
al archivo settings.py, si no están ya presentes.
|
83
|
+
"""
|
84
|
+
settings_path = os.path.join(self.project_name, 'settings.py')
|
85
|
+
|
86
|
+
# Leer el archivo settings.py
|
87
|
+
with open(settings_path, 'r') as file:
|
88
|
+
settings_content = file.readlines()
|
89
|
+
|
90
|
+
# Verificar si 'import os' ya está presente
|
91
|
+
if 'import os\n' not in settings_content:
|
92
|
+
settings_content.insert(12, 'import os\n') # Insertar al inicio del archivo
|
93
|
+
|
94
|
+
# Verificar si las variables de redirección ya están presentes
|
95
|
+
redirect_settings = [
|
96
|
+
'''\n# Variables globales\n
|
97
|
+
AUTH_USER_MODEL = 'accounts.Profile'
|
98
|
+
\n# Variables de redireccion
|
99
|
+
LOGIN_REDIRECT_URL = 'logged'
|
100
|
+
LOGOUT_REDIRECT_URL = 'home'
|
101
|
+
|
102
|
+
# Definiendo la carpeta media
|
103
|
+
MEDIA_URL = '/media/'
|
104
|
+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
105
|
+
'''
|
106
|
+
]
|
107
|
+
for line in redirect_settings:
|
108
|
+
if line not in settings_content:
|
109
|
+
settings_content.append(line) # Agregar al final si no están
|
110
|
+
|
111
|
+
# Escribir los cambios de vuelta al archivo settings.py
|
112
|
+
with open(settings_path, 'w') as file:
|
113
|
+
file.writelines(settings_content)
|
114
|
+
|
115
|
+
print("Se han agregado 'import os' y las variables de redirección al archivo settings.py.")
|
64
116
|
|
65
117
|
def create_urls(self, stdout):
|
66
118
|
"""
|
@@ -74,10 +126,12 @@ class DjangoProjectManager:
|
|
74
126
|
with open(project_urls_path, 'w') as f:
|
75
127
|
f.write("""from django.contrib import admin
|
76
128
|
from django.urls import path, include # Asegúrate de incluir include
|
129
|
+
from django.conf import settings
|
77
130
|
|
78
131
|
urlpatterns = [
|
79
132
|
path('admin/', admin.site.urls),
|
80
|
-
path('', include('home.urls'))
|
133
|
+
path('', include('home.urls')),
|
134
|
+
path('accounts/', include('django.contrib.auth.urls')),
|
81
135
|
# Añade tus rutas aquí
|
82
136
|
]
|
83
137
|
""")
|
@@ -112,11 +166,17 @@ Including another URLconf
|
|
112
166
|
"""
|
113
167
|
from django.contrib import admin
|
114
168
|
from django.urls import path, include
|
169
|
+
from django.conf import settings
|
115
170
|
|
116
171
|
urlpatterns = [
|
117
172
|
path('admin/', admin.site.urls),
|
118
173
|
path('', include('Home.urls')),
|
174
|
+
path('accounts/', include('django.contrib.auth.urls')),
|
119
175
|
]
|
176
|
+
|
177
|
+
if settings.DEBUG:
|
178
|
+
from django.conf.urls.static import static
|
179
|
+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
120
180
|
'''
|
121
181
|
updated = True
|
122
182
|
|
@@ -135,45 +195,61 @@ urlpatterns = [
|
|
135
195
|
|
136
196
|
# Ruta para el nuevo archivo a crear
|
137
197
|
authentication_path = os.path.join(authentication_dir, 'auth.py')
|
138
|
-
|
198
|
+
forms_path = os.path.join(authentication_dir, 'forms.py')
|
139
199
|
|
140
200
|
# Usar el atributo __file__ del módulo 'auth' para obtener la ruta del archivo fuente
|
141
201
|
auth_source_path = os.path.abspath(auth.__file__)
|
142
|
-
|
202
|
+
forms_source_path = os.path.abspath(forms.__file__)
|
143
203
|
|
144
204
|
if not os.path.exists(auth_source_path):
|
145
205
|
stdout.write(f"El archivo fuente '{auth_source_path}' no existe. Verifica la instalación del paquete.")
|
146
|
-
|
147
|
-
|
148
|
-
if not os.path.exists(form_source_path):
|
149
|
-
stdout.write(f"El archivo fuente '{form_source_path}' no existe. Verifica la instalación del paquete.")
|
206
|
+
stdout.write(f"El archivo fuente '{forms_source_path}' no existe. Verifica la instalación del paquete.")
|
150
207
|
return
|
151
208
|
|
152
209
|
if not os.path.exists(authentication_path):
|
153
210
|
stdout.write(f"Creando el archivo '{authentication_path}'...")
|
154
|
-
stdout.write(f"Creando el archivo '{
|
211
|
+
stdout.write(f"Creando el archivo '{forms_path}'...")
|
155
212
|
|
156
213
|
# Leer el contenido de 'auth.py' del paquete
|
157
214
|
try:
|
158
215
|
with open(auth_source_path, 'r') as source_file:
|
159
216
|
auth_code = source_file.read()
|
160
217
|
|
161
|
-
with open(
|
162
|
-
|
218
|
+
with open(forms_source_path, 'r') as source_file:
|
219
|
+
forms_code = source_file.read()
|
163
220
|
|
164
221
|
# Escribir el contenido en el nuevo archivo 'authentication.py'
|
165
222
|
with open(authentication_path, 'w') as dest_file:
|
166
223
|
dest_file.write(auth_code)
|
167
|
-
|
168
|
-
with open(
|
169
|
-
dest_file.write(
|
224
|
+
|
225
|
+
with open(forms_path, 'w') as dest_file:
|
226
|
+
dest_file.write(forms_code)
|
170
227
|
|
171
228
|
stdout.write(f"El archivo '{authentication_path}' fue creado y el código fue copiado.")
|
172
|
-
stdout.write(f"El archivo '{
|
229
|
+
stdout.write(f"El archivo '{forms_path}' fue creado y el código fue copiado.")
|
173
230
|
except Exception as e:
|
174
231
|
stdout.write(f"Error al copiar el archivo: {e}")
|
175
232
|
else:
|
176
233
|
stdout.write(f"El archivo '{authentication_path}' ya existe.")
|
234
|
+
|
235
|
+
def create_profile_model(self):
|
236
|
+
models_path = os.path.join(self.app_accounts, 'models.py')
|
237
|
+
|
238
|
+
model_source_path = os.path.abspath(model.__file__)
|
239
|
+
|
240
|
+
if not os.path.exists(model_source_path):
|
241
|
+
print(f"El archivo fuente '{model_source_path}' no existe. Verifica la instalación del paquete.")
|
242
|
+
return
|
243
|
+
|
244
|
+
try:
|
245
|
+
with open(model_source_path, 'r') as source_file:
|
246
|
+
model_code = source_file.read()
|
247
|
+
|
248
|
+
with open(models_path, 'w') as dest_file:
|
249
|
+
dest_file.write(model_code)
|
250
|
+
print(f"El archivo '{models_path}' fue creado y el código fue copiado.")
|
251
|
+
except Exception as e:
|
252
|
+
print(f"Error al crear o modificar el archivo '{models_path}': {e}")
|
177
253
|
|
178
254
|
def create_views_urls(self, stdout):
|
179
255
|
home_dir = 'Home' # Nombre de la aplicación Home
|
@@ -194,17 +270,14 @@ from services.authentication.auth import Authentication
|
|
194
270
|
def home(request):
|
195
271
|
return render(request, 'home.html')
|
196
272
|
|
197
|
-
def
|
198
|
-
return Authentication.
|
199
|
-
|
200
|
-
def signout(request):
|
201
|
-
return Authentication.get_signout(request)
|
273
|
+
def register(request):
|
274
|
+
return Authentication.register(request)
|
202
275
|
|
203
|
-
def
|
204
|
-
return Authentication.
|
276
|
+
def exit(request):
|
277
|
+
return Authentication.exit(request)
|
205
278
|
|
206
279
|
def logged(request):
|
207
|
-
return Authentication.
|
280
|
+
return Authentication.logged(request)
|
208
281
|
'''
|
209
282
|
with open(views_path, 'w') as views_file: # Abrir en modo escritura siempre
|
210
283
|
views_file.write(views_code)
|
@@ -217,9 +290,8 @@ from . import views
|
|
217
290
|
|
218
291
|
urlpatterns = [
|
219
292
|
path("", views.home, name='home'),
|
220
|
-
path("
|
221
|
-
path("
|
222
|
-
path("logout", views.signout, name='logout'),
|
293
|
+
path("register/", views.register, name='register'),
|
294
|
+
path("logout/", views.exit, name='exit'),
|
223
295
|
path("logged", views.logged, name='logged'),
|
224
296
|
]
|
225
297
|
'''
|
@@ -233,54 +305,47 @@ urlpatterns = [
|
|
233
305
|
def creation_utils(self, stdout):
|
234
306
|
|
235
307
|
app_name = self.app_name
|
308
|
+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
236
309
|
#creacion de los directorios
|
237
310
|
templates_dir = os.path.join(app_name, 'templates')
|
238
311
|
static_dir = os.path.join(app_name, 'static')
|
312
|
+
media_dir = os.path.join(BASE_DIR, 'media')
|
239
313
|
|
240
314
|
#creacion de subcarpetas
|
241
315
|
layouts_dir = os.path.join(templates_dir, 'layouts')
|
316
|
+
registration_dir = os.path.join(templates_dir, 'registration')
|
242
317
|
js_dir = os.path.join(static_dir, 'js')
|
243
318
|
css_dir = os.path.join(static_dir, 'css')
|
244
|
-
|
319
|
+
users_dir = os.path.join(media_dir, 'users')
|
245
320
|
|
246
321
|
# Crear las carpetas principales y subcarpetas
|
247
322
|
os.makedirs(templates_dir, exist_ok=True)
|
248
323
|
os.makedirs(layouts_dir, exist_ok=True)
|
324
|
+
os.makedirs(media_dir, exist_ok=True)
|
325
|
+
os.makedirs(registration_dir, exist_ok=True)
|
249
326
|
os.makedirs(static_dir, exist_ok=True)
|
250
327
|
os.makedirs(js_dir, exist_ok=True)
|
251
|
-
os.makedirs(css_dir, exist_ok=True)
|
252
|
-
os.makedirs(
|
328
|
+
os.makedirs(css_dir, exist_ok=True)
|
329
|
+
os.makedirs(users_dir, exist_ok=True)
|
253
330
|
|
254
331
|
stdout.write("Estructura de carpetas creada.\n")
|
255
332
|
|
256
333
|
files_to_copy = [
|
334
|
+
|
335
|
+
#carpetas principales
|
257
336
|
("services.utils.js", "alertErrors.js", os.path.join(js_dir, "alertErrors.js")),
|
258
337
|
("services.utils.css", "authentication.css", os.path.join(css_dir, "authentication.css")),
|
259
|
-
("services.utils.css", "aside.css", os.path.join(css_dir, "aside.css")), # Subpaquete específico
|
260
|
-
("services.utils.views.layouts", "index.html", os.path.join(layouts_dir, "index.html")),
|
261
338
|
("services.utils.views", "home.html", os.path.join(templates_dir, "home.html")),
|
262
|
-
("services.utils.views", "signup.html", os.path.join(templates_dir, "signup.html")),
|
263
|
-
("services.utils.views", "login.html", os.path.join(templates_dir, "login.html")),
|
264
339
|
("services.utils.views", "logged.html", os.path.join(templates_dir, "logged.html")),
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
"services.
|
271
|
-
"services.utils.css.user",
|
272
|
-
"services.utils.views",
|
273
|
-
"services.utils.views.user",
|
274
|
-
"services.utils.views.components"
|
340
|
+
|
341
|
+
#sub carpetas
|
342
|
+
("services.utils.views.layouts", "index.html", os.path.join(layouts_dir, "index.html")),
|
343
|
+
("services.utils.views.registration", "login.html", os.path.join(registration_dir, "login.html")),
|
344
|
+
("services.utils.views.registration", "register.html", os.path.join(registration_dir, "register.html")),
|
345
|
+
("services.media.users", "usuario.png", os.path.join(users_dir, "usuario.png")),
|
275
346
|
]
|
276
347
|
|
277
|
-
for package in
|
278
|
-
|
279
|
-
resources = list(pkg_resources.contents(package))
|
280
|
-
print(f"Recursos disponibles en '{package}': {resources}")
|
281
|
-
except ImportError as e:
|
282
|
-
print(f"Error al importar el paquete '{package}': {e}")
|
283
|
-
except Exception as e:
|
284
|
-
print(f"Error desconocido en el paquete '{package}': {e}")
|
348
|
+
for package, resource_name, destination_path in files_to_copy:
|
349
|
+
copy_static_file(package, resource_name, destination_path, stdout)
|
285
350
|
|
286
351
|
stdout.write("Archivos estáticos copiados.\n")
|
@@ -8,27 +8,24 @@ def copy_static_file(package, resource_name, destination_path, stdout=sys.stdout
|
|
8
8
|
Copia un archivo estático empaquetado a una ruta de destino.
|
9
9
|
|
10
10
|
:param package: El nombre del paquete donde está el recurso.
|
11
|
-
:param resource_name:
|
11
|
+
:param resource_name: Ruta relativa del recurso dentro del paquete.
|
12
12
|
:param destination_path: Ruta completa donde se copiará el archivo.
|
13
13
|
:param stdout: Salida estándar para mensajes (por defecto usa sys.stdout).
|
14
14
|
"""
|
15
15
|
try:
|
16
|
-
#
|
17
|
-
os.makedirs(os.path.dirname(destination_path), exist_ok=True)
|
18
|
-
|
19
|
-
# Verificar que el recurso existe
|
16
|
+
# Verifica si el recurso existe en el paquete
|
20
17
|
if not pkg_resources.is_resource(package, resource_name):
|
21
18
|
stdout.write(f"El recurso '{resource_name}' no existe en el paquete '{package}'.\n")
|
22
19
|
return
|
23
20
|
|
24
|
-
#
|
21
|
+
# Crear el directorio de destino si no existe
|
22
|
+
os.makedirs(os.path.dirname(destination_path), exist_ok=True)
|
23
|
+
|
24
|
+
# Leer el archivo desde el paquete y escribirlo en la ruta destino
|
25
25
|
with pkg_resources.open_binary(package, resource_name) as resource_file:
|
26
26
|
with open(destination_path, 'wb') as dest_file:
|
27
27
|
shutil.copyfileobj(resource_file, dest_file)
|
28
28
|
|
29
29
|
stdout.write(f"El recurso '{resource_name}' fue copiado a '{destination_path}'.\n")
|
30
|
-
except ImportError as e:
|
31
|
-
stdout.write(f"Error: No se pudo importar el paquete '{package}': {e}\n")
|
32
30
|
except Exception as e:
|
33
|
-
stdout.write(f"Error al copiar el archivo
|
34
|
-
|
31
|
+
stdout.write(f"Error al copiar el archivo: {e}\n")
|
Binary file
|
{componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/views/layouts/index.html
RENAMED
@@ -5,10 +5,7 @@
|
|
5
5
|
<meta charset="UTF-8">
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
7
|
<link rel="stylesheet" href="{% static 'css/authentication.css' %}">
|
8
|
-
|
9
|
-
{% endblock %}
|
10
|
-
<!-- boxicons -->
|
11
|
-
<script src="https://unpkg.com/boxicons@2.1.4/dist/boxicons.js"></script>
|
8
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
12
9
|
<title>django components</title>
|
13
10
|
</head>
|
14
11
|
<body class="bg-gray-100 text-gray-800">
|
@@ -16,7 +13,7 @@
|
|
16
13
|
<nav class="navbar">
|
17
14
|
<div class="logo">
|
18
15
|
<a href="{% url 'home' %}">
|
19
|
-
<
|
16
|
+
<i class="fa-solid fa-house"></i>
|
20
17
|
</a>
|
21
18
|
</div>
|
22
19
|
<div class="menu-toggle">
|
@@ -24,9 +21,9 @@
|
|
24
21
|
</div>
|
25
22
|
<ul class="nav-links">
|
26
23
|
{% if user.is_authenticated %}
|
27
|
-
<li><a href="{% url '
|
24
|
+
<li><a href="{% url 'exit' %}" class="nav-item">Logout</a></li>
|
28
25
|
{% else %}
|
29
|
-
<li><a href="{% url '
|
26
|
+
<li><a href="{% url 'register' %}" class="nav-item">Sign Up</a></li>
|
30
27
|
<li><a href="{% url 'login' %}" class="nav-item">Login</a></li>
|
31
28
|
{% endif %}
|
32
29
|
</ul>
|
@@ -37,7 +34,7 @@
|
|
37
34
|
{% endblock %}
|
38
35
|
</div>
|
39
36
|
|
40
|
-
|
41
|
-
{%
|
37
|
+
|
38
|
+
<script src="{% static 'js/alertErrors.js'%}"></script>
|
42
39
|
</body>
|
43
40
|
</html>
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='componentsDjangoType',
|
5
|
-
version='2.1.
|
5
|
+
version='2.1.14',
|
6
6
|
packages=find_packages(),
|
7
7
|
include_package_data=True,
|
8
8
|
package_data={
|
@@ -11,6 +11,8 @@ setup(
|
|
11
11
|
'utils/css/*.css',
|
12
12
|
'utils/views/*.html',
|
13
13
|
'utils/views/layouts/*.html',
|
14
|
+
'media/users/*.jpg',
|
15
|
+
'media/users/*.png',
|
14
16
|
],
|
15
17
|
},
|
16
18
|
license='MIT',
|
Binary file
|
@@ -1,76 +0,0 @@
|
|
1
|
-
from django.shortcuts import render, redirect
|
2
|
-
from django.contrib.auth.forms import AuthenticationForm
|
3
|
-
from django.contrib.auth import login, logout
|
4
|
-
from django.db import IntegrityError
|
5
|
-
from services.authentication.forms import customUserCreationform
|
6
|
-
|
7
|
-
class Authentication:
|
8
|
-
@staticmethod
|
9
|
-
def get_signup(request):
|
10
|
-
if request.method == 'GET':
|
11
|
-
# Crear una nueva instancia del formulario en GET
|
12
|
-
return render(request, 'signup.html', {
|
13
|
-
'form': customUserCreationform() # Instancia del formulario
|
14
|
-
})
|
15
|
-
elif request.method == 'POST':
|
16
|
-
# Crear una instancia del formulario con los datos enviados
|
17
|
-
form = customUserCreationform(request.POST)
|
18
|
-
if form.is_valid():
|
19
|
-
try:
|
20
|
-
user = form.save()
|
21
|
-
login(request, user)
|
22
|
-
return redirect('logged')
|
23
|
-
except IntegrityError:
|
24
|
-
# Si ocurre un error de integridad (por ejemplo, nombre de usuario duplicado)
|
25
|
-
return render(request, 'signup.html', {
|
26
|
-
'form': form,
|
27
|
-
'error': 'Unable to register. Please try again later.'
|
28
|
-
})
|
29
|
-
else:
|
30
|
-
# Si el formulario no es válido, muestra los errores
|
31
|
-
return render(request, 'signup.html', {
|
32
|
-
'form': form,
|
33
|
-
'error': 'Please correct the errors below.'
|
34
|
-
})
|
35
|
-
|
36
|
-
@staticmethod
|
37
|
-
def get_signout(request):
|
38
|
-
logout(request)
|
39
|
-
return redirect('home')
|
40
|
-
|
41
|
-
@staticmethod
|
42
|
-
def get_signing(request):
|
43
|
-
if request.method == 'GET':
|
44
|
-
return render(request, 'login.html', {
|
45
|
-
'form': AuthenticationForm()
|
46
|
-
})
|
47
|
-
elif request.method == 'POST':
|
48
|
-
form = AuthenticationForm(data=request.POST)
|
49
|
-
if form.is_valid():
|
50
|
-
user = form.get_user()
|
51
|
-
login(request, user)
|
52
|
-
return redirect('logged')
|
53
|
-
else:
|
54
|
-
return render(request, 'login.html', {
|
55
|
-
'form': form,
|
56
|
-
'error': 'Invalid username or password. Please try again.'
|
57
|
-
})
|
58
|
-
|
59
|
-
@staticmethod
|
60
|
-
def get_logged(request):
|
61
|
-
return render(request, 'logged.html')
|
62
|
-
|
63
|
-
def dispatch(self, request, *args, **kwargs):
|
64
|
-
match request.path:
|
65
|
-
case "/signup":
|
66
|
-
return self.get_signup(request)
|
67
|
-
case "/login":
|
68
|
-
return self.get_signing(request)
|
69
|
-
case "/logout":
|
70
|
-
return self.get_signout(request)
|
71
|
-
case "/logged":
|
72
|
-
return self.get_logged(request)
|
73
|
-
case "/":
|
74
|
-
return self.get(request)
|
75
|
-
case _:
|
76
|
-
return self.get(request)
|
File without changes
|
@@ -1,41 +0,0 @@
|
|
1
|
-
.user-sidebar {
|
2
|
-
max-width: 300px;
|
3
|
-
background-color: #f9fafb;
|
4
|
-
border: 1px solid #e5e7eb;
|
5
|
-
border-radius: 0.5rem;
|
6
|
-
padding: 1rem;
|
7
|
-
display: inline-block;
|
8
|
-
overflow: hidden;
|
9
|
-
}
|
10
|
-
|
11
|
-
.user-menu {
|
12
|
-
list-style-type: none;
|
13
|
-
margin: 0;
|
14
|
-
padding: 0;
|
15
|
-
}
|
16
|
-
|
17
|
-
.user-item {
|
18
|
-
display: flex;
|
19
|
-
align-items: center;
|
20
|
-
margin-bottom: 1rem;
|
21
|
-
}
|
22
|
-
|
23
|
-
.user-item .icon {
|
24
|
-
display: flex;
|
25
|
-
justify-content: center;
|
26
|
-
align-items: center;
|
27
|
-
width: 2.5rem;
|
28
|
-
height: 2.5rem;
|
29
|
-
font-size: 1.2rem;
|
30
|
-
}
|
31
|
-
|
32
|
-
.user-item .text {
|
33
|
-
font-size: 1rem;
|
34
|
-
color: #1f2937;
|
35
|
-
font-weight: 500;
|
36
|
-
}
|
37
|
-
|
38
|
-
.user-item:last-child {
|
39
|
-
margin-bottom: 0;
|
40
|
-
}
|
41
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
{% load static %}
|
2
|
-
{% block css %}
|
3
|
-
<link rel="stylesheet" href="{% static 'css/user/aside.css' %}">
|
4
|
-
{% endblock %}
|
5
|
-
<aside class="user-sidebar bg-gray-100 p-4 rounded-lg shadow-md">
|
6
|
-
<ul class="user-menu list-none m-0 p-0">
|
7
|
-
<li class="user-item flex items-center mb-4">
|
8
|
-
<span class="icon bg-blue-500 text-white rounded-full p-2 mr-3">
|
9
|
-
<box-icon type='solid' name='image-alt'></box-icon>
|
10
|
-
</span>
|
11
|
-
<span class="text">Image</span>
|
12
|
-
</li>
|
13
|
-
<li class="user-item flex items-center mb-4">
|
14
|
-
<span class="icon bg-green-500 text-white rounded-full p-2 mr-3">
|
15
|
-
<box-icon name='user'></box-icon>
|
16
|
-
</span>
|
17
|
-
<span class="text">Name</span>
|
18
|
-
</li>
|
19
|
-
<li class="user-item flex items-center mb-4">
|
20
|
-
<span class="icon bg-orange-500 text-white rounded-full p-2 mr-3">
|
21
|
-
<box-icon type='solid' name='lock-alt'></box-icon>
|
22
|
-
</span>
|
23
|
-
<span class="text">Password</span>
|
24
|
-
</li>
|
25
|
-
<li class="user-item flex items-center">
|
26
|
-
<span class="icon bg-red-500 text-white rounded-full p-2 mr-3">
|
27
|
-
<box-icon name='trash-alt' type='solid' ></box-icon>
|
28
|
-
</span>
|
29
|
-
<span class="text">Delete User</span>
|
30
|
-
</li>
|
31
|
-
</ul>
|
32
|
-
</aside>
|
@@ -1,37 +0,0 @@
|
|
1
|
-
{% extends "layouts/index.html" %}
|
2
|
-
{% load static %}
|
3
|
-
{% block layout %}
|
4
|
-
{% if error %}
|
5
|
-
<div class="alert" id="alert">
|
6
|
-
<div class="alert-content">
|
7
|
-
{{ error }}
|
8
|
-
<button class="close-btn" onclick="closeAlert()">
|
9
|
-
<span class="sr-only">Close</span>
|
10
|
-
<svg class="close-icon" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
11
|
-
<path d="M0.92524 0.687069C1.126 0.486219 1.39823 0.373377 1.68209 0.373377C1.96597 0.373377 2.2382 0.486219 2.43894 0.687069L8.10514 6.35813L13.7714 0.687069C13.8701 0.584748 13.9882 0.503105 14.1188 0.446962C14.2494 0.39082 14.3899 0.361248 14.5321 0.360026C14.6742 0.358783 14.8151 0.38589 14.9468 0.439762C15.0782 0.493633 15.1977 0.573197 15.2983 0.673783C15.3987 0.774389 15.4784 0.894026 15.5321 1.02568C15.5859 1.15736 15.6131 1.29845 15.6118 1.44071C15.6105 1.58297 15.5809 1.72357 15.5248 1.85428C15.4688 1.98499 15.3872 2.10324 15.2851 2.20206L9.61883 7.87312L15.2851 13.5441C15.4801 13.7462 15.588 14.0168 15.5854 14.2977C15.5831 14.5787 15.4705 14.8474 15.272 15.046C15.0735 15.2449 14.805 15.3574 14.5244 15.3599C14.2437 15.3623 13.9733 15.2543 13.7714 15.0591L8.10514 9.38812L2.43894 15.0591C2.23704 15.2543 1.96663 15.3623 1.68594 15.3599C1.40526 15.3574 1.13677 15.2449 0.938279 15.046C0.739807 14.8474 0.627232 14.5787 0.624791 14.2977C0.62235 14.0168 0.730236 13.7462 0.92524 13.5441L6.59144 7.87312L0.92524 2.20206C0.724562 2.00115 0.611816 1.72867 0.611816 1.44457C0.611816 1.16047 0.724562 0.887983 0.92524 0.687069Z" fill="currentColor"/>
|
12
|
-
</svg>
|
13
|
-
</button>
|
14
|
-
</div>
|
15
|
-
</div>
|
16
|
-
{% endif %}
|
17
|
-
|
18
|
-
<div class="form-wrapper">
|
19
|
-
<div class="form-container">
|
20
|
-
<form action="" method="post" class="form-control">
|
21
|
-
{% csrf_token %}
|
22
|
-
<h1>Login</h1>
|
23
|
-
|
24
|
-
<label for="username">Usuario:</label>
|
25
|
-
{{ form.username }}
|
26
|
-
|
27
|
-
<label for="password">Contraseña:</label>
|
28
|
-
<input type="password" id="password" name="password" value="{{ form.password2 }}" required>
|
29
|
-
|
30
|
-
<button type="submit">Login</button>
|
31
|
-
</form>
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
{% endblock %}
|
35
|
-
{% block script %}
|
36
|
-
<script src="{% static 'js/alertErrors.js'%}"></script>
|
37
|
-
{% endblock %}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
{% extends "layouts/index.html" %}
|
2
|
-
{% load static %}
|
3
|
-
{% block layout %}
|
4
|
-
{% if error %}
|
5
|
-
<div class="alert" id="alert">
|
6
|
-
<div class="alert-content">
|
7
|
-
{{ error }}
|
8
|
-
<button class="close-btn" onclick="closeAlert()">
|
9
|
-
<span class="sr-only">Close</span>
|
10
|
-
<svg class="close-icon" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
11
|
-
<path d="M0.92524 0.687069C1.126 0.486219 1.39823 0.373377 1.68209 0.373377C1.96597 0.373377 2.2382 0.486219 2.43894 0.687069L8.10514 6.35813L13.7714 0.687069C13.8701 0.584748 13.9882 0.503105 14.1188 0.446962C14.2494 0.39082 14.3899 0.361248 14.5321 0.360026C14.6742 0.358783 14.8151 0.38589 14.9468 0.439762C15.0782 0.493633 15.1977 0.573197 15.2983 0.673783C15.3987 0.774389 15.4784 0.894026 15.5321 1.02568C15.5859 1.15736 15.6131 1.29845 15.6118 1.44071C15.6105 1.58297 15.5809 1.72357 15.5248 1.85428C15.4688 1.98499 15.3872 2.10324 15.2851 2.20206L9.61883 7.87312L15.2851 13.5441C15.4801 13.7462 15.588 14.0168 15.5854 14.2977C15.5831 14.5787 15.4705 14.8474 15.272 15.046C15.0735 15.2449 14.805 15.3574 14.5244 15.3599C14.2437 15.3623 13.9733 15.2543 13.7714 15.0591L8.10514 9.38812L2.43894 15.0591C2.23704 15.2543 1.96663 15.3623 1.68594 15.3599C1.40526 15.3574 1.13677 15.2449 0.938279 15.046C0.739807 14.8474 0.627232 14.5787 0.624791 14.2977C0.62235 14.0168 0.730236 13.7462 0.92524 13.5441L6.59144 7.87312L0.92524 2.20206C0.724562 2.00115 0.611816 1.72867 0.611816 1.44457C0.611816 1.16047 0.724562 0.887983 0.92524 0.687069Z" fill="currentColor"/>
|
12
|
-
</svg>
|
13
|
-
</button>
|
14
|
-
</div>
|
15
|
-
</div>
|
16
|
-
{% endif %}
|
17
|
-
|
18
|
-
<div class="form-wrapper">
|
19
|
-
<div class="form-container">
|
20
|
-
<form action="" method="post" class="form-control" enctype="multipart/form-data">
|
21
|
-
{% csrf_token %}
|
22
|
-
<h1>sing up</h1>
|
23
|
-
|
24
|
-
<label for="img_url">Imagen de Perfil:</label>
|
25
|
-
{{ form.image }}
|
26
|
-
|
27
|
-
<label for="username">Usuario:</label>
|
28
|
-
{{ form.username }}
|
29
|
-
|
30
|
-
<label for="password1">Contraseña:</label>
|
31
|
-
{{ form.password1 }}
|
32
|
-
|
33
|
-
<label for="password2">Confirmar Contraseña:</label>
|
34
|
-
{{ form.password2 }}
|
35
|
-
|
36
|
-
<button type="submit">sing Up</button>
|
37
|
-
</form>
|
38
|
-
</div>
|
39
|
-
</div>
|
40
|
-
{% endblock %}
|
41
|
-
{% block script %}
|
42
|
-
<script src="{% static 'js/alertErrors.js'%}"></script>
|
43
|
-
{% endblock %}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/authentication/__init__.py
RENAMED
File without changes
|
File without changes
|
{componentsdjangotype-2.1.7 → componentsdjangotype-2.1.14}/services/utils/css/authentication.css
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|