예제 #1
0
def getUserMessagesByEmail(email, profileEmail):
    """Returns the messages for a user's wall."""
    data = ['email=' + email] 
    if profileEmail is None:
        profileEmail = email
    data.append('&profileEmail=' + profileEmail) 
    clientHash = request.headers.get('Hash-Hmac') 
    utcTimestamp = request.headers.get('Hash-Timestamp')
    if validHMACHash(clientHash, data, email, utcTimestamp):
        if emailExists(email):
            messages = database_helper.getUserMessagesByEmail(profileEmail)
            messagesList = []
            for message in messages:
                messageDict = {'messageId': message[0], 'message': message[1], 'datePosted': message[2], 'wallEmail': message[3], 'writer': message[4]}
                fileName = database_helper.getFileNameByMessageId(message[0])
                if fileName is not None:
                    messageDict.update({'fileName': fileName})
                    fileExtension = getFileExtension(fileName)
                    fileType = getFileType(fileExtension)
                    messageDict.update({'fileType': fileType})
                messagesList.append(messageDict)                
            return json.dumps({'success': True, 'message': 'User messages retreived.', 'data': messagesList}), 200
        else:
            return json.dumps({'success': False, 'message': 'No such user.'}), 404
    else:
        return json.dumps({'success': False, 'message': 'Invalid hash.'}), 405
예제 #2
0
파일: server.py 프로젝트: joihn/TDDD97_Lab2
def getUserMessagesByEmail(token, email):
    if email is None:
        email = database_helper.getUserEmailByToken(token)

    signedInEmail = database_helper.getUserEmailByToken(token)
    if signedInEmail is not None:
        if emailExists(email):
            messages = database_helper.getUserMessagesByEmail(email)
            messagesList = []
            for message in messages:
                messagesList.append({'messageId': message[0], 'message': message[1], 'datePosted': message[2], 'wallEmail': message[3], 'writer': message[4]})
            return json.dumps({'success': True, 'message': 'User messages retreived.', 'data': messagesList}), 200
        else:
            return json.dumps({'success': False, 'message': 'No such user.'}), 404
    else:
        return json.dumps({'success': False, 'message': 'You are not signed in.'}), 405