@@ -19,95 +19,11 @@ |
subtitle = "A CDPHE Analysis Tool by eRAMS" |
|
disable_oauth = True |
- enable_direct_sign_in = True |
+ enable_direct_sign_in = False |
+ enable_registration = False |
+ enable_anonymous = True |
scratch_project_url = { |
"name": "New Project", |
"url": "/", |
} |
- enable_anonymous = True |
- |
user_data_path = "gis_data/users/users_303d_hashed.json" |
- |
- enable_registration = False |
- |
- |
- def get_user_collection(self): |
- #fullPath = os.path.join(get_cwd(), self.user_data_path) # TODO use this one for development |
- fullPath = self.user_data_path # TODO switch to this line for production builds, since gis_data is up at the top level |
- if os.path.exists(fullPath): |
- with open(fullPath) as fp: |
- j = json.load(fp) |
- return j["users"] |
- # This exception spits out a lot of information aimed to help debug file path issues with new installs |
- raise Exception("User path does not exist from current path") |
- |
- def set_user_collection(self, coll): |
- with open(self.user_data_path, "w") as fp: |
- json.dump({"users": coll}, fp, indent=4) |
- |
- def verify_password(self, stored_password, provided_password): |
- """Verify a stored password against one provided by user""" |
- salt = stored_password[:64] |
- stored_password = stored_password[64:] |
- pwdhash = hashlib.pbkdf2_hmac( |
- "sha512", provided_password.encode("utf-8"), salt.encode("ascii"), 100000 |
- ) |
- pwdhash = binascii.hexlify(pwdhash).decode("ascii") |
- return pwdhash == stored_password |
- |
- def handle_authentication(self, request, user_attrs): |
- user_id, email, first_name, last_name, attrs = [None] * 5 |
- if "username" in user_attrs and user_attrs["username"]: |
- user_id = user_attrs["username"] |
- if os.path.exists(self.user_data_path): |
- with open(self.user_data_path) as fp: |
- j = json.load(fp) |
- user_info = j["users"].get(user_attrs["username"], None) |
- if user_info: |
- pw_hashed = user_info["password"] |
- if self.verify_password(pw_hashed, user_attrs["password"]): |
- attrs = { |
- "projects": [ |
- { |
- "name": user_id, |
- "type": "303d", |
- "url": "/", |
- }, |
- ], |
- } |
- email = user_info.get("email", "") |
- first_name = user_info.get("firstName", "") |
- last_name = user_info.get("lastName", "") |
- else: |
- user_id = None # reset back to none for data access reasons |
- attrs = { |
- "error": "Login failed", |
- } |
- else: |
- user_id = None # reset back to none for data access reasons |
- attrs = { |
- "error": "User does not exist", |
- } |
- else: |
- user_id = None # reset back to none for data access reasons |
- attrs = { |
- "error": "User data not found", |
- } |
- else: |
- # anonymous login |
- attrs = { |
- "projects": [ |
- { |
- "name": "anonymous", |
- "type": "303d", |
- "url": "/", |
- }, |
- ], |
- } |
- |
- token = user_attrs.get("token", request.session.get("token", None)) |
- # if login succeeded, projects will exist |
- if token and "projects" in attrs: |
- for p in attrs["projects"]: |
- p["url"] += f"?token={token}" |
- return user_id, email, first_name, last_name, attrs |