Commit fc0c39b4 authored by François Ferry's avatar François Ferry
Browse files

feat: create anonymous user at runtime if it doesn't exist already.

related: #88
parent f386f98916f5
......@@ -386,8 +386,19 @@ def includeme(config):
with repo.internal_cnx() as cnx:
login = config.registry['cubicweb.config'].anonymous_user()[0]
if login is not None:
config.registry['cubicweb.anonymous_eid'] = cnx.find(
'CWUser', login=login).one().eid
try:
config.registry['cubicweb.anonymous_eid'] = cnx.find(
'CWUser', login=login).one().eid
except cubicweb.NoResultError:
# Anonymous access is enabled, but anonymous user doesn't exist
# which happens when we authorized anonymous access on a previously
# private instance.
from cubicweb.server import create_user
anonlogin, anonpwd = config.registry['cubicweb.config'].anonymous_user()
create_user(cnx, anonlogin, anonpwd, 'guests')
cnx.commit()
config.registry['cubicweb.anonymous_eid'] = cnx.find(
'CWUser', login=login).one().eid
config.add_request_method(
_cw_session, name='cw_session', property=True, reify=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment