This commit is contained in:
ville rantanen
2016-07-04 12:36:50 +03:00
parent 1468a8258b
commit c7abca9659
4 changed files with 35 additions and 4 deletions

18
shop.py
View File

@@ -408,6 +408,24 @@ def register():
return redirect(url_for('login'))
return render_template('register.html', error=error)
@app.route('/profile', methods=['GET', 'POST'])
def profile():
error = None
if request.method == 'POST':
import re, string
pattern = re.compile('[\W]+')
password=password_hash(request.form['password'])
if len(request.form['password'])<5:
error="Password too short"
return render_template('profile.html', error=error)
g.db.execute('update users set pass=? where id=?',
[password,session.get('user')])
g.db.commit()
flash('successfully updated profile.')
return redirect(url_for('profile'))
return render_template('profile.html', error=error)
@app.route('/logout')
def logout():

View File

@@ -12,12 +12,11 @@
</head>
<body>
<div class=page>
<div class=metanav>
<a href="{{ url_for('list_shops') }}">List shops</a>
<a href="#" onclick="reload();">Reload page</a>
<a href="{{ url_for('profile') }}">Profile</a>
<a href="{{ url_for('logout') }}">Logout</a>
<div class=metanav>
</div>
{% for message in get_flashed_messages() %}
<div class=flash>{{ message }}</div>

14
templates/profile.html Normal file
View File

@@ -0,0 +1,14 @@
{% extends "layout.html" %}
{% block body %}
<h2>Profile</h2>
{% if error %}<p class=error><strong>Error:</strong> {{ error }}{% endif %}
<form action="{{ url_for('profile') }}" method=post>
<dl>
<dt>Username:
<dd>
<dt>Password:
<dd><input type=password name=password>
<dd><input type=submit value=Update>
</dl>
</form>
{% endblock %}

View File

@@ -8,7 +8,7 @@
<dd><input type=text name=username>
<dt>Password:
<dd><input type=password name=password>
<dd><input type=submit value=Login>
<dd><input type=submit value=register>
</dl>
</form>
{% endblock %}