API Reference
Sign-up tokens module for user registration.
This module provides CRUD operations, email messaging, and utilities for sign-up token management.
Exports
- CRUD: create_sign_up_token, get_sign_up_token_by_hash, mark_sign_up_token_used, delete_expired_sign_up_tokens
- Schemas: SignUpToken, SignUpConfirm, SignUpResponse
- Models: SignUpToken (ORM model)
SignUpConfirm
Bases: BaseModel
Request schema for confirming a sign-up.
Attributes:
| Name | Type | Description |
|---|---|---|
token |
StrictStr
|
The sign-up token received by user. |
Source code in backend/app/sign_up_tokens/schema.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
SignUpResponse
Bases: BaseModel
Response schema for sign-up operations.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
StrictStr
|
Human-readable result message. |
email_verification_required |
StrictBool | None
|
Whether email verification is required. |
admin_approval_required |
StrictBool | None
|
Whether admin approval is required. |
Source code in backend/app/sign_up_tokens/schema.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
SignUpToken
Bases: BaseModel
Schema representing a sign-up token record.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictStr
|
Unique identifier for the token. |
user_id |
StrictInt
|
ID of the user who signed up. |
token_hash |
StrictStr
|
Hashed token value. |
created_at |
datetime
|
Timestamp when token was created. |
expires_at |
datetime
|
Timestamp when the token expires. |
used |
StrictBool
|
Whether the token has been used. |
Source code in backend/app/sign_up_tokens/schema.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
SignUpTokenModel
Bases: Base
Sign-up token database model.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Mapped[str]
|
Unique token identifier (string, 64 chars). |
user_id |
Mapped[int]
|
ID of the user who owns the token. |
token_hash |
Mapped[str]
|
Hashed sign-up token. |
created_at |
Mapped[datetime]
|
Token creation date. |
expires_at |
Mapped[datetime]
|
Token expiration date. |
used |
Mapped[bool]
|
Whether the token has been used. |
users |
Mapped[Users]
|
Relationship to the Users model. |
Source code in backend/app/sign_up_tokens/models.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
create_sign_up_token
create_sign_up_token(token, db)
Create and persist a new sign-up token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
SignUpToken
|
Schema object with token data to persist. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
SignUpToken
|
The persisted SignUpToken ORM instance. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/sign_up_tokens/crud.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
delete_expired_sign_up_tokens
delete_expired_sign_up_tokens(db)
Delete all expired sign-up tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of deleted rows. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/sign_up_tokens/crud.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_sign_up_token_by_hash
get_sign_up_token_by_hash(token_hash, db)
Retrieve an unused, unexpired token matching the hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_hash
|
str
|
The hashed token value to look up. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
SignUpToken | None
|
The matching SignUpToken if found and valid, |
SignUpToken | None
|
None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/sign_up_tokens/crud.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
mark_sign_up_token_used
mark_sign_up_token_used(token_id, db)
Mark a sign-up token as used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_id
|
str
|
The unique identifier of the token. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
SignUpToken | None
|
Updated SignUpToken instance if found, |
SignUpToken | None
|
None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/sign_up_tokens/crud.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |