Skip to content

Instantly share code, notes, and snippets.

@stefbrad15
Created August 6, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefbrad15/3e41ca85a28fcf4a9553fe8f3a28693f to your computer and use it in GitHub Desktop.
Save stefbrad15/3e41ca85a28fcf4a9553fe8f3a28693f to your computer and use it in GitHub Desktop.
Add users functionality
from app import app
from app.helpers import user_helpers as u_helper
from app.helpers import DynamoInterface
from flask import jsonify, request
@app.route("/api/user", methods=['GET'])
def get_user():
username = request.args['username']
password = request.args['password']
encrypted_pass = u_helper.encrypt_password(password)
i_dynamo = DynamoInterface()
user_table = i_dynamo.get_table('users')
try:
user = user_table.get_item(
username=username,
password=encrypted_pass
)
return jsonify(dict(user))
except Exception as e:
return str(e)
@app.route('/api/users', methods=['GET'])
def get_all_users():
i_dynamo = DynamoInterface()
tables = i_dynamo.list_tables()
app.logger.debug(tables)
if "users" not in tables:
users = u_helper.create_user_table(i_dynamo, app.logger)
return jsonify(users)
else:
attributes = (
'username',
'first_name',
'last_name',
'account_type'
)
users = i_dynamo.get_all_items("users", attributes)
return jsonify(users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment