-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from cs3216-a3-group-4/seeleng/email-validati…
…on-v2 feat: email verification
- Loading branch information
Showing
28 changed files
with
1,068 additions
and
177 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
backend/alembic/versions/4f9ec96fc98e_add_unverified_tier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Add unverified tier | ||
Revision ID: 4f9ec96fc98e | ||
Revises: 651ed2d244c5 | ||
Create Date: 2024-10-31 14:30:56.099043 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlalchemy.orm as orm | ||
from alembic_postgresql_enum import TableReference | ||
from src.limits.models import Tier | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "4f9ec96fc98e" | ||
down_revision: Union[str, None] = "651ed2d244c5" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values( | ||
"public", | ||
"tiernames", | ||
["FREE", "ADMIN", "PREMIUM", "UNVERIFIED"], | ||
[ | ||
TableReference( | ||
table_schema="public", table_name="tier", column_name="tier_name" | ||
) | ||
], | ||
enum_values_to_rename=[], | ||
) | ||
session = orm.Session(bind=op.get_bind()) | ||
session.add(Tier(tier_name="UNVERIFIED", label="Unverified", gp_question_limit=0)) | ||
session.commit() | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
session = orm.Session(bind=op.get_bind()) | ||
unverified = session.scalar(sa.select(Tier).where(Tier.label == "Unverified")) | ||
session.delete(unverified) | ||
session.commit() | ||
|
||
op.sync_enum_values( | ||
"public", | ||
"tiernames", | ||
["FREE", "ADMIN", "PREMIUM"], | ||
[ | ||
TableReference( | ||
table_schema="public", table_name="tier", column_name="tier_name" | ||
) | ||
], | ||
enum_values_to_rename=[], | ||
) | ||
|
||
# ### end Alembic commands ### |
48 changes: 48 additions & 0 deletions
48
backend/alembic/versions/63af7264fba3_add_essay_rate_limit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Add essay rate limit | ||
Revision ID: 63af7264fba3 | ||
Revises: 4f9ec96fc98e | ||
Create Date: 2024-10-31 14:54:32.307467 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlalchemy.orm as orm | ||
from src.limits.models import Tier | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "63af7264fba3" | ||
down_revision: Union[str, None] = "4f9ec96fc98e" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
ESSAY_LIMITS = {"Free": 3, "Premium": 10, "Unverified": 0, "Admin": 1000} | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"tier", | ||
sa.Column("essay_limit", sa.Integer(), server_default="0", nullable=False), | ||
) | ||
op.add_column( | ||
"usage", sa.Column("essays", sa.Integer(), server_default="0", nullable=False) | ||
) | ||
session = orm.Session(bind=op.get_bind()) | ||
for tier_type, essay_limit in ESSAY_LIMITS.items(): | ||
tier = session.scalar(sa.select(Tier).where(Tier.label == tier_type)) | ||
tier.essay_limit = essay_limit | ||
session.add(tier) | ||
session.commit() | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("usage", "essays") | ||
op.drop_column("tier", "essay_limit") | ||
# ### end Alembic commands ### |
54 changes: 54 additions & 0 deletions
54
backend/alembic/versions/651ed2d244c5_add_email_verification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Add email verification | ||
Revision ID: 651ed2d244c5 | ||
Revises: 59cef91d2fa1 | ||
Create Date: 2024-10-31 13:46:07.360330 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "651ed2d244c5" | ||
down_revision: Union[str, None] = "59cef91d2fa1" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"email_verification", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.Column("code", sa.String(), nullable=False), | ||
sa.Column("used", sa.Boolean(), nullable=False), | ||
sa.Column( | ||
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False | ||
), | ||
sa.Column( | ||
"updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False | ||
), | ||
sa.Column("deleted_at", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["user.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.add_column( | ||
"user", | ||
sa.Column("verified", sa.Boolean(), server_default="true", nullable=False), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("user", "verified") | ||
op.drop_table("email_verification") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.