diff --git a/index.py b/index.py index 8479d02..552e817 100755 --- a/index.py +++ b/index.py @@ -16,6 +16,16 @@ app.jinja_env.lstrip_blocks = True rdb = Redis(host=app.config.get('REDIS_HOST', '127.0.0.1'), password=app.config.get('REDIS_PSWD')) +class ReadonlyStringField(StringField): + def __call__(self, *args, **kwargs): + kwargs.setdefault('readonly', True) + return super(ReadonlyStringField, self).__call__(*args, **kwargs) + +class EditForm(Form): + user = ReadonlyStringField('Username') + pswd = PasswordField('Password') + submit = SubmitField('Submit') + class LoginForm(Form): user = StringField('Username', validators=[Required()]) pswd = PasswordField('Password', validators=[Required()]) @@ -26,13 +36,24 @@ class LoginForm(Form): def index(): nav = None if 'uuid' in session: - nav = ['logout'] + nav = ['edit', 'logout'] else: nav = ['login'] return render_template('index.html', nav=nav) +@app.route('/edit', methods=['GET', 'POST']) +def edit(): + if 'uuid' not in session: + return redirect(url_for('index')) + + nav = ['edit', 'logout'] + form = EditForm() + user = rdb.hgetall(session['uuid'])['user'] + form.user.data = user + return render_template('edit.html', form=form, nav=nav) + @app.route('/login', methods=['GET', 'POST']) def login(): nav = ['login'] @@ -64,7 +85,7 @@ def login(): def logout(): if 'uuid' in session: rdb.delete(session['uuid']) - del session['uuid'] + del session['uuid'] return redirect(url_for('index')) diff --git a/templates/edit.html b/templates/edit.html new file mode 100644 index 0000000..45f86e1 --- /dev/null +++ b/templates/edit.html @@ -0,0 +1,10 @@ +{% from "_helpers.html" import render_field %} +{% extends "base.html" %} +{% block content %} +
+{% endblock %}