-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:EVS-GIS/woodcam-rm into main
- Loading branch information
Showing
10 changed files
with
97 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,56 @@ | ||
import sys | ||
import simplejson as json | ||
from flask_httpauth import HTTPBasicAuth | ||
from werkzeug.security import check_password_hash | ||
|
||
from flask_restx import Resource | ||
from woodcamrm import api | ||
from woodcamrm.db import Stations, Users | ||
|
||
|
||
auth = HTTPBasicAuth() | ||
|
||
@auth.verify_password | ||
def authenticate(username, password): | ||
if username and password: | ||
|
||
user = Users.query.filter_by(username=username).first() | ||
|
||
error = None | ||
|
||
if user is None: | ||
error = 'Incorrect username.' | ||
elif not check_password_hash(user.password, password): | ||
error = 'Incorrect password.' | ||
|
||
if error is None: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
|
||
@api.route('/datarecovery') | ||
@api.doc(params={'station': 'Station ID', | ||
'from_ts': 'From timestamp', | ||
'to_ts': 'To timestamp'}) | ||
class DataRecovery(Resource): | ||
|
||
@api.doc(responses={403: 'Not Authorized'}) | ||
def get(self, station, from_ts, to_ts): | ||
api.abort(403) | ||
decorators = [auth.login_required] | ||
|
||
def post(self, station, from_ts, to_ts): | ||
return {'station': station, | ||
'from_ts': from_ts, | ||
'to_ts': to_ts} | ||
'to_ts': to_ts} | ||
|
||
|
||
@api.route('/stations') | ||
class StationsEndpoint(Resource): | ||
decorators = [auth.login_required] | ||
|
||
def get(self): | ||
|
||
stations = Stations.query.all() | ||
results = {st.common_name:st.__dict__ for st in stations} | ||
results = json.dumps(results, use_decimal=True, default=lambda o: 'NA') | ||
|
||
return {'data': results} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.