Skip to content

Commit d7a2517

Browse files
committed
drafted registration
1 parent 0136ef5 commit d7a2517

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

services/web/server/src/simcore_service_webserver/login/_controller/rest/preregistration.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from servicelib.aiohttp.application_keys import APP_FIRE_AND_FORGET_TASKS_KEY
1313
from servicelib.aiohttp.requests_validation import parse_request_body_as
1414
from servicelib.logging_utils import get_log_record_extra, log_context
15-
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
1615
from servicelib.request_keys import RQT_USERID_KEY
1716
from servicelib.utils import fire_and_forget_task
17+
from simcore_service_webserver.users._users_rest import PreRegisteredUserGet
1818

1919
from ...._meta import API_VTAG
2020
from ....constants import RQ_PRODUCT_KEY
@@ -71,11 +71,21 @@ async def request_product_account(request: web.Request):
7171
assert body.captcha # nosec
7272

7373
if body.captcha != session.get(CAPTCHA_SESSION_KEY):
74-
raise web.HTTPUnprocessableEntity(
75-
text=MSG_WRONG_CAPTCHA__INVALID, content_type=MIMETYPE_APPLICATION_JSON
76-
)
74+
raise web.HTTPUnprocessableEntity(text=MSG_WRONG_CAPTCHA__INVALID)
7775
session.pop(CAPTCHA_SESSION_KEY, None)
7876

77+
pre_user_profile = PreRegisteredUserGet.model_validate(
78+
# TODO: can raise vliadation error
79+
body.form
80+
)
81+
82+
user_profile = await _preregistration_service.create_pre_registration(
83+
# TODO: this raises AlreadyPreRegisteredError or ValidationError or anything regarding
84+
request.app,
85+
profile=pre_user_profile,
86+
product_name=product.name,
87+
)
88+
7989
# send email to fogbugz or user itself
8090
fire_and_forget_task(
8191
_preregistration_service.send_account_request_email_to_support(

services/web/server/src/simcore_service_webserver/login/_preregistration_service.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
from captcha.image import ImageCaptcha
88
from common_library.json_serialization import json_dumps
99
from models_library.emails import LowerCaseEmailStr
10+
from models_library.products import ProductName
1011
from models_library.utils.fastapi_encoders import jsonable_encoder
1112
from PIL.Image import Image
1213
from pydantic import EmailStr, PositiveInt, TypeAdapter, ValidationError
1314
from servicelib.utils_secrets import generate_passcode
15+
from simcore_service_webserver.users._users_rest import PreRegisteredUserGet
1416

1517
from ..email.utils import send_email_from_template
1618
from ..products import products_web
1719
from ..products.models import Product
20+
from ..users import _users_service
1821

1922
_logger = logging.getLogger(__name__)
2023

@@ -122,3 +125,12 @@ async def create_captcha() -> tuple[str, bytes]:
122125
image_data = img_byte_arr.getvalue()
123126

124127
return (captcha_text, image_data)
128+
129+
130+
async def create_pre_registration(
131+
app: web.Application, profile: PreRegisteredUserGet, product_name: ProductName
132+
):
133+
134+
await _users_service.pre_register_user(
135+
app, profile=profile, creator_user_id=None, product_name=product_name
136+
)

services/web/server/src/simcore_service_webserver/users/_users_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def pre_register_user(
4545
app: web.Application,
4646
*,
4747
profile: PreRegisteredUserGet,
48-
creator_user_id: UserID,
48+
creator_user_id: UserID | None,
4949
product_name: ProductName,
5050
) -> UserAccountGet:
5151

services/web/server/tests/unit/with_dbs/03/login/test_login_preregistration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async def test_request_an_account(
168168
assert client.app
169169
# A form similar to the one in https://github.com/ITISFoundation/osparc-simcore/pull/5378
170170
user_data = {
171-
**AccountRequestInfo.model_config["json_schema_extra"]["example"]["form"],
171+
**AccountRequestInfo.model_json_schema()["example"]["form"],
172172
# fields required in the form
173173
"firstName": faker.first_name(),
174174
"lastName": faker.last_name(),
@@ -188,8 +188,10 @@ async def test_request_an_account(
188188

189189
product = get_product(client.app, product_name="osparc")
190190

191-
# sent email?
191+
# check email was sent
192192
mimetext = mocked_send_email.call_args[1]["message"]
193193
assert "account" in mimetext["Subject"].lower()
194194
assert mimetext["From"] == product.support_email
195195
assert mimetext["To"] == product.product_owners_email or product.support_email
196+
197+
# TODO: switch to PO user and check if request is listed

0 commit comments

Comments
 (0)