@@ -55,38 +55,45 @@ async def get_public_project(app: web.Application, project_uuid: str):
55
55
return prj
56
56
57
57
58
- # TODO: from .users import create_temporary_user
59
58
async def create_temporary_user (request : web .Request ):
60
59
"""
61
60
TODO: user should have an expiration date and limited persmissions!
62
61
"""
63
62
from .login .cfg import get_storage
64
- from .login .handlers import ACTIVE , GUEST
63
+ from .login .handlers import ACTIVE , GUEST , ANONYMOUS
65
64
from .login .utils import get_client_ip , get_random_string
66
65
from .security_api import encrypt_password
67
-
68
- # from .utils import generate_passphrase
69
- # from .utils import generate_password
66
+ from .resource_manager .websocket_manager import WebsocketRegistry
70
67
71
68
db = get_storage (request .app )
72
69
73
70
# TODO: avatar is an icon of the hero!
74
- # FIXME: # username = generate_passphrase(number_of_words=2).replace(" ", "_").replace("'", "")
75
71
username = get_random_string (min_len = 5 )
76
72
email = username + "@guest-at-osparc.io"
77
73
password = get_random_string (min_len = 12 )
78
74
75
+ # creates a user that is marked as ANONYMOUS
79
76
user = await db .create_user (
80
77
{
81
78
"name" : username ,
82
79
"email" : email ,
83
80
"password_hash" : encrypt_password (password ),
84
81
"status" : ACTIVE ,
85
- "role" : GUEST ,
82
+ "role" : ANONYMOUS ,
86
83
"created_ip" : get_client_ip (request ),
87
84
}
88
85
)
89
86
87
+ # creates an entry in the socket's registry to avoid garbage collector (GC) deleting it
88
+ # See https://github.com/ITISFoundation/osparc-simcore/issues/1853
89
+ registry = WebsocketRegistry (user ["id" ], f"{ username } -guest-session" , request .app )
90
+ await registry .set_socket_id (f"{ username } -guest-socket-id" )
91
+
92
+ # Now that we know the ID, we set the user as GUEST
93
+ # This extra step is to prevent the possibility that the GC is cleaning while
94
+ # the function above is creating the entry in the socket
95
+ await db .update_user (user , updates = {"role" : GUEST })
96
+
90
97
return user
91
98
92
99
0 commit comments