Example #1
0
def removeInsertUserFromContactList(user_id, contact_id):
    if request.method == 'DELETE':
        return UserHandler().removeUserFromContacts(user_id, contact_id)
    elif request.method == 'POST':
        return UserHandler().insertUserToContacts(user_id, contact_id)
    else:
        return jsonify(Error="Method not allowed."), 405
Example #2
0
class Contacts(Resource):
    def __init__(self):
        self.handler = UserHandler()

    @jwt_required
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('first_name', help=HELP_TEXT, required=True)
        parser.add_argument('last_name', help=HELP_TEXT, required=True)
        parser.add_argument('email', help=HELP_TEXT)
        parser.add_argument('phone_number', help=HELP_TEXT)
        data = parser.parse_args()
        return self.handler.insert_contact(data)

    # @jwt_required
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument('contact_id', help=HELP_TEXT, required=True)
        data = parser.parse_args()
        contact = self.handler.update_contact(1)
        return jsonify(contact=contact)

    @jwt_required
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument('contact_id', help=HELP_TEXT, required=True)
        data = parser.parse_args()
        return self.handler.remove_contact(data)
Example #3
0
def manage_users():
    if request.method == 'GET':
        if not request.data:
            return UserHandler().getAllUsers()
        else:
            row = request.get_json()
            return UserHandler().getUserByUsername(row['username'])
Example #4
0
def getAllUsers():
    if request.method == 'POST':
        print("REQUEST: ", request.json)
        return UserHandler().createUser(request.json)
    else:
        if not request.args:
            return UserHandler().getAllUsers()
Example #5
0
def getMyContacts(pid):
    if request.method == 'GET':
        if not request.args:
            return UserHandler().getUserContacts(pid)
        else:
            return UserHandler().searchContacts(pid, request.args)
    elif request.method == 'POST':
        return ContactHandler().insertContact(pid, request.json)
Example #6
0
def getUserContactList(user_id):
    if request.method == 'GET':
        return UserHandler().getUserContactList(user_id)
    elif request.method == 'PUT':
        return UserHandler().updateUser(user_id, request.json)
    elif request.method == 'DELETE':
        return UserHandler().removeUserFromContacts(user_id)
    else:
        return jsonify(Error="Method not allowed."), 405
Example #7
0
def getUserById(user_id):
    if request.method == 'GET':
        return UserHandler().getUserById(user_id)
    elif request.method == 'PUT':
        return UserHandler().updateUser(user_id, request.json)
    elif request.method == 'DELETE':
        return UserHandler().deleteUser(user_id)
    else:
        return jsonify(Error="Method not allowed."), 405
Example #8
0
class User(Resource):
    def __init__(self):
        self.handler = UserHandler()

    def get(self, user):
        if user.isdigit():
            _user = self.handler.get_user_by_id(user)
        else:
            _user = self.handler.get_user_by_username(user)
        return jsonify(user=user)
Example #9
0
def num_of_mess_per_day(uid):
    """
    Gets numbers of posted messages by user per day
    :param uid: int
    :return: JSON
    """
    return UserHandler().get_num_messages_user(uid)
Example #10
0
def removeInsertUserFromToChat(chat_id, user_id):
    if request.method == 'POST':
        return ChatHandler().insertUserToChat(chat_id, user_id)
    elif request.method == 'DELETE':
        return UserHandler().removeUserFromChat(user_id, chat_id)
    else:
        return jsonify(Error="Method not allowed."), 405
Example #11
0
class Contact(Resource):
    def __init__(self):
        self.handler = UserHandler()

    def get(self, uid):
        contacts = self.handler.get_contacts(uid)
        return jsonify(contacts=contacts)
Example #12
0
class UserRegistration(Resource):
    def __init__(self):
        self.handler = UserHandler()

    def post(self):
        """
        Registers user to application.
        :return: JSON
        """

        # Arguments to be extracted from request
        parser = reqparse.RequestParser()
        parser.add_argument('username', help=HELP_TEXT, required=True)
        parser.add_argument('email', help=HELP_TEXT, required=True)
        parser.add_argument('password', help=HELP_TEXT, required=True)
        parser.add_argument('first_name', help=HELP_TEXT, required=True)
        parser.add_argument('last_name', help=HELP_TEXT, required=True)
        parser.add_argument('phone_number', help=HELP_TEXT, required=True)

        # Verifies required arguments are in request and extracts data into a dictionary
        data = parser.parse_args()
        response, status = self.handler.insert_user(data)
        return app.response_class(response=response,
                                  status=status,
                                  mimetype='application/json')
