示例#1
0
def user_upload_profile_url():
    if request.method == 'GET':
        user_ID = request.args.get('user_ID')
        status = status_response()
        url = dataAccess.user_upload_profile_photo(user_ID)
        status.attach_data('profile_upload_url', url)
    return status.get_response()
示例#2
0
def user_sign_up():
    status = status_response()
    if request.method == 'POST':
        firstName = request.form.get('firstName')
        lastName = request.form.get('lastName')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        if firstName and lastName and email and username and password:
            try:
                dataAccess.lookup_email(email)
                status.set_errorMessage('email already exist')
                return status.get_response()
            except:
                try:
                    dataAccess.lookup_username(username)
                    status.set_errorMessage('username already exist')
                    return status.get_response()
                except:
                    user_ID = dataAccess.user_sign_up(email, password,
                                                      firstName, lastName,
                                                      username)
                    status.attach_data('user_ID', response, isSuccess=True)
                    url = dataAccess.user_upload_profile_photo(user_ID)
                    status.attach_data('profile_upload_url', url)
    return status.get_response()
示例#3
0
def user_get_data():
    status = status_response()
    if request.method == 'GET':
        label = request.args.get('label')
        data = dataAccess.user_search(label)
        status.attach_data('data', data, isSuccess=True)
    return status.get_response()
示例#4
0
def delete_follow():
    status = status_response()
    if request.method == 'DELETE':
        from_user = request.form.get('from_user')
        to_user = request.form.get('to_user')
        response = dataAccess.delete_follow(from_user, to_user)
        if response:
            status.set_status(True)
        else:
            status.set_errorMessage('user not existed')
    return status.get_response()
示例#5
0
def user_get_data():
    status = status_response()
    if request.method == 'GET':
        user_ID = request.args.get('user_ID')
        dataType = request.args.get('dataType')
        try:
            if dataType:
                response = dataAccess.user_get(user_ID, dataType=dataType)
            else:
                response = dataAccess.user_get_basic(user_ID)
            status.attach_data('data', response, isSuccess=True)
        except:
            status.set_errorMessage('user_ID not exist')
    return status.get_response()
示例#6
0
def user_authenticate():
    status = status_response()
    if request.method == 'GET':
        user_ID = request.args.get('user_ID')
        email = request.args.get('email')
        username = request.args.get('username')
        password = request.args.get('password')
        try:
            response = dataAccess.user_authenticate(user_ID=user_ID,
                                                    email=email,
                                                    username=username,
                                                    password=password)
            status.attach_data('data', response, isSuccess=True)
        except:
            status.set_errorMessage('email or username not exist')
    return status.get_response()
示例#7
0
def add_follow():
    status = status_response()
    if request.method == 'POST':
        from_user = request.form.get('from_user')
        to_user = request.form.get('to_user')
        # add follow to database
        response = dataAccess.add_follow(from_user, to_user)
        if response:
            # get a list of moment dicts needed to be propagated
            momentDictList = dataAccess.get_moments(to_user)
            if momentDictList:
                response = notifyMap.followPropagate(momentDictList, from_user)
                if response:
                    status.set_status(True)
                else:
                    status.set_errorMessage('failed to notify map')
            else:
                status.set_status(True)
                status.set_errorMessage('this user has no moments')
    return status.get_response()
示例#8
0
def momentPost():
    status = status_response()
    if request.method == 'POST':
        moment_ID = request.form.get('moment_ID')
        attraction_ID = request.form.get('attraction_ID')
        user_ID = request.form.get('user_ID')
        # add moment to database
        response = dataAccess.add_post(moment_ID, attraction_ID, user_ID)
        if response:
            # get all subscribers of this user
            friendList = dataAccess.get_followers(user_ID)
            if friendList:
                # notify the map to propagate the change
                response = notifyMap.momentPropagate(moment_ID, attraction_ID,
                                                     friendList)
                if response:
                    status.set_status(True)
                else:
                    status.set_errorMessage('fail to notify map')
            else:
                status.set_status(True)
                status.set_errorMessage('no friends')
    return status.get_response()