Don't key off of email for login

Let's not emulate the rest of WPI's shitty login system that doesn't
deal with name changes

This also opens us to up to making it significantly easier to update
names and emails, if they don't match on login but ID matches. Will file
bug to implement this, though it'll be hard to test

Note that this is a BREAKING CHANGE, the database will need to be
cleared before applying migrations will succeed
This commit is contained in:
Cara Salter 2024-04-06 10:17:45 +11:00
parent c2c70fc659
commit 5b1d41eb58
No known key found for this signature in database
GPG key ID: A8A3A601440EADA5
3 changed files with 37 additions and 1 deletions

View file

@ -27,10 +27,11 @@ def oauth2_callback():
resp.raise_for_status()
profile = resp.json()
print(profile)
u = User.query.filter_by(email=profile['mail']).first()
u = User.query.filter_by(microsoft_id=profile['id']).first()
if u is None:
u = User(
id=ulid.ulid(),
microsoft_id=profile['id'],
password='',
email=profile['mail'],
first_name=profile['givenName'],

View file

@ -8,6 +8,7 @@ from . import login
class User(db.Model, UserMixin):
__tablename__ = "acm_users"
id = Column(String, primary_key=True)
microsoft_id = Column(String, unique=True, nullable=False)
email = Column(String, unique=True, nullable=True)
password = Column(String, nullable=False)
first_name = Column(String, nullable=False)

View file

@ -0,0 +1,34 @@
"""add microsoft GUID to user model
Revision ID: 300f24071c14
Revises: 4fa893cdd432
Create Date: 2024-04-06 10:15:35.146272
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '300f24071c14'
down_revision = '4fa893cdd432'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('acm_users', schema=None) as batch_op:
batch_op.add_column(sa.Column('microsoft_id', sa.String(), nullable=False))
batch_op.create_unique_constraint(None, ['microsoft_id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('acm_users', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='unique')
batch_op.drop_column('microsoft_id')
# ### end Alembic commands ###