44from aiohttp import web
55from servicelib .mimetype_constants import MIMETYPE_APPLICATION_JSON
66from simcore_postgres_database .models .users import UserStatus
7+ from simcore_postgres_database .utils_repos import transaction_context
78from simcore_postgres_database .utils_users import UsersRepo
9+ from simcore_service_webserver .db .plugin import get_asyncpg_engine
810
9- from ..db .plugin import get_database_engine
10- from ..groups .api import is_user_by_email_in_group
11+ from ..groups import api as groups_service
1112from ..products .models import Product
12- from ..security . api import check_password , encrypt_password
13+ from ..security import api as security_service
1314from . import _login_service
1415from ._constants import MSG_UNKNOWN_EMAIL , MSG_WRONG_PASSWORD
1516from ._login_repository_legacy import AsyncpgStorage , get_plugin_storage
@@ -30,16 +31,16 @@ async def create_user(
3031 expires_at : datetime | None ,
3132) -> dict [str , Any ]:
3233
33- async with get_database_engine ( app ). acquire ( ) as conn :
34+ async with transaction_context ( get_asyncpg_engine ( app )) as conn :
3435 user = await UsersRepo .new_user (
3536 conn ,
3637 email = email ,
37- password_hash = encrypt_password (password ),
38+ password_hash = security_service . encrypt_password (password ),
3839 status = status_upon_creation ,
3940 expires_at = expires_at ,
4041 )
41- await UsersRepo .join_and_update_from_pre_registration_details (
42- conn , user .id , user .email
42+ await UsersRepo .link_and_update_user_from_pre_registration (
43+ conn , new_user_id = user .id , new_user_email = user .email
4344 )
4445 return dict (user .items ())
4546
@@ -57,7 +58,7 @@ async def check_authorized_user_credentials_or_raise(
5758
5859 _login_service .validate_user_status (user = user , support_email = product .support_email )
5960
60- if not check_password (password , user ["password_hash" ]):
61+ if not security_service . check_password (password , user ["password_hash" ]):
6162 raise web .HTTPUnauthorized (
6263 reason = MSG_WRONG_PASSWORD , content_type = MIMETYPE_APPLICATION_JSON
6364 )
@@ -75,8 +76,11 @@ async def check_authorized_user_in_product_or_raise(
7576 product_group_id = product .group_id
7677 assert product_group_id is not None # nosec
7778
78- if product_group_id is not None and not await is_user_by_email_in_group (
79- app , user_email = email , group_id = product_group_id
79+ if (
80+ product_group_id is not None
81+ and not await groups_service .is_user_by_email_in_group (
82+ app , user_email = email , group_id = product_group_id
83+ )
8084 ):
8185 raise web .HTTPUnauthorized (
8286 reason = MSG_UNKNOWN_EMAIL , content_type = MIMETYPE_APPLICATION_JSON
0 commit comments