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()
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()
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()
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()
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()
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()
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()
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()