-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/user management #24
base: staging
Are you sure you want to change the base?
Changes from all commits
9bd5a05
6b5f8c4
d12ebcd
c32fd33
93a7b4b
2e27c66
68ee774
5edc3ca
b390a3c
66753f7
1ea4c6d
4b822b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
GOOGLE_CLIENT_ID=553026630658-ed4e19reiffffm0kihn5lh6ln3d4g.apps.googleusercontent.com | ||
GOOGLE_CLIENT_SECRET=LUjC5CPRqX3mFcfdddxAqCoE9Tk | ||
SECRET=S3CR3T | ||
GOPHIE_ACCESS_KEY=S3CR3TK3Y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this file to .gitignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add the .DS_Store and clean them up |
||
"python.linting.banditEnabled": false, | ||
"python.linting.enabled": true, | ||
"python.linting.flake8Enabled": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""add oauth2 to user model | ||
|
||
Revision ID: 3c0cb039fd0a | ||
Revises: b44fef6dc06b | ||
Create Date: 2021-11-18 20:59:19.398458 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '3c0cb039fd0a' | ||
down_revision = 'b44fef6dc06b' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index('ix_user_email', table_name='user') | ||
op.drop_table('user') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('user', | ||
sa.Column('id', sa.CHAR(length=36), nullable=False), | ||
sa.Column('email', sa.VARCHAR(length=320), nullable=False), | ||
sa.Column('hashed_password', sa.VARCHAR(length=72), nullable=False), | ||
sa.Column('is_active', sa.BOOLEAN(), nullable=False), | ||
sa.Column('is_superuser', sa.BOOLEAN(), nullable=False), | ||
sa.Column('is_verified', sa.BOOLEAN(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index('ix_user_email', 'user', ['email'], unique=False) | ||
# ### end Alembic commands ### |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""autho2 | ||
|
||
Revision ID: b44fef6dc06b | ||
Revises: ed436e5e9cd6 | ||
Create Date: 2021-11-18 20:48:38.550131 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b44fef6dc06b' | ||
down_revision = 'ed436e5e9cd6' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index('ix_user_email', table_name='user') | ||
op.drop_table('user') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('user', | ||
sa.Column('id', sa.CHAR(length=36), nullable=False), | ||
sa.Column('email', sa.VARCHAR(length=320), nullable=False), | ||
sa.Column('hashed_password', sa.VARCHAR(length=72), nullable=False), | ||
sa.Column('is_active', sa.BOOLEAN(), nullable=False), | ||
sa.Column('is_superuser', sa.BOOLEAN(), nullable=False), | ||
sa.Column('is_verified', sa.BOOLEAN(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index('ix_user_email', 'user', ['email'], unique=False) | ||
# ### end Alembic commands ### |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""autho2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the new migration files look incredibly sus There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've not been able to successfully migrate this, we could possibly check this out together later... having issues with FK and i haven't worked on it since the last time we spoke. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright no problem |
||
|
||
Revision ID: ed436e5e9cd6 | ||
Revises: 05e696f0741c | ||
Create Date: 2021-11-18 20:28:43.053448 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'ed436e5e9cd6' | ||
down_revision = '05e696f0741c' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from httpx_oauth.clients.google import GoogleOAuth2 | ||
from fastapi import Depends, Request | ||
from fastapi_users import BaseUserManager | ||
from typing import Optional | ||
from fastapi_users.authentication import JWTAuthentication | ||
from app.models import get_user_db | ||
import logging | ||
|
||
from app.models.models import UserCreate, UserDB | ||
from app.settings import settings | ||
|
||
|
||
class UserManager(BaseUserManager[UserCreate, UserDB]): | ||
user_db_model = UserDB | ||
reset_password_token_secret = settings.secret | ||
verification_token_secret = settings.secret | ||
|
||
async def on_after_register(self, user: UserDB, request: Optional[Request] = None): | ||
logging.info(f"User {user.id} has registered.") | ||
|
||
async def on_after_forgot_password( | ||
self, user: UserDB, token: str, request: Optional[Request] = None | ||
): | ||
logging.info( | ||
f"User {user.id} has forgot their password. Reset token: {token}") | ||
|
||
async def on_after_request_verify( | ||
self, user: UserDB, token: str, request: Optional[Request] = None | ||
): | ||
logging.info( | ||
f"Verification requested for user {user.id}. Verification token: {token}") | ||
|
||
|
||
async def get_user_manager(user_db=Depends(get_user_db)): | ||
yield UserManager(user_db) | ||
|
||
jwt_authentication = JWTAuthentication( | ||
secret=settings.secret, lifetime_seconds=3600, tokenUrl="auth/login") | ||
|
||
google_oauth_client = GoogleOAuth2( | ||
settings.google_client_id, settings.google_client_secret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this is actually a fake accoutn.