Ejemplo n.º 1
0
def optin(user_ID=None):
	signup_method = request.args.get('signup_method')
	include_email = request.args.get('include_email')
	iframe = request.args.get('iframe')
	if not include_email:
		include_email = False
	elif include_email.lower() == "true":
		include_email = True
	else:
		include_email = False
	if not iframe:
		iframe = False
	elif iframe.lower() == "true":
		iframe = True
	else:
		iframe = False
	if not signup_method:
		signup_method = 3 # Default to website
	cur_user = current_user()
	if user_ID:
		# Regardless of who is logged in, send to page for provided user ID
		restaurant = UserAccount.get_by_id(int(user_ID))
	else:
		# No one is logged in, send to provided user or if none redirect to home
		if cur_user.is_authenticated():
			restaurant = cur_user
		else:
			return redirect(url_for("index")) 
	return render_response("optin.html",restaurant=restaurant,signup_method=signup_method,include_email=include_email,iframe=iframe)
Ejemplo n.º 2
0
def index():
	# Each user has an invitation link (in /network) which they send to other users to
	# invite them to connect on BookOut. Currently, this is the only method of connecting
	# users. The link adds an argument to the index link (?connect=) with the inviter's
	# user ID. A modal appears in the view if otherUserID is not 0.
	
	# Grab User ID from connection invitation
	otherUserID = request.args.get('connect')
	
	# If no connect argument is present (just a regular visit to the dashboard), set to 0 (ignored in view)
	if otherUserID is None:
		connectionType = 0 #No connection request is being made
		otherUserID = 0
		otherUserName = 0
	else:
		# Get User Name from User ID
		otherUserObj = UserAccount.get_by_id(int(otherUserID))
		# Set invalid objects to invalid
		if otherUserObj is None:
			otherUserID = 0
			otherUserName = 0
			connectionType = 1 #Invalid User ID
		else:
			otherUserName = otherUserObj.name
			connectionType = 2 #Valid User
	
		# Don't let a user connect with him/herself, set to 0 so they get nothing
		if int(otherUserID) == current_user().get_id():
			connectionType = 3 #Own self
			
		# Don't let a user connect with an existing connection
		# if int(otherUserID) matches something in current_user().connected_accounts
		#	connectionType = 4 #Existing Connection
			
	return render_response('home.html',connectUserID=otherUserID,connectUserName=otherUserName,connectType=connectionType)
Ejemplo n.º 3
0
def optin_guest(user_ID,signup_method):
	user = UserAccount.get_by_id(int(user_ID))
	# Opt in the guest (this will add them if they don't exist, and update and optin if they already do)
	guest = Guest.add_guest(firstName=request.form["firstName"], lastName=None, smsNumber=functions.digitizePhoneNumber(request.form["smsNumber"]), email=request.form["email"], preferredContact=request.form["preferredContact"], optIn=True, signup_method=int(signup_method), user=user)
	if guest:
		return "Success"
	else:
		return "Error"
Ejemplo n.º 4
0
def generate_gravatar(userID,size):
	try:
		int(userID)
		user = UserAccount.get_by_id(int(userID))
		import hashlib
		import urllib
		gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(user.email).hexdigest() + "?s=" + size + "&d=" + urllib.quote(request.host_url,'') + "static%2Fimg%2Fnoimage.png"
	except:
		return False
	return redirect(gravatar_url)
Ejemplo n.º 5
0
def get_borrowed_books():
	cur_user = current_user()
	borrowedBooks = []
	for bookcopy in cur_user.get_borrowed_books():
		book = Book.get_by_id(bookcopy.book.id())
		owner = UserAccount.get_by_id(bookcopy.owner.id())
		bookInfo = dict()
		bookInfo["title"] = book.title
		bookInfo["author"] = book.author
		bookInfo["copyID"] = bookcopy.key.id()
		bookInfo["ownerId"] = bookcopy.owner.id()
		bookInfo["owner"] = owner.name
		bookInfo["due_date"] = str(bookcopy.due_date)
		borrowedBooks.append(bookInfo)
	return jsonify({"borrowedBooks":borrowedBooks})
Ejemplo n.º 6
0
def get_borrowed_items():
	cur_user = current_user()
	borrowedItems = []
	for itemcopy in cur_user.get_borrowed_books():
		if not itemcopy.manual_borrower_name: #Don't include items the user is manually lending (they would come up because the borrower is set to the user)
			item = Item.get_by_id(itemcopy.item.id())
			owner = UserAccount.get_by_id(itemcopy.owner.id())
			itemInfo = dict()
			itemInfo["title"] = item.title
			itemInfo["author"] = item.author
			itemInfo["copyID"] = itemcopy.key.id()
			itemInfo["ownerId"] = itemcopy.owner.id()
			itemInfo["owner"] = owner.name
			itemInfo["due_date"] = str(itemcopy.due_date)
			borrowedItems.append(itemInfo)
	return jsonify({"borrowedItems":borrowedItems})
