-
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 #37 from cs3216-a3-group-4/seeleng/add-password-reset
feat: add password routes
- Loading branch information
Showing
8 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
backend/alembic/versions/3c473e77f83a_add_user_password_reset_table.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,42 @@ | ||
"""Add user password reset table | ||
Revision ID: 3c473e77f83a | ||
Revises: a31eae0cbe7a | ||
Create Date: 2024-09-24 16:29:28.507257 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "3c473e77f83a" | ||
down_revision: Union[str, None] = "a31eae0cbe7a" | ||
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( | ||
"password-reset", | ||
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.ForeignKeyConstraint( | ||
["user_id"], | ||
["user.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("password-reset") | ||
# ### 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
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
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,25 @@ | ||
import smtplib | ||
import ssl | ||
from email.message import EmailMessage | ||
|
||
from src.common.constants import GOOGLE_APP_PASSWORD, GOOGLE_EMAIL | ||
|
||
PORT = 465 # For SSL | ||
|
||
|
||
def send_email( | ||
receiving_email_addr: str, | ||
subject: str, | ||
message: str, | ||
): | ||
context = ssl.create_default_context() | ||
with smtplib.SMTP_SSL("smtp.gmail.com", PORT, context=context) as server: | ||
server.login(GOOGLE_EMAIL, GOOGLE_APP_PASSWORD) | ||
|
||
msg = EmailMessage() | ||
msg["Subject"] = subject | ||
msg["From"] = GOOGLE_EMAIL | ||
msg["To"] = receiving_email_addr | ||
msg.set_content(message) | ||
|
||
server.sendmail(GOOGLE_EMAIL, receiving_email_addr, msg.as_string()) |