diff --git a/app.py b/app.py index b994d93..3f613ab 100644 --- a/app.py +++ b/app.py @@ -15,8 +15,9 @@ Application is kept compact, with all its core in a single file. from flask import ( Flask, Markup, abort, flash, g, jsonify, make_response, redirect, request, render_template, send_from_directory) -from flask_login import LoginManager +from flask_login import LoginManager, login_user, logout_user from flask_wtf import CSRFProtect +from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.routing import BaseConverter from peewee import * from playhouse.db_url import connect as dbconnect @@ -425,13 +426,16 @@ login_manager = LoginManager(app) @app.before_request def _before_request(): - for l in request.headers.get('accept-language', 'it,en').split(','): - if ';' in l: - l, _ = l.split(';') - lang = l - break + if request.args.get('uselang') is not None: + lang = request.args['uselang'] else: - lang = 'en' + for l in request.headers.get('accept-language', 'it,en').split(','): + if ';' in l: + l, _ = l.split(';') + lang = l + break + else: + lang = 'en' g.lang = lang @app.context_processor @@ -766,6 +770,8 @@ def stats(): revision_count=PageRevision.select().count() ) +## account management ## + @app.route('/accounts/theme-switch') def theme_switch(): cook = request.cookies.get('dark') @@ -773,6 +779,32 @@ def theme_switch(): resp.set_cookie('dark', '0' if cook == '1' else '1', max_age=31556952, path='/') return resp +@app.route('/accounts/login/', methods=['GET','POST']) +def accounts_login(): + if request.method == 'POST': + try: + username = request.form['username'] + user = User.get(User.username == username) + if not check_password_hash(user.password, request.form['password']): + flash('Invalid username or password.') + return render_template('login.html') + except User.DoesNotExist: + flash('Invalid username or password.') + else: + remember_for = int(request.form['remember']) + if remember_for > 0: + login_user(user, remember=True, + duration=datetime.timedelta(days=remember_for)) + else: + login_user(user) + return redirect(request.args.get('next', '/')) + return render_template('login.html') + +@app.route('/accounts/logout/') +def accounts_logout(): + logout_user() + return redirect(request.args.get('next', '/')) + ## easter egg (lol) ## MNeaster = { diff --git a/i18n/salvi.en.json b/i18n/salvi.en.json index 7f81eec..3a39f35 100644 --- a/i18n/salvi.en.json +++ b/i18n/salvi.en.json @@ -28,6 +28,14 @@ "just-now": "just now", "n-minutes-ago": "{0} minutes ago", "n-hours-ago": "{0} hours ago", - "n-days-ago": "{0} days ago" + "n-days-ago": "{0} days ago", + "backlinks": "Backlinks", + "backlinks-empty": "No other pages linking here. Is this page orphan?", + "back-to": "Back to", + "login": "Log in", + "username": "Username", + "password": "Password", + "no-account-sign-up": "Don’t have an account?", + "sign-up": "Sign up" } } \ No newline at end of file diff --git a/i18n/salvi.fr.json b/i18n/salvi.fr.json new file mode 100644 index 0000000..439b6a4 --- /dev/null +++ b/i18n/salvi.fr.json @@ -0,0 +1,10 @@ +{ + "fr": { + "welcome": "Bienvenue à {0}!", + "homepage": "Page de démarrage", + "latest-notes": "Dernières notes", + "latest-uploads": "Derniers téléchargements", + "new-note": "Créer un note", + "upload-file": "Télécharger une image" + } +} \ No newline at end of file diff --git a/i18n/salvi.it.json b/i18n/salvi.it.json index 224d179..a746c5c 100644 --- a/i18n/salvi.it.json +++ b/i18n/salvi.it.json @@ -28,6 +28,12 @@ "just-now": "poco fa", "n-minutes-ago": "{0} minuti fa", "n-hours-ago": "{0} ore fa", - "n-days-ago": "{0} giorni fa" + "n-days-ago": "{0} giorni fa", + "backlinks": "Collegamenti in entrata", + "backlinks-empty": "Nessuna altra pagina punta qui. Questa pagina è orfana?", + "back-to": "Torna a", + "login": "Entra", + "username": "Nome utente", + "password": "Password" } } \ No newline at end of file diff --git a/i18n/salvi.ru.json b/i18n/salvi.ru.json new file mode 100644 index 0000000..bea96b7 --- /dev/null +++ b/i18n/salvi.ru.json @@ -0,0 +1,5 @@ +{ + "ru":{ + "welcome": "Добро пожаловать в {0}!" + } +} \ No newline at end of file diff --git a/templates/backlinks.html b/templates/backlinks.html index a064af9..9cf9f7c 100644 --- a/templates/backlinks.html +++ b/templates/backlinks.html @@ -8,7 +8,7 @@ {% block content %}

{{ p.title }}

-
Backlinks
+
{{ T('backlinks') }}
{% if backlinks %} {% else %} -

No other pages linking here. Is this page orphan?

+

{{ T("backlinks-empty") }}

{% endif %} -

Back to {{ p.title }}.

+

{{ T("back-to") }} {{ p.title }}.

{% endblock %} diff --git a/templates/base.html b/templates/base.html index 945f45f..fc6f0a1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -28,6 +28,7 @@
  • search
  • shuffle
  • create
  • +
  • login