forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Enables direct frontend/backend communication sans Login.gov/Cloud.gov - Drives off new DEVELOPMENT env var - Pre-configures and disables frontend auth functionality - Testing based on new dev user - Install via web: ./manage.py generate_dev_user
- Loading branch information
Thomas Tignor
authored and
Thomas Tignor
committed
Nov 29, 2023
1 parent
9b1c2d1
commit 55fec3f
Showing
10 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,8 +4,23 @@ | |
|
||
from rest_framework.authentication import BaseAuthentication | ||
import logging | ||
import os | ||
logger = logging.getLogger(__name__) | ||
|
||
class DevAuthentication(BaseAuthentication): | ||
def authenticate(self, request): | ||
if not os.environ.get('DEVELOPMENT'): | ||
return None | ||
logging.debug(f"{self.__class__.__name__}: {request} ; {request.data}") | ||
requser = request.data.get("user") | ||
reqname = requser if requser and requser != "undefined" else "[email protected]" | ||
User = get_user_model() | ||
authuser = User.objects.get(username=reqname) | ||
if authuser and requser == "undefined": | ||
request.data["user"] = authuser.id | ||
return (User.objects.get(username=reqname), True) | ||
|
||
|
||
class CustomAuthentication(BaseAuthentication): | ||
"""Define authentication and get user functions for custom authentication.""" | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
tdrs-backend/tdpservice/users/management/commands/generate_dev_user.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,30 @@ | ||
#!/usr/bin/env python | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Group | ||
from django.core.management import BaseCommand | ||
|
||
User = get_user_model() | ||
|
||
email = "[email protected]" | ||
pswd = "pass" | ||
first = "Jon" | ||
last = "Tester" | ||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
user = User.objects.get(username=email) | ||
print(f"Found {vars(user)}") | ||
except User.DoesNotExist: | ||
group = Group.objects.get(name="Developer") | ||
user = User.objects.create(username=email, | ||
email=email, | ||
password=pswd, | ||
first_name=first, | ||
last_name=last, | ||
account_approval_status="Approved") | ||
user.groups.add(group) | ||
print(f"Created {vars(user)}") | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import { createBrowserHistory } from 'history' | |
import thunkMiddleware from 'redux-thunk' | ||
import loggerMiddleware from './middleware/logger' | ||
import createRootReducer from './reducers' | ||
import { permissions } from './components/Header/developer_permissions' | ||
|
||
export const history = createBrowserHistory() | ||
|
||
|
@@ -13,9 +14,29 @@ export const history = createBrowserHistory() | |
export default function configureStore(preloadedState) { | ||
const middlewares = [thunkMiddleware, loggerMiddleware] | ||
const composedEnhancers = composeWithDevTools(applyMiddleware(...middlewares)) | ||
const devState = { | ||
router: { location: { pathname: '/profile' } }, | ||
auth: { | ||
user: { | ||
email: '[email protected]', | ||
first_name: 'Jon', | ||
last_name: 'Tester', | ||
roles: [{ id: 1, name: 'Developer', permissions }], | ||
access_request: true, | ||
account_approval_status: 'Approved', | ||
stt: { | ||
id: 31, | ||
type: 'state', | ||
code: 'NJ', | ||
name: 'New Jersey', | ||
}, | ||
}, | ||
authenticated: true, | ||
}, | ||
} | ||
const store = createStore( | ||
createRootReducer(history), | ||
preloadedState, | ||
process.env.DEVELOPMENT ? devState : preloadedState, | ||
composedEnhancers | ||
) | ||
return store | ||
|