diff options
-rw-r--r-- | app/templates/base.html | 2 | ||||
-rw-r--r-- | app/views/users.py | 24 |
2 files changed, 12 insertions, 14 deletions
diff --git a/app/templates/base.html b/app/templates/base.html index 6e8c372..687d718 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -37,7 +37,7 @@ </ul> <ul class="nav navbar-nav navbar-right"> {% if current_user.is_authenticated %} - <li><a href="{{ url_for('user_profile_page') }}">{{ current_user.first_name or current_user.username }}</a></li> + <li><a href="{{ url_for('user_profile_page', username=current_user.username) }}">{{ current_user.display_name }}</a></li> <li><a href="{{ url_for('user.logout') }}">Sign out</a></li> {% else %} <li><a href="{{ url_for('user.login') }}">Sign in</a></li> diff --git a/app/views/users.py b/app/views/users.py index e1d3408..72fc5fc 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -20,20 +20,18 @@ class UserProfileForm(FlaskForm): display_name = StringField("Display name") submit = SubmitField('Save') -@app.route('/user/', methods=['GET', 'POST']) -@app.route('/user/<username>/', methods=['GET']) -def user_profile_page(username=None): - user = None - form = None - if username is None: - if not current_user.is_authenticated: - return current_app.login_manager.unauthorized() - user = current_user - else: - user = User.query.filter_by(username=username).first() - if not user: - abort(404) +@app.route('/user/', methods=['GET']) +@login_required +def self_user_profile_page(): + return redirect(url_for("user_profile_page", username=current_user.username)) + +@app.route('/user/<username>/', methods=['GET', 'POST']) +def user_profile_page(username): + user = User.query.filter_by(username=username).first() + if not user: + abort(404) + form = None if user == current_user: # Initialize form form = UserProfileForm(formdata=request.form, obj=current_user) |