island: Drop mongo db when registartion requirement is realised instead

of when registration request is sent

The issue with this whole change is that there's a long gap where
nothing happens after you click on the log in or register button on the
UI.

But we don't need to worry about this because we plan on shipping
Island's mongodb with attack mitigations already present.
This commit is contained in:
Shreya Malviya 2021-09-27 14:36:55 +05:30 committed by VakarisZ
parent 340dd1f94b
commit 6fe4d6cb31
1 changed files with 5 additions and 3 deletions

View File

@ -16,14 +16,16 @@ logger = logging.getLogger(__name__)
class Registration(flask_restful.Resource):
def get(self):
return {"needs_registration": env_singleton.env.needs_registration()}
is_registration_needed = env_singleton.env.needs_registration()
if is_registration_needed:
# if registration is required, drop previous user's data (for credentials reset case)
_drop_mongo_db()
return {"needs_registration": is_registration_needed}
def post(self):
credentials = _get_user_credentials_from_request(request)
try:
# if new registration is required (credentials are reset), drop previous user's data
_drop_mongo_db()
env_singleton.env.try_add_user(credentials)
init_collections()
return make_response({"error": ""}, 200)