Ejemplo n.º 7
0
def profile(userID):
	profile_user = UserAccount.get_by_id(int(userID))
	user = current_user()
	if not profile_user:
		return render_response('invalidprofile.html')
	if user.is_connected(profile_user):
		library = []
		for copy in profile_user.get_library():
			book = Book.query(Book.key == copy.book).get()
			library.append(book)
			if copy.borrower is None:
				book.available = True
			else:
				book.available = False
			book.copyid = copy.key.id()
		return render_response('profile.html',profile_user=profile_user,library=library)
	return render_response('invalidprofile.html')
Ejemplo n.º 8
0
def get_lent_items():
	cur_user = current_user()
	lentItems = []
	for itemcopy in cur_user.get_lent_books():
		item = Item.get_by_id(itemcopy.item.id())
		borrower = UserAccount.get_by_id(itemcopy.borrower.id())
		itemInfo = dict()
		itemInfo["title"] = item.title
		itemInfo["author"] = item.author
		itemInfo["copyID"] = itemcopy.key.id()
		itemInfo["borrowerId"] = itemcopy.borrower.id()
		itemInfo["borrower"] = borrower.name
		itemInfo["due_date"] = str(itemcopy.due_date)
		if itemcopy.manual_borrower_name:
			itemInfo["manual_borrower_name"] = itemcopy.manual_borrower_name
			itemInfo["manual_borrower_email"] = itemcopy.manual_borrower_email
		lentItems.append(itemInfo)
	return jsonify({"lentItems":lentItems})
Ejemplo n.º 9
0
def get_user_email(userID):
	userEmail = UserAccount.get_by_id(int(userID)).email
	emailSplit = userEmail.split("@", 1)
	privacyEmail = userEmail[0:1] + '******@' + emailSplit[1]
	return jsonify({"email": privacyEmail})
Ejemplo n.º 10
0
def profile(userID):
	try:
		int(userID)
		profile_user = UserAccount.get_by_id(int(userID))
		# Check if profile user has a custom url and forward if so
		if profile_user.custom_url:
			try:
				long(profile_user.custom_url) # Custom URLs MUST include at least one letter, so this will always fail with a custom URL
			except:
				return redirect('/user/' + profile_user.custom_url)
			
	except:
		# Query custom URLs
		custom_url_user = UserAccount.query(UserAccount.custom_url==userID).get()
		if custom_url_user:
			profile_user = custom_url_user
		else:
			return redirect(url_for("invalid_profile"))
	
	user = current_user()
	if user.is_authenticated():
		inNetwork = user.is_connected(profile_user)
	else:
		inNetwork = False
	if inNetwork or profile_user.profile_privacy == 1:
		if user == profile_user:
			inNetwork = True
		booklist = []
		for copy in profile_user.get_library():
			item = Item.query(Item.key == copy.item).get().to_dict()
			if item["item_type"] == "book":
				item["item_subtype"] = copy.item_subtype
				item["star_rating"] = copy.star_rating
				item["escapedtitle"] = re.escape(item["title"])
				if copy.borrower is None:
					item["available"] = True
				else:
					item["available"] = False
				item["copyID"] = copy.key.id()
				booklist.append(item)
			
		# Sort library alphabetically, with title as the primary sort key,
		# author as secondary, and item_subtype as tertiary
		booklist.sort(key=lambda item: item["item_subtype"])
		booklist.sort(key=lambda item: item["title"].lower())

		movielist = []
		for copy in profile_user.get_library():
			item = Item.query(Item.key == copy.item).get().to_dict()
			if item["item_type"] == "movie":
				item["item_subtype"] = copy.item_subtype
				item["star_rating"] = copy.star_rating
				item["escapedtitle"] = re.escape(item["title"])
				if copy.borrower is None:
					item["available"] = True
				else:
					item["available"] = False
				item["copyID"] = copy.key.id()
				movielist.append(item)
			
		# Sort library alphabetically, with title as the primary sort key,
		# author as secondary, and item_subtype as tertiary
		movielist.sort(key=lambda item: item["item_subtype"])
		movielist.sort(key=lambda item: item["title"].lower())
		import hashlib
		import urllib
		gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(profile_user.email).hexdigest() + "?s=150&d=" + urllib.quote(request.host_url,'') + "static%2Fimg%2Fnoimage.png"
		return render_response('profile.html',inNetwork=inNetwork,profile_user=profile_user,booklist=booklist,movielist=movielist,gravatar_url=gravatar_url)
	return redirect(url_for("invalid_profile"))