Example #1
0
def see_users():
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    dict_user = edit_user.read_u(cursor, 0, 0, 0)
    array_user = []

    for userid, user in dict_user.items():
        username = user.u_name
        firstName = user.f_name
        lastName = user.l_name
        myid = user.user_id
        bday = user.bday
        occupation = user.occupation
        about = user.about
        email = user.email

        ind_user = {
            'username': username,
            'firstName': firstName,
            'lastName': lastName,
            'id': myid,
            'bday': bday,
            'occupation': occupation,
            'about': about,
            'email': email
        }

        array_user.append(ind_user)

    start_db.commitclose(cursor, db)

    return jsonify({'person': array_user})
Example #2
0
def add_friend():
    content = request.json
    print "content"
    print content
    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    checkbit = edit_friendships.add_f(
        cursor, content['user_id_a'],
        content['user_id_b'])  #just in case, "supposed" to be user_id

    start_db.commitclose(cursor, db)

    #need to pull relevant info out of content, if necessary

    if checkbit == 0:
        return jsonify({
            'user_a': content['user_id_a'],
            'user_b': content['user_id_b'],
            'success': 'false'
        })
    else:
        return jsonify({
            'user_a': content['user_id_a'],
            'user_b': content['user_id_b'],
            'success': 'true'
        })
Example #3
0
def create_user():
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    username = content['username']
    desc = content['desc']
    email = content['email']
    bday = content['bday']

    user_id = cursor.lastrowid
    start_time = datetime.datetime.now()
    test = edit_user.user(0, 0, 0, username, 0, 0, desc, 0, bday, email,
                          start_time, 1)
    check = edit_user.update_u(cursor, username, test)

    start_db.commitclose(cursor, db)

    if check == 1:
        return jsonify({
            'username': content['username'],
            'desc': content['desc'],
            'email': content['email'],
            'bday': content['bday'],
            'success': 'true'
        })
    else:
        return '', status.HTTP_404_NOT_FOUND
Example #4
0
def makepost():
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)
    '''
    #usera = edit_user.read_u(cursor, username_a) #might be (cursor, 0, 0, username_a)
    #userb = edit_user.read_u(cursor, username_b)
    '''
    #Supposedly want user_id, not user

    post_id = cursor.lastrowid
    timestamp = datetime.datetime.now()
    user_id_a = content['user_id_a']
    user_id_b = content['user_id_b']
    writeup = content['content']
    newpost = edit_posts.post(post_id, user_id_a, user_id_b, timestamp,
                              writeup)
    check = edit_posts.create_p(cursor, newpost)
    start_db.commitclose(cursor, db)

    if check == 1:
        return jsonify({'stuff': content})
        #return correct jsonify
    else:
        return '', status.HTTP_404_NOT_FOUND
Example #5
0
def confirm_friend():
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    #may need to change status from string to int
    checkbit = edit_friendships.confirm_f(cursor, content['user_id_a'],
                                          content['user_id_b'],
                                          content['status'])

    start_db.commitclose(cursor, db)
    print "checkbit"
    print checkbit
    #Again, need to pull out all relevant info from content

    if checkbit > 0:
        if checkbit == 2:
            return jsonify({
                'user_a': content['user_id_a'],
                'user_b': content['user_id_b'],
                'result': 'denied'
            })  #return for deny, success
        else:
            return jsonify({
                'user_a': content['user_id_a'],
                'user_b': content['user_id_b'],
                'result': 'accepted'
            })  #return for accept, success
    else:
        if checkbit == -2:
            return '', status.HTTP_404_NOT_FOUND
        else:
            return '', status.HTTP_404_NOT_FOUND
