def add_note(): form = NoteForm(request.form) if AuthHelper.check_session_validation(current_user) and form.validate(): # Create new note note = Note() note.title = form.title.data note.content = form.content.data note.isprivate = form.isprivate.data # Get categories splitted_list = CategoryHelper.split_and_filter( form.categories.data, '') print(splitted_list) new_categories = CategoryHelper.get_new_categories( splitted_list, note.isprivate) print(new_categories) # Relations current_user.categories.extend(new_categories) note.categories.extend(new_categories) # Encrypt note.encrypt(AuthHelper.get_random_key()) # Database operations db.session.add(note) current_user.notes.append(note) db.session.commit() return redirect( url_for('app_notes.notes', username=current_user.username)) else: abort(404)
def notes(username): if current_user.is_authenticated and AuthHelper.check_username(current_user, username) \ and AuthHelper.check_session_validation(current_user): note_list = NoteHelper.get_user_notes(current_user) return render_template("notes.html.j2", notes=note_list, edit_form=NoteForm(), delete_form=DeleteNoteForm(), title="{} @ Librenotes".format(username), description="Welcome, {}".format(username)) else: note_list, searched_user = NoteHelper.get_searched_user_notes(username) if searched_user is not None: flash("You are seeing public notes of {}".format(username), "warning") description = "See public notes of {}".format(username) if searched_user.description is not None: description = searched_user.description return render_template("notes.html.j2", notes=note_list, edit_form=None, delete_form=None, title="{} @ Librenotes".format(username), description=description) else: abort(404)
def delete_note(): form = DeleteNoteForm(request.form) note = NoteHelper.get_user_note_with_id(current_user, form.id.data) if note and AuthHelper.check_session_validation(current_user): db.session.delete(note) db.session.commit() return redirect( url_for('app_notes.notes', username=current_user.username)) else: return abort(404)
def change_description_post(): form = ChangeDescription(request.form) if form.validate(): if AuthHelper.check_session_validation(current_user): current_user.description = form.description.data db.session.commit() Flasher.flash("Your description is successfully changed", "success") else: Flasher.flash("Are you fake?", category='warning') else: Flasher.flash_errors(form, "danger") return redirect(url_for("app_notes.notes", username=current_user.username))
def change_pass_post(): form = ChangePasswordForm(request.form) if form.validate(): if AuthHelper.check_password(current_user, form.password.data) and AuthHelper.check_session_validation( current_user): current_user.password = generate_password_hash(form.new_password.data) current_user.encrypt_rand_key(form.new_password.data, AuthHelper.get_random_key()) db.session.commit() Flasher.flash("Your password is successfully changed", "success") return redirect(url_for("app_notes.notes", username=current_user.username)) else: Flasher.flash("Your current password doesn't match with entered password or you are fake!", category='warning') return redirect(url_for("app_notes.notes", username=current_user.username)) else: Flasher.flash_errors(form, "danger") return redirect(url_for("app_notes.notes", username=current_user.username))
def edit_note(): form = NoteForm(request.form) note = NoteHelper.get_user_note_with_id(current_user, form.id.data) if note and form.validate() and AuthHelper.check_session_validation( current_user): # Update note note.title = form.title.data note.content = form.content.data note.isprivate = form.isprivate.data # Update note categoires splitted_list = CategoryHelper.split_and_filter( form.categories.data, '') new_categories = CategoryHelper.get_new_categories( splitted_list, note.isprivate) # Delete categories of note note.categories = [] # Append it current_user.categories.extend(new_categories) note.categories.extend(new_categories) note.encrypt(AuthHelper.get_random_key()) db.session.commit() return redirect(url_for('app_notes.notes', username=current_user)) else: return abort(404)