Exemple #1
0
def postMessage(token, email):
    signedInEmail = database_helper.getUserEmailByToken(token)
    if signedInEmail is not None:
        if emailExists(email):
            if len(request.form['message']) > 0:
                database_helper.insertMessage(signedInEmail, email, request.form['message'])
                return json.dumps({'success': True, 'message': 'Message posted.'}), 200
            else:
                return json.dumps({'success': False, 'message': 'Form data missing or incorrect type.'}), 400
        else:
            return json.dumps({'success': False, 'message': 'No such user.'}), 404
    else:
        return json.dumps({'success': False, 'message': 'You are not signed in.'}), 405
Exemple #2
0
def post_message():  #token, message, email
    req = request.get_json()
    token = request.headers.get('Authorization')[7:]

    status = database_helper.insertMessage(token, req['message'], req['email'])

    if status == 1:
        return jsonify({
            "success": "true",
            "mgunicorn server:appessage": "Message posted."
        })
    elif status == 0:
        return jsonify({"success": "false", "message": "No such user."})
    else:
        return jsonify({
            "success": "false",
            "message": "You are not signed in."
        })
Exemple #3
0
def postMessage(email):
    """Posts a message (and file if supplied) to a user's wall."""
    # Remove new lines in the message, otherwise the hash won't work.
    data = ['email=' + email, '&message=' + request.form['message'].replace("\r\n", ""), '&wallEmail=' + request.form['wallEmail']] 
    if len(request.files) > 0:
        data.append('&file=' + request.files['file'].filename);
    clientHash = request.headers.get('Hash-Hmac')
    utcTimestamp = request.headers.get('Hash-Timestamp')
    if validHMACHash(clientHash, data, email, utcTimestamp):
        if emailExists(request.form['wallEmail']):
            if len(request.form['message']) > 0:
                messageId = database_helper.insertMessage(email, request.form['wallEmail'], request.form['message'])
                if len(request.files) > 0:
                    uploadFile(request.files['file'], messageId)
                sendUserPostData(email)
                sendUserPostTotalData(email)
                sendUserViewData(email)
                return json.dumps({'success': True, 'message': 'Message posted.'}), 200
            else:
                return json.dumps({'success': False, 'message': 'Form data missing or incorrect type.'}), 400
        else:
            return json.dumps({'success': False, 'message': 'No such user.'}), 404
    else:
        return json.dumps({'success': False, 'message': 'Invalid hash.'}), 405