diasporadiaries

a platform for writing stories with personal accounts and messages
git clone git://parazyd.org/diasporadiaries.git
Log | Files | Refs | Submodules | README | LICENSE

commit ec13abe974fb2253051cd736a5e1c3c3f1b05007
parent 7ece93e2c759a388a02f079904f0a09003a4bfda
Author: parazyd <parazyd@dyne.org>
Date:   Sun, 20 Jan 2019 22:31:06 +0100

Move error templates to single file.

Diffstat:
Mdiaspora.py | 32+++++++++++++++-----------------
Atemplates/fail.html | 15+++++++++++++++
Dtemplates/fail_delete.html | 17-----------------
Dtemplates/fail_edit.html | 17-----------------
Dtemplates/fail_login.html | 15---------------
Dtemplates/fail_permissions.html | 15---------------
Dtemplates/fail_profile.html | 17-----------------
Dtemplates/fail_write.html | 15---------------
8 files changed, 30 insertions(+), 113 deletions(-)

diff --git a/diaspora.py b/diaspora.py @@ -97,14 +97,14 @@ def login(): """ if request.method == 'POST': if request.form['42']: - return render_template('fail_login.html', msg='You robot!') + return render_template('fail.html', msg='You robot!') username = request.form['username'] password = request.form['password'] user = find_user_by_email(username) if not user: - return render_template('fail_login.html', msg='No such user.') + return render_template('fail.html', msg='No such user.') if validate_user(user, password): login_user(LoginUser(user['id']), remember=True) @@ -113,8 +113,7 @@ def login(): nxt = url_for('main') return redirect(nxt) else: - return render_template('fail_login.html', - msg='Incorrect password.') + return render_template('fail.html', msg='Incorrect password.') return render_template('login.html') @@ -144,6 +143,7 @@ def messages(): msgs = get_latest_messages(current_user.username) return render_template('messages.html', messages=msgs) + @app.route('/sendmsg', methods=['POST']) @login_required def sendmsg(): @@ -164,7 +164,7 @@ def write(): return render_template('write.html') if request.form['42']: - return render_template('fail_write.html') + return render_template('fail.html', msg='Are you a robot?') delkey = randomstring(32) storyargs = [ @@ -196,13 +196,13 @@ def edit(): Route for editing and redacting. """ if not current_user.is_admin: - return render_template('fail_permissions.html') + return render_template('fail.html', msg='Unauthorized.') if request.method != 'POST': story = get_story(request.args.get('id')) if story: return render_template('edit.html', story=story) - return render_template('fail_edit.html') + return render_template('fail.html', msg='No story with this story id.') vals = [ ('name', request.form['Name']), @@ -231,14 +231,10 @@ def view(): @app.route('/delete') -@login_required def delete(): """ Route for deleting a specific story. """ - if not current_user.is_admin: - return render_template('fail_permissions.html') - delkey = request.args.get('key') if delkey: story_id = sql_select_col_where('id', 'deletekey', delkey) @@ -247,7 +243,8 @@ def delete(): sql_delete_row_where('id', story_id) return render_template('success_delete.html') - return render_template('fail_delete.html') + return render_template('fail.html', + msg='No story is linked to your delete key.') @app.route('/country') @@ -300,8 +297,9 @@ def profile(): name = stories[0]['name'] return render_template('profile.html', stories=stories, name=name, uid=uid) + return render_template('fail.html', msg='No stories listed.') - return render_template('fail_profile.html') + return render_template('fail.html', msg='No such profile.') @app.route('/dashboard') @@ -311,7 +309,7 @@ def dashboard(): Route for dashboard/admin view. """ if not current_user.is_admin: - return render_template('fail_permissions.html') + return render_template('fail.html', msg="Unauthorized.") fparam = {'pending': 0, 'published': 1} @@ -342,13 +340,13 @@ def dashboard(): @app.route('/users', methods=['GET', 'POST']) -#@login_required +@login_required def users(): """ Route for users view. """ - #if not current_user.is_admin: - # return render_template('fail_permissions.html') + if not current_user.is_admin: + return render_template('fail.html', msg='Unauthorized.') if request.method == 'POST': vals = [] diff --git a/templates/fail.html b/templates/fail.html @@ -0,0 +1,15 @@ +{% include 'header.html' %} + + <title>Sorry | Diaspora Diaries</title> + +{% include 'nav.html' %} + + <main role="main" class="container cover"> + + <h1 class="cover-heading">Sorry!</h1> + + <p class="lead">{{ msg }}</p> + + </main> + +{% include 'footer.html' %} diff --git a/templates/fail_delete.html b/templates/fail_delete.html @@ -1,17 +0,0 @@ -{% include 'header.html' %} - - <title>Deletion fail | Diaspora Diaries</title> - -{% include 'nav.html' %} - - <main role="main" class="container cover"> - - <h1 class="cover-heading">Error!</h1> - - <p class="lead">No story is linked to your delete key.</p> - - <p class="lead">You can return to the <a href="/">homepage</a> now.</p> - - </main> - -{% include 'footer.html' %} diff --git a/templates/fail_edit.html b/templates/fail_edit.html @@ -1,17 +0,0 @@ -{% include 'header.html' %} - - <title>Edit fail | Diaspora Diaries</title> - -{% include 'nav.html' %} - - <main role="main" class="container cover"> - - <h1 class="cover-heading">Error!</h1> - - <p class="lead">No story with this story id.</p> - - <p class="lead">You can return to the <a href="/">homepage</a> now.</p> - - </main> - -{% include 'footer.html' %} diff --git a/templates/fail_login.html b/templates/fail_login.html @@ -1,15 +0,0 @@ -{% include 'header.html' %} - - <title>Login fail | Diaspora Diaries</title> - -{% include 'nav.html' %} - - <main role="main" class="container cover"> - - <h1 class="cover-heading">Error!</h1> - - <p class="lead">{{ msg }}</p> - - </main> - -{% include 'footer.html' %} diff --git a/templates/fail_permissions.html b/templates/fail_permissions.html @@ -1,15 +0,0 @@ -{% include 'header.html' %} - - <title>Access denied | Diaspora Diaries</title> - -{% include 'nav.html' %} - - <main role="main" class="container cover"> - - <h1 class="cover-heading">Error!</h1> - - <p class="lead">You don't have the required permissions to view this page.</p> - - </main> - -{% include 'footer.html' %} diff --git a/templates/fail_profile.html b/templates/fail_profile.html @@ -1,17 +0,0 @@ -{% include 'header.html' %} - - <title>Error | Diaspora Diaries</title> - -{% include 'nav.html' %} - - <main role="main" class="container cover"> - - <h1 class="cover-heading">Error!</h1> - - <p class="lead">No such profile.</p> - - <p class="lead">You can return to the <a href="/">homepage</a> now.</p> - - </main> - -{% include 'footer.html' %} diff --git a/templates/fail_write.html b/templates/fail_write.html @@ -1,15 +0,0 @@ -{% include 'header.html' %} - - <title>Fail! | Diaspora Diaries</title> - -{% include 'nav.html' %} - - <main role="main" class="container cover"> - - <h1 class="cover-heading">Error!</h1> - - <p class="lead">Are you a robot?</p> - - </main> - -{% include 'footer.html' %}