API Reference
User module for user account management and authentication.
This module provides comprehensive user management including account creation, profile updates, authentication, MFA support, email verification, and admin approval workflows.
Exports
- CRUD: get_all_users, get_users_number, get_users_with_pagination, get_user_by_username, get_user_by_email, get_user_by_id, get_users_admin, create_user, create_signup_user, edit_user, approve_user, verify_user_email, edit_user_password, update_user_photo, update_user_mfa, delete_user
- Schemas: UsersBase, Users, UsersRead, UsersMe, UsersSignup, UsersCreate, UsersEditPassword, UsersListResponse
- Models: Users (ORM model)
- Enums: Gender, Language, WeekDay, UserAccessType
- Utils: get_user_by_id_or_404, get_admin_users_or_404, check_password_and_hash, check_user_is_active, create_user_default_data, save_user_image_file, delete_user_photo_filesystem
Gender
Bases: Enum
User gender enumeration.
Attributes:
| Name | Type | Description |
|---|---|---|
MALE |
Male gender. |
|
FEMALE |
Female gender. |
|
UNSPECIFIED |
Unspecified or undisclosed gender. |
Source code in backend/app/users/users/schema.py
18 19 20 21 22 23 24 25 26 27 28 29 30 | |
Language
Bases: Enum
Supported application languages.
Attributes:
| Name | Type | Description |
|---|---|---|
CATALAN |
Catalan (ca). |
|
CHINESE_SIMPLIFIED |
Simplified Chinese (cn). |
|
CHINESE_TRADITIONAL |
Traditional Chinese (tw). |
|
GERMAN |
German (de). |
|
FRENCH |
French (fr). |
|
GALICIAN |
Galician (gl). |
|
ITALIAN |
Italian (it). |
|
DUTCH |
Dutch (nl). |
|
PORTUGUESE |
Portuguese (pt). |
|
SLOVENIAN |
Slovenian (sl). |
|
SWEDISH |
Swedish (sv). |
|
SPANISH |
Spanish (es). |
|
ENGLISH_USA |
US English (us). |
Source code in backend/app/users/users/schema.py
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 61 62 63 64 65 | |
UserAccessType
Bases: Enum
User access level enumeration.
Attributes:
| Name | Type | Description |
|---|---|---|
REGULAR |
Standard user access. |
|
ADMIN |
Administrative access. |
Source code in backend/app/users/users/schema.py
91 92 93 94 95 96 97 98 99 100 101 | |
Users
Bases: UsersBase
Complete users schema with all fields.
Attributes:
| Name | Type | Description |
|---|---|---|
access_type |
UserAccessType
|
User access level. |
photo_path |
StrictStr | None
|
Path to user's photo. |
active |
StrictBool
|
Whether the user is active. |
mfa_enabled |
StrictBool
|
Whether MFA is enabled. |
mfa_secret |
StrictStr | None
|
MFA secret (encrypted at rest). |
email_verified |
StrictBool
|
Whether email is verified. |
pending_admin_approval |
StrictBool
|
Whether pending admin approval. |
Source code in backend/app/users/users/schema.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
UsersBase
Bases: BaseModel
Base users schema with common fields.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
StrictStr
|
User's full name (1-250 chars). |
username |
StrictStr
|
Unique username (1-250 chars, alphanumeric and dots). |
email |
EmailStr
|
User's email address (max 250 chars). |
city |
StrictStr | None
|
User's city (max 250 chars). |
birthdate |
date | None
|
User's birthdate. |
preferred_language |
Language
|
Preferred language. |
gender |
Gender
|
User's gender. |
units |
Units
|
User units (metric, imperial). |
height |
StrictInt | None
|
User's height in centimeters (1-300). |
max_heart_rate |
StrictInt | None
|
Maximum heart rate in bpm (30-250). |
first_day_of_week |
WeekDay
|
First day of the week. |
currency |
Currency
|
User currency (euro, dollar, pound). |
Source code in backend/app/users/users/schema.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
validate_birthdate
classmethod
validate_birthdate(value)
Convert birthdate to ISO format string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
date | str | None
|
Birthdate as date object, string, or None. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
ISO format date string or None. |
Source code in backend/app/users/users/schema.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
UsersCreate
Bases: Users
Users schema for admin user creation.
Attributes:
| Name | Type | Description |
|---|---|---|
password |
StrictStr
|
User's password (min 8 chars). |
Source code in backend/app/users/users/schema.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
UsersEditPassword
Bases: BaseModel
Schema for password update operations.
Attributes:
| Name | Type | Description |
|---|---|---|
password |
StrictStr
|
New password (min 8 chars). |
Source code in backend/app/users/users/schema.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
UsersListResponse
Bases: BaseModel
Response model for paginated user listing.
Attributes:
| Name | Type | Description |
|---|---|---|
total |
StrictInt
|
Total number of user records. |
num_records |
StrictInt | None
|
Number of records in this response. |
page_number |
StrictInt | None
|
Current page number. |
records |
list[UsersRead]
|
List of user records. |
Source code in backend/app/users/users/schema.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
UsersMe
Bases: UsersRead
Extended users schema for current user profile.
Includes privacy settings and integration status.
Attributes:
| Name | Type | Description |
|---|---|---|
is_strava_linked |
StrictInt | None
|
Strava integration status. |
is_garminconnect_linked |
StrictInt | None
|
Garmin Connect status. |
default_activity_visibility |
StrictStr | None
|
Default visibility level. |
hide_activity_start_time |
StrictBool | None
|
Hide start time setting. |
hide_activity_location |
StrictBool | None
|
Hide location setting. |
hide_activity_map |
StrictBool | None
|
Hide map setting. |
hide_activity_hr |
StrictBool | None
|
Hide heart rate setting. |
hide_activity_power |
StrictBool | None
|
Hide power setting. |
hide_activity_cadence |
StrictBool | None
|
Hide cadence setting. |
hide_activity_elevation |
StrictBool | None
|
Hide elevation setting. |
hide_activity_speed |
StrictBool | None
|
Hide speed setting. |
hide_activity_pace |
StrictBool | None
|
Hide pace setting. |
hide_activity_laps |
StrictBool | None
|
Hide laps setting. |
hide_activity_workout_sets_steps |
StrictBool | None
|
Hide workout sets/steps. |
hide_activity_gear |
StrictBool | None
|
Hide gear setting. |
Source code in backend/app/users/users/schema.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
UsersModel
Bases: Base
User account and profile information.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Mapped[int]
|
Primary key. |
name |
Mapped[str]
|
User's real name (may include spaces). |
username |
Mapped[str]
|
Unique username (letters, numbers, dots). |
email |
Mapped[str]
|
Unique email address (max 250 characters). |
password |
Mapped[str]
|
User's password hash. |
city |
Mapped[str | None]
|
User's city. |
birthdate |
Mapped[date | None]
|
User's birthdate. |
preferred_language |
Mapped[str]
|
Preferred language code. |
gender |
Mapped[str]
|
User's gender (male, female, unspecified). |
units |
Mapped[str]
|
Measurement units (metric, imperial). |
height |
Mapped[int | None]
|
User's height in centimeters. |
max_heart_rate |
Mapped[int | None]
|
User maximum heart rate (bpm). |
access_type |
Mapped[str]
|
User type (regular, admin). |
photo_path |
Mapped[str | None]
|
Path to user's photo. |
active |
Mapped[bool]
|
Whether the user is active. |
first_day_of_week |
Mapped[str]
|
First day of the week (sunday, monday, etc.). |
currency |
Mapped[str]
|
Currency preference (euro, dollar, pound). |
mfa_enabled |
Mapped[bool]
|
Whether multi-factor authentication is enabled. |
mfa_secret |
Mapped[str | None]
|
MFA secret for TOTP generation (encrypted at rest). |
email_verified |
Mapped[bool]
|
Whether the user's email address has been verified. |
pending_admin_approval |
Mapped[bool]
|
Whether the user is pending admin approval for activation. |
users_sessions |
List of session objects. |
|
password_reset_tokens |
List of password reset tokens. |
|
sign_up_tokens |
List of sign-up tokens. |
|
users_integrations |
List of integrations. |
|
users_default_gear |
List of default gear. |
|
users_privacy_settings |
List of privacy settings. |
|
gear |
List of gear owned by the user. |
|
gear_components |
List of gear components. |
|
activities |
List of activities performed. |
|
followers |
List of Follower objects representing users who follow this user. |
|
following |
List of Follower objects representing users this user is following. |
|
health_sleep |
List of health sleep records. |
|
health_weight |
List of health weight records. |
|
health_steps |
List of health steps records. |
|
health_targets |
List of health targets. |
|
notifications |
List of notifications. |
|
goals |
List of user goals. |
|
user_identity_providers |
List of identity providers linked to the user. |
|
oauth_states |
List of OAuth states for the user. |
|
mfa_backup_codes |
List of MFA backup codes. |
Source code in backend/app/users/users/models.py
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
UsersRead
Bases: Users
Users schema for read operations.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
User ID. |
external_auth_count |
StrictInt
|
Number of external auth providers. |
Source code in backend/app/users/users/schema.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
UsersSignup
Bases: UsersBase
Users schema for signup operations.
Attributes:
| Name | Type | Description |
|---|---|---|
password |
StrictStr
|
User's password (min 8 chars). |
Source code in backend/app/users/users/schema.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
WeekDay
Bases: Enum
Days of the week enumeration.
Attributes:
| Name | Type | Description |
|---|---|---|
SUNDAY |
Sunday. |
|
MONDAY |
Monday. |
|
TUESDAY |
Tuesday. |
|
WEDNESDAY |
Wednesday. |
|
THURSDAY |
Thursday. |
|
FRIDAY |
Friday. |
|
SATURDAY |
Saturday. |
Source code in backend/app/users/users/schema.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
approve_user
approve_user(user_id, db)
Approve a user by marking them as active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to approve. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
400 if user email not verified. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
check_password_and_hash
check_password_and_hash(password, password_hasher, server_settings, user_access_type)
Validates password against the configured policy and hashes it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
The password to validate and hash. |
required |
password_hasher
|
PasswordHasher
|
The password hasher instance. |
required |
server_settings
|
ServerSettings | ServerSettingsRead
|
The server settings containing password policies. |
required |
user_access_type
|
str
|
The access type of the user (e.g., "regular" or "admin"). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The hashed password. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If password validation fails. |
Source code in backend/app/users/users/utils.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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
check_user_is_active
check_user_is_active(user)
Check if user is active and raise 403 if inactive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Users | UsersRead
|
User object to check (User or UsersRead schema). |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
403 if user is not active. |
Source code in backend/app/users/users/utils.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
create_signup_user
create_signup_user(user, server_settings, password_hasher, db)
Create a new user during signup process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
UsersSignup
|
User signup data. |
required |
server_settings
|
ServerSettingsRead
|
Server config for signup requirements. |
required |
password_hasher
|
PasswordHasher
|
Password hasher instance. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
Users
|
Created Users model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 if email/username already exists. Abstract message to reduce information leakage. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
create_user
create_user(user, password_hasher, db)
Create a new user with hashed password.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
UsersCreate
|
User creation data with plain text password. |
required |
password_hasher
|
PasswordHasher
|
Password hasher instance. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
Users
|
Created Users model with hashed password. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 if email/username already exists. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
create_user_default_data
create_user_default_data(user_id, db)
Create default data for newly created user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to create default data for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in backend/app/users/users/utils.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
delete_user
async
delete_user(user_id, db)
Delete a user from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to delete. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
delete_user_photo_filesystem
async
delete_user_photo_filesystem(user_id)
Delete user photo files from filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user whose photo files to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in backend/app/users/users/utils.py
211 212 213 214 215 216 217 218 219 220 221 222 223 | |
edit_user
async
edit_user(user_id, user, db)
Update an existing user's information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to update. |
required |
user
|
UsersRead
|
User data to update with. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
Users
|
users_models.Users |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
409 if email/username conflict. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
edit_user_password
edit_user_password(user_id, password, password_hasher, db, is_hashed=False)
Update a user's password.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to update password for. |
required |
password
|
str
|
New password (plain text or hashed based on is_hashed). |
required |
password_hasher
|
PasswordHasher
|
Password hasher instance. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
is_hashed
|
bool
|
Whether password is already hashed. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
get_admin_users_or_404
get_admin_users_or_404(db)
Retrieve all admin users from database or raise 404 error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
list[Users]
|
List of all admin User models. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if no admin users found. |
Source code in backend/app/users/users/utils.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
get_all_users
get_all_users(db)
Retrieve all users from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
list[Users]
|
List of all User models. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
get_user_by_email
get_user_by_email(email, db)
Retrieve user by email address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Email address to search for (case-insensitive). |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
Users | None
|
Users model if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_user_by_id
get_user_by_id(user_id, db, public_check=False)
Retrieve user by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
public_check
|
bool
|
If True, only returns user when public sharing is enabled in server settings. |
False
|
Returns:
| Type | Description |
|---|---|
Users | None
|
Users model if found (and public sharing enabled if |
Users | None
|
public_check=True), None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
get_user_by_id_or_404
get_user_by_id_or_404(user_id, db)
Retrieve user by ID or raise 404 error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
Users
|
Users model (guaranteed non-None). |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
Source code in backend/app/users/users/utils.py
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 | |
get_user_by_username
get_user_by_username(username, db, contains=False)
Retrieve user by username.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
Username to search for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
contains
|
bool
|
If True, performs partial match search and returns list of matching users. If False, performs exact match and returns single user or None. |
False
|
Returns:
| Type | Description |
|---|---|
list[Users] | Users | None
|
If contains=False: Users model if found, None otherwise. |
list[Users] | Users | None
|
If contains=True: List of User models matching the search. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
get_users_admin
get_users_admin(db)
Retrieve all admin users from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
list[Users]
|
List of User models with admin access. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
get_users_number
get_users_number(db)
Get total count of users in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Total number of users. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_users_with_pagination
get_users_with_pagination(db, page_number=1, num_records=5)
Retrieve paginated list of users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy database session. |
required |
page_number
|
int
|
Page number to retrieve (1-indexed). |
1
|
num_records
|
int
|
Number of records per page. |
5
|
Returns:
| Type | Description |
|---|---|
list[Users]
|
List of User models for the requested page. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/users/users/crud.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
save_user_image_file
async
save_user_image_file(user_id, file, db)
Save user image file with security validation and update DB.
Uses centralized file upload handler for validation and async I/O, then updates user photo path in database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user whose image is being saved. |
required |
file
|
UploadFile
|
Uploaded image file (UploadFile). |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Path to saved image file. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if filename missing, 500 if upload fails. |
Source code in backend/app/users/users/utils.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
update_user_mfa
update_user_mfa(user_id, db, encrypted_secret=None)
Update a user's MFA settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to update MFA for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
encrypted_secret
|
str | None
|
Encrypted MFA secret. If None, disables MFA. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
update_user_photo
async
update_user_photo(user_id, db, photo_path=None)
Update a user's photo path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to update photo for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
photo_path
|
str | None
|
New photo path. If None, removes photo. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The updated photo path, or None if removed. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
verify_user_email
verify_user_email(user_id, server_settings, db)
Verify user email and conditionally activate account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
ID of user to verify. |
required |
server_settings
|
ServerSettingsRead
|
Server config determining activation policy. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if user not found. |
HTTPException
|
500 if database error occurs. |
Source code in backend/app/users/users/crud.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |