Ejemplo n.º 1
0
def updateNotebyID(NoteID):
	sessionUser = checkCookiesSessionUser();
	if (sessionUser == None):
		return redirectHome();
	
	newTitle 		 = request.forms.get('titleNote');
	newContent 		 = request.forms.get('contentNote');
	updatedTime 	 = datetime.now().strftime('%Y-%m-%d %H:%M:%S');

	#Update fields for the note before inserting into database..
	note 			 = db.getNotebyNoteID(NoteID); #get note object from the previous note.
	note['Title'] 	 = newTitle;
	note['Content']  = newContent;
	note['EditedAt'] = updatedTime;
	note['Color']    = request.forms.get('colorNote');
	note['Private']  = request.forms.get('privateNote');
	note['Published']= int(request.forms.get('publishedNote'));

	if db.updateNote(note): #update the note into the database.

		response.status = 303
		user = db.getUserbyID(note['UserID'])

		response.set_header('Location', '/'+user['Username']+'/'+note['Permalink']);
		return template('singleNote', note=note, user=user); #Show login screen
		return template('singleNote', note=note, user=user);
	else:
		#problems updating note.
		return template('error', user=sessionUser)
Ejemplo n.º 2
0
def checkCookiesSessionUser():

	sessionUser   = None;
	sessionEmail  = request.get_cookie("Email", secret="secret123")
	sessionUserID = request.get_cookie("UserID", secret="secret123")

	if (sessionEmail == None or sessionUserID == None):
		return None; # Cookies doesn't match

	identifiedUser = db.getUserbyID(sessionUserID); # Return identified user. If the user was removed from our system, will return null user.
	return identifiedUser;
Ejemplo n.º 3
0
def showFormToEditUser():
	sessionUser = checkCookiesSessionUser();
	if (sessionUser == None):
		return redirectHome();

	user = db.getUserbyID(sessionUser['UserID']); # Get a user dictionary

	if user != None and sessionUser['UserID'] == user['UserID']: # if the user exists.
		return template("signup", user=user, editUser=True);
	else:
		return redirectHome();
Ejemplo n.º 4
0
def searchOnNotes():
	sessionUser = checkCookiesSessionUser();
	if (sessionUser == None):
		return template('login', user=None)

	user = db.getUserbyID(sessionUser['UserID'])

	if (user != None):
		Keyword = request.forms.get('query');
		notes = db.searchNotesFromUser(Keyword, sessionUser['UserID']);
		return template('notes', Keyword=Keyword, searchTemplate=True,  notes=notes, user=user);
	else:
		return redirectHome();
Ejemplo n.º 5
0
def userProfile():
	sessionUser = checkCookiesSessionUser();

	if (sessionUser == None):
		return redirectHome();

	user  = db.getUserbyID(sessionUser['UserID']);
	notes = db.getNotesByUserID(user['UserID']);
 
	if user != None:
		return template("profile", user=user, notes=notes);
	else:
		return redirectLogin();
Ejemplo n.º 6
0
def editSessionUser():
	sessionUser = checkCookiesSessionUser();
	
	if (sessionUser == None):
		return redirectLogin();

	user = db.getUserbyID(sessionUser['UserID']);
	
	user['Name'] 	 = request.forms.get('namesignup');
	user['Surname']  = request.forms.get('surnamesignup');
	user['Birthday'] = request.forms.get('birthdaysignup'); 
	user['City'] 	 = request.forms.get('citysignup'); 
 	
	if db.updateUser(user):
		notes = db.getNotesByUserID(user['UserID']);
		return template("profile", notes=notes, user=user);
	else:
		return template("profile-update-fail", user=sessionUser);