コード例 #1
0
ファイル: UsersHandler.py プロジェクト: Y-E-R-A/Whitestone
    def insertUserJSON(self, json):
        """
        Handle the insertion of a new user
        :param json: credential id, user first name, user last name, user description
        user role, user classification(Elect Senator, Ex-Officio....)
        :return: json with the new user inserted information
        """

        cid = json.get('cID')
        ufirstname = json.get('ufirstname')
        ulastname = json.get('ulastname')
        udescription = json.get('udescription')
        urole = json.get('urole')
        uclassification = json.get('uclassification')

        if UsersDAO().getUserBycID(cid):

            return jsonify(Error="The credential ID belong to other user"), 400
        else:

            if cid and ufirstname and ulastname and urole and uclassification:

                uid = UsersDAO().insert(cid, ufirstname, ulastname,
                                        udescription, urole, uclassification)
                mapped_result = self.buildUserDict(uid, cid, ufirstname,
                                                   ulastname, udescription,
                                                   urole, uclassification)
                return jsonify(User=mapped_result), 201

            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
コード例 #2
0
ファイル: UsersHandler.py プロジェクト: Y-E-R-A/Whitestone
    def getUser(self, json):
        """
        Handle the search of user information according to the login type
        :param json: login type(LOCAL or RADIUS), email, pin
        :return: if exists, returns the user information corresponding to the uid
        """

        login = json.get("login")
        email = json.get('email')
        pin = json.get("pin")

        if login == "LOCAL":
            result = UsersDAO().getUser(email, pin)
            if not result:
                return jsonify(Error="NOT FOUND"), 404

            else:

                mapped_result = self.mapToUserInfoDict(result)
                return jsonify(User=mapped_result), 200

        else:
            result = UsersDAO().getUserbyEmail(email)
            if not result:
                return jsonify(Error="NOT FOUND"), 404

            else:

                mapped_result = self.mapToUserInfoDict(result)
                return jsonify(User=mapped_result), 200
コード例 #3
0
    def getUser(self, json):
        # Handle the search of user information according to the login type
        login = json.get("login")
        email = json.get('email')
        pin = json.get("pin")

        if login == "LOCAL":
            result = UsersDAO().getUser(email, pin)
            if not result:
                return jsonify(Error="NOT FOUND"), 404

            else:

                mapped_result = self.mapToUserInfoDict(result)
                return jsonify(User=mapped_result), 200

        else:
            result = UsersDAO().getUserbyEmail(email)
            if not result:
                return jsonify(Error="NOT FOUND"), 404

            else:

                mapped_result = self.mapToUserInfoDict(result)
                return jsonify(User=mapped_result), 200
コード例 #4
0
ファイル: UsersHandler.py プロジェクト: Y-E-R-A/Whitestone
    def updateUser(self, uID, form):
        """
        Handle the update of user information with certain uID
        :param uID: user id
        :param form: ufirstname, ulastname, udescription, urole, uclassification
        :return: json with the user updated information
        """
        if not UsersDAO().getUserByuID(uID):
            return jsonify(Error="User not found"), 404
        else:

            if len(form) != 5:
                return jsonify(Error="Malformed update request"), 400
            else:

                ufirstname = form['ufirstname']
                ulastname = form['ulastname']
                udescription = form['udescription']
                urole = form['urole']
                uclassification = form['uclassification']

                if ufirstname and ulastname and urole and uclassification:
                    UsersDAO().updateUser(uID, ufirstname, ulastname,
                                          udescription, urole, uclassification)
                    result = self.editUserDict(uID, ufirstname, ulastname,
                                               udescription, urole,
                                               uclassification)
                    return jsonify(User=result), 200
                else:
                    return jsonify(
                        Error="Unexpected attributes in update request"), 400
コード例 #5
0
    def deleteUser(self, uID):
        # Handle the cascade deletion of a user, its credentials, and vote in relations
        if not UsersDAO().getUserByuID(uID):
            return jsonify(Error="User not found"), 404

        else:

            UsersDAO().deleteUser(uID)
            return jsonify(Action="User deleted"), 200
コード例 #6
0
    def updateCredential(self, form):
        # Handle the email and pin updates for user with certain cID
        user = UsersDAO().getUserbyEmail(form['email'])

        if (user and
            (user[7] == form['email'] and user[1] == form['cID'])) or not user:
            if len(form) != 3:

                return jsonify(Error="Malformed update request"), 400

            else:

                cID = form['cID']
                email = form['email']
                pin = form['pin']

                if cID and email and pin:
                    CredentialDAO().updateCredentials(email, pin, cID)
                    result = self.buildCredentialDict(cID, email, pin)
                    return jsonify(Credential=result), 200

                else:
                    return jsonify(
                        Error="Unexpected attributes in update request"), 400
        else:
            return jsonify(Error="Email is already registered."), 400
コード例 #7
0
    def updateCredential(self, form):
        """
        Handle the email and pin updates for user with certain cID
        :param form: information to be updated
        :return: json with the new credential information (updated)
        """

        user = UsersDAO().getUserbyEmail(form['email'])

        # Check if the email in the form already exist, and if exists if the email correspond to the same
        # user to be updated
        if (user and (user[7] == form['email'] and user[1] == form['cID'])) or not user:
            if len(form) != 3:

                return jsonify(Error="Malformed update request"), 400

            else:

                cID = form['cID']
                email = form['email']
                pin = form['pin']

                if cID and email and pin:
                    CredentialDAO().updateCredentials(email, pin, cID)
                    result = self.buildCredentialDict(cID, email, pin)
                    return jsonify(Credential=result), 200

                else:
                    return jsonify(Error="Unexpected attributes in update request"), 400
        else:
            return jsonify(Error="Email is already registered."), 400
