This commit is contained in:
Timothy Jaeryang Baek
2026-07-27 04:46:12 -04:00
parent 50e050e195
commit 39206602ac
2 changed files with 11 additions and 38 deletions
+11 -23
View File
@@ -3,13 +3,12 @@
from __future__ import annotations
import logging
import time
import uuid
from typing import Optional
import bcrypt
from open_webui.internal.db import Base, JSONField, get_async_db_context
from open_webui.models.users import User, UserModel, UserProfileImageResponse, Users
from open_webui.models.users import UserModel, UserProfileImageResponse, Users
from open_webui.utils.validate import validate_profile_image_url
from pydantic import BaseModel, field_validator
from sqlalchemy import Boolean, Column, String, Text, delete, select, update
@@ -111,13 +110,12 @@ class AuthsTable:
role: str = 'pending',
oauth: dict | None = None,
db: AsyncSession | None = None,
user_id: str | None = None,
) -> UserModel | None:
"""Create an Auth + User pair inside a single transaction."""
async with get_async_db_context(db) as session:
log.info('insert_new_auth')
new_id = user_id or str(uuid.uuid4())
new_id = str(uuid.uuid4())
credential = Auth(
id=new_id,
@@ -128,25 +126,15 @@ class AuthsTable:
session.add(credential)
try:
profile_image_url = validate_profile_image_url(profile_image_url)
except ValueError:
profile_image_url = '/user.png'
now = int(time.time())
created_user = UserModel(
id=new_id,
email=email,
name=name,
role=role,
profile_image_url=profile_image_url,
last_active_at=now,
created_at=now,
updated_at=now,
oauth=oauth,
)
session.add(User(**created_user.model_dump()))
try:
created_user = await Users.insert_new_user(
new_id,
name,
email,
profile_image_url,
role,
oauth=oauth,
db=session,
)
await session.commit()
except IntegrityError:
await session.rollback()