Skip to content

Commit

Permalink
modify and rename unlockUser
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Damico committed May 26, 2021
1 parent 19f70d9 commit 730310f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
9 changes: 5 additions & 4 deletions LDlink/LDlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from LDassoc import calculate_assoc
from SNPclip import calculate_clip
from SNPchip import calculate_chip, get_platform_request
from RegisterAPI import register_user, checkToken, checkBlocked, checkLocked, toggleLocked, logAccess, emailJustification, blockUser, unblockUser, getToken, getStats, unlockUser, unlockAllUsers, getLockedUsers, getBlockedUsers
from RegisterAPI import register_user, checkToken, checkBlocked, checkLocked, toggleLocked, logAccess, emailJustification, blockUser, unblockUser, getToken, getStats, setUserLock, unlockAllUsers, getLockedUsers, getBlockedUsers
from werkzeug.utils import secure_filename
from werkzeug.debug import DebuggedApplication

Expand Down Expand Up @@ -236,12 +236,13 @@ def unblock_user():
return sendJSON(out_json)

# Web route to unlock user's API token
@app.route('/LDlinkRestWeb/apiaccess/unlock_user', methods=['GET'])
@app.route('/LDlinkRestWeb/apiaccess/set_user_lock', methods=['GET'])
@requires_admin_token
def unlock_user():
def set_user_lock():
print("Execute api unlock user")
email = request.args.get('email', False)
out_json = unlockUser(email)
lockValue = request.args.get('locked', False)
out_json = setUserLock(email, lockValue)
return sendJSON(out_json)

# Web route to unlock all users API tokens
Expand Down
12 changes: 3 additions & 9 deletions LDlink/RegisterAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def unblockUser(email):
return out_json

# sets locked attribute of user to 0=false
def unlockUser(email):
def setUserLock(email, lockValue):
with open('config.yml', 'r') as f:
config = yaml.load(f)
env = config['env']
Expand All @@ -248,7 +248,7 @@ def unlockUser(email):
mongo_port = config['database']['mongo_port']

out_json = {
"message": "Email user (" + email + ")'s token access has been unlocked."
"message": "Email user (" + email + ")'s token access lock has been set to " + lockValue
}
if env == 'local':
mongo_host = api_mongo_addr
Expand All @@ -257,14 +257,8 @@ def unlockUser(email):
client = MongoClient('mongodb://' + mongo_username + ':' + mongo_password + '@' + mongo_host + '/LDLink', mongo_port)
db = client["LDLink"]
users = db.api_users
record = users.find_one({"email": email})
users.find_one_and_update({"email": email}, { "$set": {"locked": lockValue}})

if record["locked"] == -1:
out_json = {
"message": "Email user (" + email + ") has concurrent access."
}
else:
users.find_one_and_update({"email": email}, { "$set": {"locked": 0}})
return out_json

# sets locked attribute of all users to 0=false
Expand Down

0 comments on commit 730310f

Please sign in to comment.