Users can now be invited to an org by email. "Email" for now is "print to stdout" Resolves #12
This commit is contained in:
parent
1012947b67
commit
62c43ce883
5 changed files with 173 additions and 5 deletions
|
|
@ -6,10 +6,12 @@ Exports:
|
|||
"""
|
||||
|
||||
from typing import Any
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.exceptions import UnprocessableContentException
|
||||
from src.utils import send_email, generate_jwt
|
||||
|
||||
from src.user.schemas import OIDCUser
|
||||
from src.user.models import User
|
||||
|
|
@ -48,3 +50,24 @@ async def add_user_to_db(db: Session, user_claims: dict[str, Any]) -> int:
|
|||
db.add(db_user)
|
||||
db.commit()
|
||||
return user_id
|
||||
|
||||
|
||||
async def send_invitation(user_email: str, org_name: str, org_id: int):
|
||||
expiry_delta = timedelta(hours=24)
|
||||
expiry = datetime.now(timezone.utc) + expiry_delta
|
||||
claims = {
|
||||
"email": user_email,
|
||||
"org_id": org_id,
|
||||
"exp": expiry,
|
||||
"type": "org_invite",
|
||||
}
|
||||
|
||||
token = await generate_jwt(claims)
|
||||
subject = f"You have been invited to join {org_name}"
|
||||
body = f"You have been invited to join {org_name}.\nClick the link to accept.\nfrontend.capture/send/to/endpoint/{token}"
|
||||
|
||||
await send_email(
|
||||
recipient=user_email,
|
||||
subject=subject,
|
||||
body=body,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue