예제 #1
0
def update_user_info():
	requested_user = g.user

	if "email" in request.form:
		requested_user.email = request.form["email"]
	if "phone" in request.form:
		phone = request.form["phone"]
		phone = user_service.convert_text_to_num(phone)
		requested_user.phone = phone
	if "first_name" in request.form:
		requested_user.first_name = request.form["first_name"]
	if "last_name" in request.form:
		requested_user.last_name = request.form["last_name"]
	if "nick_name" in request.form:
		requested_user.nick_name = request.form["nick_name"]
	if "show_last_name" in request.form:
		requested_user.preferences.show_last_name = request.form["show_last_name"] == "true"
	if "name_search" in request.form:
		requested_user.preferences.name_search = request.form["name_search"] == "true"
	if "browser_geo" in request.form:
		requested_user.preferences.browser_geo = request.form["browser_geo"] == "true"

	updated_user = user_service.update_user(requested_user)

	return { "success" :  True, "user" : updated_user.to_json_dict(private=True) }
예제 #2
0
def delete_profile_photo():
	current_user = g.user

	if current_user.portrait != None:
		old_hash = filesystem_storage_service.get_cropped_hash(current_user.portrait, current_user.user_id)
		try:
			filesystem_storage_service.delete_cropped(old_hash)
		except OSError:
			pass

	current_user.portrait = None
	updated_user = user_service.update_user(current_user)

	updated_user_json_dict = updated_user.to_json_dict(private=True)

	return { "success" : True, "user" : updated_user_json_dict }
예제 #3
0
def upload_profile_photo():
	current_user = g.user
	current_location = g.user_location

	picture_id_str = request.form.get("profile-picture-id", None)
	crop_x_str = request.form["crop-x"]
	crop_y_str = request.form["crop-y"]
	crop_width_str = request.form["width"]
	crop_height_str = request.form["height"]
	privacy = request.form["privacy"]
	uploaded_photo = request.files.get("image", None)

	if picture_id_str == None and uploaded_photo == None:
		return { "success" : False }
	try:
		if picture_id_str != None:
			picture_id = int(picture_id_str)
		else:
			picture_id = None

		crop_x = int(crop_x_str)
		crop_y = int(crop_y_str)
		crop_width = int(crop_width_str)
		crop_height = int(crop_height_str)
	except ValueError as e:
		return { "success" : False }

	if picture_id == None:
		secured_name = secure_filename(uploaded_photo.filename)

		full_picture = UploadedPicture(current_user.user_id, datetime.now(), secured_name, current_location, None, None, privacy)
		picture_meta_service.create_picture(full_picture)
		picture_id = full_picture.picture_id

		# Temporary local filesystem storage
		hashed_filename = filesystem_storage_service.get_image_hash(full_picture.picture_id, full_picture.author_id)
		try:
			filesystem_storage_service.save_image(uploaded_photo, hashed_filename)
		except ServiceException as se:
			picture_meta_service.delete_picture_by_id(full_picture.picture_id)
			return { "error" : True, "message" : "Error saving new image" }, 500
	else:
		full_picture = picture_meta_service.get_picture_by_id(picture_id, current_user.user_id)
		hashed_filename = filesystem_storage_service.get_image_hash(full_picture.picture_id, full_picture.author_id)
		uploaded_photo = filesystem_storage_service.get_image(hashed_filename)


	profile_picture = ProfilePicture(picture_id, datetime.now())
	picture_meta_service.create_profile_picture(profile_picture)

	# Attempt to delete previous portrait
	if current_user.portrait != None:
		old_hash = filesystem_storage_service.get_cropped_hash(current_user.portrait, current_user.user_id)
		try:
			filesystem_storage_service.delete_cropped(old_hash)
		except OSError:
			pass


	# Temporary local filesystem storae
	hashed_cropped_filename = filesystem_storage_service.get_cropped_hash(profile_picture.profile_picture_id, current_user.user_id)

	try:
		crop = PictureSection(crop_x, crop_y, crop_width, crop_height)
		filesystem_storage_service.save_cropped_image(uploaded_photo, hashed_cropped_filename, crop)
	except ServiceException as se:
		print se
		return { "error" : True, "message" : "Error saving cropped image" }, 500

	current_user.portrait = profile_picture.profile_picture_id
	updated_user = user_service.update_user(current_user)

	updated_user_json_dict = updated_user.to_json_dict(private=True)

	return { "error" : False, "user" : updated_user_json_dict }