コード例 #8
0
ファイル: VoteInHandler.py プロジェクト: Y-E-R-A/Whitestone
    def insertVoteInJSON(self, json):
        """
        Handle the insertion of a voting participant
        :param json: voting id, user id
        :return: vote in information json representation
        """

        uID = json.get('uID')
        vID = json.get('vID')

        if VoteInDAO().getParticipant(vID, uID):
            return jsonify(
                Error=
                "User was previously registered for this voting.  Nothing to do"
            ), 400

        elif not VotingQuestionDAO().getVotingQuestionByID(vID) or not (
                UsersDAO().getUserByuID(uID)):
            return jsonify(Error="NOT FOUND"), 404

        else:
            if uID and vID:

                VoteInDAO().insertVoteIn(uID, vID)
                mapped_result = self.buildVoteInDict(vID, uID, False)
                return jsonify(VoteIn=mapped_result), 201

            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 404
コード例 #9
0
class MyStreamListener(tweepy.StreamListener):
  
  def __init__(self):
    print("Streamer object created")
    self.usersDAO = UsersDAO()
    self.tweetsDAO = TweetsDAO()
  
  def on_status(self, status):
    self.usersDAO.updateCollection(status)
    self.tweetsDAO.updateCollection(status)
    sys.stdout.write("Users: %d\t" % (self.usersDAO.getNumOfDocs()))
    sys.stdout.write("Tweets: %d\t" % (self.tweetsDAO.getNumOfDocs()))
    sys.stdout.write("DB Size: %.2f MB\r" % (self.tweetsDAO.getSizeOfDB()))
    sys.stdout.flush()
    
  def setAPI(self, api):
    self.api = api    
コード例 #10
0
    def getUserByuID(self, uID):
        # Handle the search of user information with certain uID
        result = UsersDAO().getUserByuID(uID)
        if not result:
            return jsonify(Error="NOT FOUND"), 404

        else:

            mapped_result = self.mapToUserInfoDict(result)
            return jsonify(User=mapped_result), 200
コード例 #11
0
    def getAllUsersInfo(self):
        # Handle the search of all users information
        result = UsersDAO().getAllUsersInfo()
        mapped_result = []

        if not result:
            return jsonify(Error="NOT FOUND"), 404

        else:
            for r in result:
                mapped_result.append(self.mapToUserInfoDict(r))

            return jsonify(User=mapped_result), 200
コード例 #12
0
    def getAllElectSenator(self):
        # Handle the search of uID with the elect senator classification
        result = UsersDAO().getAllElectSenators()
        mapped_result = []

        if not result:
            return jsonify(Error="NOT FOUND"), 404

        else:
            for r in result:
                mapped_result.append(self.mapToUserIDDict(r))

            return jsonify(User=mapped_result),200
コード例 #13
0
    def getAllSenator(self):
        # Handle the search of all the uID of users with senator role
        result = UsersDAO().getAllSenators()
        mapped_result = []

        if not result:
            return jsonify(Error="NOT FOUND"), 404

        else:
            for r in result:
                mapped_result.append(self.mapToUserIDDict(r))

            return jsonify(User=mapped_result), 200
コード例 #14
0
    def insertUserJSON(self, json):
        # Handle the insertion of a new user

        cid = json.get('cID')
        ufirstname = json.get('ufirstname')
        ulastname = json.get('ulastname');
        udescription = json.get('udescription');
        urole = json.get('urole');
        uclassification = json.get('uclassification');

        if UsersDAO().getUserBycID(cid):

            return jsonify(Error="The credential ID belong to other user"), 400
        else:

            if cid and ufirstname and ulastname and urole and uclassification:

                uid = UsersDAO().insert(cid,ufirstname,ulastname,udescription,urole, uclassification)
                mapped_result = self.buildUserDict(uid,cid,ufirstname,ulastname,udescription,urole, uclassification)
                return jsonify(User = mapped_result), 201

            else:
                return jsonify(Error="Unexpected attributes in post request"), 400
コード例 #15
0
ファイル: UsersHandler.py プロジェクト: Y-E-R-A/Whitestone
    def getUserByuID(self, uID):
        """
        Handle the search of user information with certain uID
        :param uID: user id
        :return: if exists, returns the user information corresponding to the uid
        """

        result = UsersDAO().getUserByuID(uID)
        if not result:
            return jsonify(Error="NOT FOUND"), 404

        else:

            mapped_result = self.mapToUserInfoDict(result)
            return jsonify(User=mapped_result), 200
コード例 #16
0
ファイル: UsersHandler.py プロジェクト: Y-E-R-A/Whitestone
    def getAllExOfficioStudentsSenator(self):
        """
        Handle the search of uID with the ex-officio student senator classification
        :return: ex-officio student senator uid list as json
        """
        result = UsersDAO().getAllExOfficioStudentSenators()
        mapped_result = []

        if not result:
            return jsonify(Error="NOT FOUND"), 404

        else:
            for r in result:
                mapped_result.append(self.mapToUserIDDict(r))

            return jsonify(User=mapped_result), 200
コード例 #17
0
 def __init__(self):
   print("Streamer object created")
   self.usersDAO = UsersDAO()
   self.tweetsDAO = TweetsDAO()