|
|
|
@ -2,8 +2,9 @@ from flask import render_template, flash, abort, redirect, request, url_for
@@ -2,8 +2,9 @@ from flask import render_template, flash, abort, redirect, request, url_for
|
|
|
|
|
from flask_login import current_user, login_user, logout_user, login_required |
|
|
|
|
from werkzeug.urls import url_parse |
|
|
|
|
from biscd import app |
|
|
|
|
from .utils import flash_result |
|
|
|
|
from .models import Project, User |
|
|
|
|
from .froms import NewProjectForm, LoginForm, RegistrationForm |
|
|
|
|
from .froms import NewProjectForm, LoginForm, RegistrationForm, EmptyForm |
|
|
|
|
|
|
|
|
|
@app.route('/', methods=['GET', 'POST']) |
|
|
|
|
@app.route('/index', methods=['GET', 'POST']) |
|
|
|
@ -22,7 +23,7 @@ def login():
@@ -22,7 +23,7 @@ def login():
|
|
|
|
|
if form.validate_on_submit(): |
|
|
|
|
user = User.first(name=form.username.data) |
|
|
|
|
if user is None or not user.check_password(form.password.data): |
|
|
|
|
flash('Invalid username or password') |
|
|
|
|
flash('Invalid username or password', 'warning') |
|
|
|
|
return redirect(url_for('login')) |
|
|
|
|
login_user(user, remember=form.remember_me.data) |
|
|
|
|
next_page = request.args.get('next') |
|
|
|
@ -31,8 +32,8 @@ def login():
@@ -31,8 +32,8 @@ def login():
|
|
|
|
|
return redirect(next_page) |
|
|
|
|
return render_template('login.html', title='Sign In', form=form) |
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@app.route('/logout') |
|
|
|
|
@login_required |
|
|
|
|
def logout(): |
|
|
|
|
logout_user() |
|
|
|
|
return redirect(url_for('index')) |
|
|
|
@ -46,13 +47,29 @@ def register():
@@ -46,13 +47,29 @@ def register():
|
|
|
|
|
user = User(name=form.username.data, email=form.email.data) |
|
|
|
|
user.set_password(form.password.data) |
|
|
|
|
user.save() |
|
|
|
|
flash('Congratulations, you are now a registered user!') |
|
|
|
|
flash('Congratulations, you are now a registered user!', 'info') |
|
|
|
|
return redirect(url_for('login')) |
|
|
|
|
return render_template('register.html', title='Register', form=form) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/project/<project_url>', methods=['GET', 'POST']) |
|
|
|
|
@app.route('/project/<project_name>', methods=['GET']) |
|
|
|
|
@login_required |
|
|
|
|
def project_dashboard(project_url): |
|
|
|
|
project = Project.first_or_404(url=project_url) |
|
|
|
|
def project_dashboard(project_name): |
|
|
|
|
project = Project.first_or_404(name=project_name) |
|
|
|
|
return render_template('project.html', project=project) |
|
|
|
|
|
|
|
|
|
@app.route('/project/<project_name>/update', methods=['GET']) |
|
|
|
|
@login_required |
|
|
|
|
def project_update(project_name): |
|
|
|
|
project = Project.first_or_404(name=project_name) |
|
|
|
|
result = project.update() |
|
|
|
|
flash_result(result) |
|
|
|
|
return redirect(url_for('project_dashboard', project_name=project.name)) |
|
|
|
|
|
|
|
|
|
@app.route('/project/<project_name>/delete_files', methods=['GET']) |
|
|
|
|
@login_required |
|
|
|
|
def project_delete_files(project_name): |
|
|
|
|
project = Project.first_or_404(name=project_name) |
|
|
|
|
result = project.delete_files() |
|
|
|
|
flash_result(result) |
|
|
|
|
return redirect(url_for('project_dashboard', project_name=project.name)) |