dropdown menu, and fixes

This commit is contained in:
ville rantanen
2016-07-04 13:20:20 +03:00
parent c7abca9659
commit 7423f672d7
7 changed files with 77 additions and 7 deletions

0
data/.hidden Normal file
View File

View File

View File

@@ -410,20 +410,23 @@ def register():
@app.route('/profile', methods=['GET', 'POST'])
def profile():
if not session.get('logged_in'):
abort(401)
error = None
user=get_username(session.get('user'))
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)
return render_template('profile.html', error=error,user=user)
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)
return render_template('profile.html', error=error,user=user)

View File

@@ -28,3 +28,21 @@ function hidetoggle(name) {
}}
}
}
function dropDown() {
document.getElementById("Dropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}

View File

@@ -23,3 +23,47 @@ td { height: 1.75em; }
.error { background: #f0d6d6; padding: 0.5em; }
.hidden { display: none; }
.pointer { cursor: pointer; }
/* dropdown */
.dropbtn {
color: #377ba8;
text-decoration: underline;
cursor: pointer;
font-weight: bold;
letter-spacing:-0.1em;
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #ccc;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
right: 0px;
position: absolute;
background-color: #fafafa;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
padding: 12px 16px;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

View File

@@ -13,11 +13,16 @@
<body>
<div class=page>
<div class=metanav>
<a href="{{ url_for('list_shops') }}">List shops</a>
<a href="{{ url_for('list_shops') }}">Shops</a>
<div class="dropdown">
<p onclick="dropDown()" class="dropbtn">&sube;&supe;</p>
<div id="Dropdown" class="dropdown-content">
<a href="#" onclick="reload();">Reload page</a>
<a href="{{ url_for('profile') }}">Profile</a>
<a href="{{ url_for('logout') }}">Logout</a>
</div>
</div>
</div>
{% for message in get_flashed_messages() %}
<div class=flash>{{ message }}</div>
{% endfor %}

View File

@@ -5,7 +5,7 @@
<form action="{{ url_for('profile') }}" method=post>
<dl>
<dt>Username:
<dd>
<dd>{{ user }}
<dt>Password:
<dd><input type=password name=password>
<dd><input type=submit value=Update>