removed cookies usages from API

pull/67/head
13621160019@163.com 2021-09-06 11:52:47 +08:00 committed by Caozhenhui
parent f28b21077d
commit 14d0b7aa77
5 changed files with 11 additions and 27 deletions

View File

@ -117,9 +117,7 @@ git clone https://github.com/MyEMS/myems.git
cd ~/myems/myems-api cd ~/myems/myems-api
sudo cp -R ~/myems/myems-api /myems-api sudo cp -R ~/myems/myems-api /myems-api
``` ```
Change the config file: Change IP address in the config file:
Note: change cookie domain to the actual domain or IP address of Web UI and Admin UI
```bash ```bash
sudo nano /myems-api/config.py sudo nano /myems-api/config.py
``` ```
@ -283,9 +281,9 @@ curl -i -X GET {{base_url}}/costfiles
curl -i -X DELETE {{base_url}}/costfiles/{id} curl -i -X DELETE {{base_url}}/costfiles/{id}
``` ```
* POST Upload a Cost File * POST Upload a Cost File
(user must login first to get cookie) (call users login API to get 'User-UUID' and 'Token')
```bash ```bash
curl -i -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/costfiles curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: 02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48" -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/costfiles
``` ```
* GET Restore a Cost File by ID from database to disk * GET Restore a Cost File by ID from database to disk
```bash ```bash
@ -944,9 +942,9 @@ curl -i -X GET {{base_url}}/knowledgefiles
curl -i -X DELETE {{base_url}}/knowledgefiles/{id} curl -i -X DELETE {{base_url}}/knowledgefiles/{id}
``` ```
* POST Upload a Knowledge File * POST Upload a Knowledge File
(user must login first to get cookie) (call users login API to get 'User-UUID' and 'Token')
```bash ```bash
curl -i -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/knowledgefiles curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: 02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48" -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/knowledgefiles
``` ```
* GET Restore a Knowledge File by id from database to disk * GET Restore a Knowledge File by id from database to disk
```bash ```bash
@ -1140,9 +1138,9 @@ curl -i -X GET {{base_url}}/offlinemeterfiles
curl -i -X DELETE {{base_url}}/offlinemeterfiles/{id} curl -i -X DELETE {{base_url}}/offlinemeterfiles/{id}
``` ```
* POST Upload an Offline Meter File * POST Upload an Offline Meter File
(user must log in first to get cookie) (call users login API to get 'User-UUID' and 'Token')
```bash ```bash
curl -i -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/offlinemeterfiles curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: 02f93023a39c98e1d1bc9f5197a83dfc5ddc0d48" -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/offlinemeterfiles
``` ```
* GET Restore an Offline Meter File by ID from database to disk * GET Restore an Offline Meter File by ID from database to disk
```bash ```bash

View File

@ -61,10 +61,6 @@ myems_reporting_db = {
'database': 'myems_reporting_db', 'database': 'myems_reporting_db',
} }
# address for Cookie domain
# use the actual domain or IP address of Web UI and Admin UI
myems_api_domain = '127.0.0.1'
# indicated in how many minutes to calculate meter energy consumption # indicated in how many minutes to calculate meter energy consumption
# 30 for half hourly period # 30 for half hourly period
# 60 for hourly period # 60 for hourly period

View File

@ -447,10 +447,6 @@ class UserLogin:
cnx.commit() cnx.commit()
cursor.close() cursor.close()
cnx.disconnect() cnx.disconnect()
resp.set_cookie('user_uuid', user_uuid,
domain=config.myems_api_domain, path='/', secure=False, http_only=False)
resp.set_cookie('token', token,
domain=config.myems_api_domain, path='/', secure=False, http_only=False)
del result['salt'] del result['salt']
del result['password'] del result['password']
result['token'] = token result['token'] = token
@ -502,11 +498,6 @@ class UserLogout:
if rowcount is None or rowcount == 0: if rowcount is None or rowcount == 0:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.USER_SESSION_NOT_FOUND') description='API.USER_SESSION_NOT_FOUND')
resp.set_cookie('user_uuid', '',
domain=config.myems_api_domain, path='/', secure=False, http_only=False)
resp.set_cookie('token', '',
domain=config.myems_api_domain, path='/', secure=False, http_only=False)
resp.body = json.dumps("OK") resp.body = json.dumps("OK")
resp.status = falcon.HTTP_200 resp.status = falcon.HTTP_200

View File

@ -54,12 +54,12 @@ def user_logger(func):
func(*args, **kwargs) func(*args, **kwargs)
return return
req, resp = args req, resp = args
cookies = req.cookies headers = req.headers
if cookies is not None and 'user_uuid' in cookies.keys(): if headers is not None and 'USER-UUID' in headers.keys():
user_uuid = cookies['user_uuid'] user_uuid = headers['USER-UUID']
else: else:
# todo: deal with requests with NULL user_uuid # todo: deal with requests with NULL user_uuid
print('user_logger: user_uuid is NULL') print('user_logger: USER-UUID is NULL')
# do not log for NULL user_uuid # do not log for NULL user_uuid
func(*args, **kwargs) func(*args, **kwargs)
return return

View File

@ -33,7 +33,6 @@ class Reporting:
#################################################################################################################### ####################################################################################################################
@staticmethod @staticmethod
def on_get(req, resp): def on_get(req, resp):
print(req.params)
user_uuid = req.params.get('useruuid') user_uuid = req.params.get('useruuid')
period_type = req.params.get('periodtype') period_type = req.params.get('periodtype')
base_start_datetime_local = req.params.get('baseperiodstartdatetime') base_start_datetime_local = req.params.get('baseperiodstartdatetime')