Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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)