def getToken(username): user = User.query.filter_by(username = username).first() if user is None: return return_response(404, "User not found", {}) token= user.generate_token_key() response = return_response(200, "ok", {"token":token}) return response
def getUsersOrById(username=None): if username is None: users = User.query.all() result = [user.username for user in users] else: user = User.query.filter_by(username=username).first() if user is None: return return_response(404, "No user found with this username", {}) else: result = [{user}] return return_response(200, "OK", result)
def login(): print request.json username = request.json.get("username") password = request.json.get("password") user = User.query.filter_by(username = username).first() if user is None or not check_password_hash(user.password, password): return return_response(400, "Wrong input") #return jsonify({'error':'wronginput'}), 400 # Return token key to user return return_response(200, "OK", {'token':user.generate_token_key()})
def addFriend(): username = request.json.get("username") friend = User.query.filter_by(username=username).first() newFriend = Friends(g.user.id, friend.id) db.session.add(newFriend) db.session.commit() return return_response(201, "OK")
def new_user(): username = request.json.get('username') email = request.json.get('email') password = request.json.get('password') print username,email,password if username is "" or email is "" or password is "": return return_response(400, "Missing properties") if username is None or email is None or password is None: return return_response(400, "Missing properties") alreadyRegisterd = User.query.filter_by(username = username).first() if alreadyRegisterd is not None: return return_response(400, "User exist") newUser = User(username, email, password) db.session.add(newUser) db.session.commit() # Return that the user was created but he return return_response(201, "OK", {'result':'User created'})
def getMyFriends(): return return_response(200, "OK")
def getAllUsers(): users = User.query.all() allUsers = [u.username for u in users] print allUsers return return_response(200, "OK", allUsers)