paulbricman commited on
Commit
70d46f4
1 Parent(s): 9060bc1

fix: closes #26

Browse files

Files changed (1) hide show
  1. backend/security.py +9 -4
backend/security.py CHANGED
@@ -1,5 +1,6 @@
1
  from pathlib import Path
2
  import json
 
3
 
4
 
5
  def auth(token, compact=False):
@@ -8,19 +9,23 @@ def auth(token, compact=False):
8
  'custodian': False
9
  }
10
 
11
- path = Path('..') / 'knowledge' / 'records.json'
 
 
 
 
 
12
 
13
- if not path.exists():
14
  records = {
15
  'custodian_token': token
16
  }
17
- json.dump(records, open(path, 'w'))
18
 
19
  return {
20
  'custodian': True
21
  }
22
  else:
23
- records = json.load(open(path))
24
 
25
  if records['custodian_token'] == token:
26
  return {
1
  from pathlib import Path
2
  import json
3
+ import os
4
 
5
 
6
  def auth(token, compact=False):
9
  'custodian': False
10
  }
11
 
12
+ knowledge_base_path = Path('..') / 'knowledge'
13
+ records_path = knowledge_base_path / 'records.json'
14
+
15
+ if not records_path.exists():
16
+ if not knowledge_base_path.exists():
17
+ os.mkdir(knowledge_base_path)
18
 
 
19
  records = {
20
  'custodian_token': token
21
  }
22
+ json.dump(records, open(records_path, 'w'))
23
 
24
  return {
25
  'custodian': True
26
  }
27
  else:
28
+ records = json.load(open(records_path))
29
 
30
  if records['custodian_token'] == token:
31
  return {