Example #6
0
def wait_confirm(username):

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    f_dict = edit_friendships.allpotential_f(cursor, username, 2)
    array_f = []

    for friend in f_dict:
        username = friend.u_name
        firstName = friend.f_name
        lastName = friend.l_name
        myid = friend.user_id
        bday = friend.bday
        occupation = friend.occupation
        about = friend.about
        email = friend.email

        ind_f = {
            'username': username,
            'firstName': firstName,
            'lastName': lastName,
            'id': myid,
            'bday': bday,
            'occupation': occupation,
            'about': about,
            'email': email
        }

        array_f.append(ind_f)
    print array_f
    start_db.commitclose(cursor, db)

    return jsonify({'person': array_f})
Example #7
0
def register_user():
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    firstname = content['firstName']
    lastname = content['lastName']
    username = content['username']
    password = content['password']

    user_id = cursor.lastrowid
    start_time = datetime.datetime.now()
    test = edit_user.user(user_id, firstname, lastname, username,
                          hash(password), '', 'N/A', '', 'N/A', 'N/A',
                          start_time, 1)
    check = edit_user.insert_u(cursor, test)

    start_db.commitclose(cursor, db)

    if check == 1:
        return jsonify({
            'firstName': content['firstName'],
            'lastName': content['lastName'],
            'username': content['username'],
            'password': content['password'],
            'success': 'true'
        })
    else:
        return '', status.HTTP_404_NOT_FOUND
Example #8
0
def delete_user(identity):
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    edit_user.delete_u(cursor, identity)

    start_db.commitclose(cursor, db)

    return jsonify({'id': identity, 'success': 'true'})
Example #9
0
    def __init__(self, post_id, username_a, username_b, timestamp, content):
        self.post_id = post_id
        self.username_a = username_a  #user a is the one posting, user b is the one whose profile user_a is posting on
        self.username_b = username_b
        self.timestamp = timestamp
        self.content = content  #content can be words or it can also be a relative path to media content

        db = start_db.launchdb()
        cursor = start_db.launchcursor(db)

        self.user_a = edit_user.find_u(cursor, username_a)
        self.user_b = edit_user.find_u(cursor, username_b)

        start_db.commitclose(cursor, db)
Example #10
0
def delete_friend():
    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    edit_friendships.delete_f(
        cursor, username_a, username_b
    )  #if either this or confirm friend breaks, check if delete_f in edit_friendships has been switched to usernames

    start_db.commitclose(cursor, db)

    return jsonify({
        'username_a': username_a,
        'username_b': username_b,
        'success': 'true'
    })
Example #11
0
def check_requests(requestexists):
    json_acceptable_string = requestexists.replace("'", "\"")
    requestexists = json.loads(json_acceptable_string)

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    f_dict = edit_friendships.request_exists_f(cursor,
                                               requestexists['user_id_a'],
                                               requestexists['user_id_b'])
    print f_dict
    start_db.commitclose(cursor, db)

    if f_dict == 1:
        return jsonify({'exists': 'requestgood'})
    else:
        return jsonify({'exists': 'requestbad'})
Example #12
0
def getpost(useridb):
    json_acceptable_string = useridb.replace("'", "\"")
    useridb = json.loads(json_acceptable_string)
    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    post_dict = edit_posts.show_p(cursor, useridb['user_id_a'],
                                  useridb['user_id_b'])
    #Need to decide what to do with post_dict after grabbing it
    friendzone = edit_friendships.is_f(cursor, useridb['user_id_a'],
                                       useridb['user_id_b'])
    start_db.commitclose(cursor, db)
    if (post_dict != 0):
        if (len(post_dict) != 0):
            return jsonify({'posts': post_dict})
        else:
            return jsonify({'posts': 1})
    elif (friendzone == 1):
        return jsonify({'posts': 1})
    else:
        return jsonify({'posts': 0})
Example #13
0
def Authenticate():

    content = request.json

    db = start_db.launchdb()
    cursor = start_db.launchcursor(db)

    username = content['username']
    password = content['password']

    check = edit_user.confirm_u(cursor, username, hash(password))

    start_db.commitclose(cursor, db)

    if check == 1:
        return jsonify({
            'username': content['username'],
            'password': content['password'],
            'success': 'true'
        })
    else:
        return '', status.HTTP_404_NOT_FOUND