Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typing-extensions = "*"
flask-jwt-extended = "==4.6.0"
wtforms = "==3.1.2"
sqlalchemy = "*"
flask-bcrypt = "*"

[requires]
python_version = "3.13"
Expand Down
88 changes: 77 additions & 11 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions migrations/versions/4517993f5dfe_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""empty message

Revision ID: 4517993f5dfe
Revises: 727b004dfad3
Create Date: 2025-07-25 15:48:44.313778

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '4517993f5dfe'
down_revision = '727b004dfad3'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('admin',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('password', sa.String(length=128), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('token_blocked_list',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('jti', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('jti')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('token_blocked_list')
op.drop_table('admin')
# ### end Alembic commands ###
42 changes: 42 additions & 0 deletions migrations/versions/876cb350dd08_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""empty message

Revision ID: 876cb350dd08
Revises: 4517993f5dfe
Create Date: 2025-07-25 16:00:47.587108

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '876cb350dd08'
down_revision = '4517993f5dfe'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('ct_admin',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('password', sa.String(length=128), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.drop_table('admin')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('admin',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('email', sa.VARCHAR(length=120), autoincrement=False, nullable=False),
sa.Column('password', sa.VARCHAR(length=128), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='admin_pkey'),
sa.UniqueConstraint('email', name='admin_email_key')
)
op.drop_table('ct_admin')
# ### end Alembic commands ###
36 changes: 35 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
<!doctype html><html class="h-100"><head><meta name="viewport" content="width=device-width,initial-scale=1"><meta charset="UTF-8"><title>Hello Rigo with Vanilla.js</title><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous"><link rel="icon" href="/4geeks.ico"><script defer="defer" src="/bundle.js"></script></head><body class="h-100"><div id="app" class="h-100"></div><script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script></body></html>
<!DOCTYPE html>
<html class="h-100">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta charset="UTF-8" />
<title>CloudTech</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.2.0/css/all.css"
integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ"
crossorigin="anonymous"
/>
<link rel="icon" href="/4geeks.ico" />
<script defer="defer" src="/bundle.js"></script>
</head>
<body class="h-100">
<div id="app" class="h-100"></div>
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"
integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"
integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13"
crossorigin="anonymous"
></script>
</body>
</html>
Binary file removed public/rigo-baby.jpg
Binary file not shown.
29 changes: 24 additions & 5 deletions src/api/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@

import os
from flask_admin import Admin
from .models import db, Lead
from .models import db, Lead, CTAdmin, TokenBlockedList
from flask_admin.contrib.sqla import ModelView
from wtforms import PasswordField


class CTAdminModelView(ModelView):
column_list = ('id', 'email')
form_columns = ('email', 'password_field')
column_exclude_list = ['_password']
form_extra_fields = {
'password_field': PasswordField('Password')
}

def on_model_change(self, form, model, is_created):
if form.password_field.data:
model.password = form.password_field.data
elif is_created and not form.password_field.data:
raise ValueError(
'El password es obligatorio para nuevos administradores')


def setup_admin(app):
app.secret_key = os.environ.get('FLASK_APP_KEY', 'sample key')
app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'
admin = Admin(app, name='4Geeks Admin', template_mode='bootstrap3')
admin = Admin(app, name='CloudTech Admin', template_mode='bootstrap3')


# Add your models here, for example this is how we add a the User model to the admin
admin.add_view(ModelView(Lead, db.session))
admin.add_view(CTAdminModelView(CTAdmin, db.session))
admin.add_view(ModelView(TokenBlockedList, db.session))

# You can duplicate that line to add mew models
# admin.add_view(ModelView(YourModelName, db.session))
# admin.add_view(ModelView(YourModelName, db.session))
37 changes: 37 additions & 0 deletions src/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@
db = SQLAlchemy()


class CTAdmin(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(
String(120), unique=True, nullable=False)
_password: Mapped[str] = mapped_column(
"password", String(128), nullable=False)

@property
def password(self):
raise AttributeError('Password is not a readable attribute.')

@password.setter
def password(self, password):
from app import bcrypt
self._password = bcrypt.generate_password_hash(
password).decode('utf-8')

# Método para verificar el password
def check_password(self, password):
from app import bcrypt
return bcrypt.check_password_hash(self._password, password)

def serialize(self):
return {
"id": self.id,
"email": self.email
}


class Lead(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(
Expand All @@ -25,3 +54,11 @@ def serialize(self):
"company": self.company,
"message": self.message
}


class TokenBlockedList(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
jti: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)

def __repr__(self):
return f'<CTAdmin {self.email}>'
Loading