def register_user(): data = json.loads(request.data) name = data.get('name', None) lastname = data.get('lastname', None) username = data.get('username', None) password = data.get('password', None) list = [name, lastname, username, password] for element in list: if (not element or element == ""): return jsonify({ "RESULT": "No ha brindado toda la informacion necesaria", "RETURNCODE": "-1", "METHOD": "POST" }) newUser = User(name, lastname, username, password, "client") result = UsersHandler.addUser(newUser) if result: return jsonify({ "RESULT": f"Usuario {username} Registrado con exito", "RETURNCODE": "0", "METHOD": "POST" }) else: return jsonify({ "RESULT": f"Ya existe un usario con username {username}", "RETURNCODE": "1", "METHOD": "POST" })
user = UsersHandler.getUserByUsername(username) if (user == None): return jsonify({ "RESULT": f"No existe ningun usuario con username {username}", "RETURNCODE": "1", "METHOD": "POST" }) else: return jsonify({ "RESULT": user.password, "RETURNCODE": "0", "METHOD": "POST" }) @app.route('/') def index(): return jsonify({ "MESSAGE": "BackEnd Python CUK", "RETURNCODE": "0", "METHOD": "POST" }) if __name__ == '__main__': # Threaded option to enable multiple instances for multiple user access support UsersHandler.addUser(User("Usuario", "Maestro", "admin", "admin", "admin")) app.run(threaded=True, port=5000)