Example #13
0
class Users(Resource):
    def __init__(self):
        self.handler = UserHandler()

    # @jwt_required
    def get(self):
        users = self.handler.get_users()
        return jsonify(users=users)

    # @jwt_required
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument('new_username')
        data = parser.parse_args()
        if 'new_username' in data and data['new_username']:
            user = self.handler.update_user_username(username='******',
                                                     new_username='******')
            return jsonify(user=user)
        else:
            return jsonify(msg='Bad request')
Example #14
0
 def getChatUsers(self, chat_id):
     dao = ChatsDAO()
     chat = dao.getChatById(chat_id)
     user_list = dao.getChatUsers(chat_id)
     if not user_list:
         return jsonify(Chat=user_list), 404
     elif not chat:
         return jsonify(Error="Chat not found"), 404
     else:
         result_list = []
         for row in user_list:
             user = UserHandler.build_user_dict(UserHandler, row)
             result_list.append(user)
         return jsonify(Chat=result_list)
Example #15
0
    def post(self):
        """
        Logs in existing user
        :return: JSON
        """
        parser = reqparse.RequestParser()
        parser.add_argument('username', help=HELP_TEXT, required=True)
        parser.add_argument('password', help=HELP_TEXT, required=True)

        # Extracts data from request and verifies required data is available
        data = parser.parse_args()

        response, status = UserHandler().verify_password(data)
        return app.response_class(response=response,
                                  status=status,
                                  mimetype='application/json')
Example #16
0
def active_users():
    """
    Gets daily active users from database
    :return: JSON
    """
    return UserHandler().get_daily_active_users(), 200
Example #17
0
def get_most_active():
    if request.method == 'GET':
        return UserHandler().get_most_active_users_per_day()
    else:
        return jsonify(Error="Method not allowed"), 405
Example #18
0
def manage_user_username(username):
    if request.method == 'GET':
        return UserHandler().getUserByUsername(username)
    return jsonify(Error="Method Not Allowed")
Example #19
0
def manage_user(uid):
    if request.method == 'GET':
        return UserHandler().getUsersById(uid)
    elif request.method == 'PUT':
        return UserHandler().updateUser(request.json)
    return jsonify(Error="Method Not Allowed")
Example #20
0
def register():
    if request.method == 'POST':
        return UserHandler().insertUser(request.json)
    else:
        return "Register"
Example #21
0
def manage_account():
    if request.method == 'POST':
        print('Created New User: ', jsonify(request.json))
        return UserHandler().createUser(request.json)
Example #22
0
def status():
    global isLoggedIn
    if isLoggedIn:
        return UserHandler().getUsersById(loggedUID)
    else:
        return jsonify("Logged in")
Example #23
0
 def __init__(self):
     self.handler = UserHandler()
Example #24
0
def login():
    if request.method == 'POST':
        return UserHandler().UserLogin(request.json)
    else:
        return "Login"
Example #25
0
def users():
    if request.method == 'GET':
        if not request.args:
            return UserHandler().getAllUsers()
        else:
            return UserHandler().searchUser(request.args)
Example #26
0
def getUserById(pid):
    if request.method == 'GET':
        return UserHandler().getUserById(pid)
Example #27
0
def getUserGroups(pid):
    if request.method == 'GET':
        return UserHandler().getUserGroups(pid)
    elif request.method == 'POST':
        return GroupHandler().createGroup(pid, request.json)
Example #28
0
def getUsersThatReactToPostX(post_id, react_type):
    if request.method == 'GET':
        return UserHandler().getUsersThatReact(post_id, react_type)
    else:
        return jsonify(Error="Method not allowed."), 405
Example #29
0
def login():
    if request.method == 'POST':
        return UserHandler().login(request.json)
    else:
        return jsonify(Error="Method not allowed."), 405
Example #30
0
def insertPhoneNumber():
    if request.method == 'POST':
        return UserHandler().insertPhone(request.json)