(username: str,
password: str,
application_password: str,
full_name: Optional[str] = None)
| 117 | # Endpoint for creating first user, at launch with appliaction password rather than user credentials |
| 118 | @router.post('/launch_user') |
| 119 | async def first_user(username: str, |
| 120 | password: str, |
| 121 | application_password: str, |
| 122 | full_name: Optional[str] = None): |
| 123 | |
| 124 | # Check application password is correct |
| 125 | if application_password != Config.APP_PASSWORD: |
| 126 | denial = HTTPException( |
| 127 | status_code=status.HTTP_401_UNAUTHORIZED, |
| 128 | detail="Incorrect application password, please try again.", |
| 129 | headers={"WWW-Authenticate": "Bearer"}, |
| 130 | ) |
| 131 | time.sleep(1) |
| 132 | return denial |
| 133 | |
| 134 | # Create dictionary of new user attributes |
| 135 | attributes = { |
| 136 | 'username': username, |
| 137 | 'full_name': full_name, |
| 138 | 'hashed_password': create_password_hash(password), |
| 139 | 'joined': str(datetime.now(timezone.utc)), |
| 140 | 'disabled': False, |
| 141 | } |
| 142 | |
| 143 | # Write Cypher query and run against the database |
| 144 | cypher_search = 'MATCH (user:User) WHERE user.username = $username RETURN user' |
| 145 | cypher_create = 'CREATE (user:User $params) RETURN user' |
| 146 | |
| 147 | with neo4j_driver.session() as session: |
| 148 | # First, run a search of users to determine if username is already in use |
| 149 | check_users = session.run(query=cypher_search, parameters={'username': username}) |
| 150 | |
| 151 | # Return error message if username is already in the database |
| 152 | if check_users.data(): |
| 153 | raise HTTPException( |
| 154 | status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, |
| 155 | detail=f"Operation not permitted, user with username {username} already exists.", |
| 156 | headers={"WWW-Authenticate": "Bearer"} |
| 157 | ) |
| 158 | |
| 159 | response = session.run(query=cypher_create, parameters={'params': attributes}) |
| 160 | user_data = response.data()[0]['user'] |
| 161 | return User(**user_data) |
nothing calls this directly
no test coverage detected