mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-08 14:08:20 -06:00
Add profile name & about-me editing form
This commit is contained in:
@@ -37,6 +37,9 @@ def create_app():
|
||||
from .routes import blueprint as routes_blueprint
|
||||
app.register_blueprint(routes_blueprint)
|
||||
|
||||
from .forms import blueprint as forms_blueprint
|
||||
app.register_blueprint(forms_blueprint)
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
# note that we set the 404 status explicitly
|
||||
|
||||
24
forms.py
Normal file
24
forms.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from flask import Blueprint, flash, redirect, request, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
from create_app import db
|
||||
from .models import User
|
||||
|
||||
blueprint = Blueprint('forms', __name__)
|
||||
|
||||
|
||||
@blueprint.route('/user/<username>/edit', methods=['POST'])
|
||||
@login_required
|
||||
def edit_profile_post(username):
|
||||
user = db.session.query(User).filter_by(username=username).first_or_404()
|
||||
|
||||
# Ignore non
|
||||
if current_user.id != user.id:
|
||||
return redirect(url_for('main.user', username=username))
|
||||
|
||||
user.about_me = request.form.get('about-me', user.about_me)
|
||||
user.name = request.form.get('name', user.name)
|
||||
db.session.commit()
|
||||
|
||||
flash('Successfully updated profile.')
|
||||
return redirect(url_for('main.edit_user', username=username))
|
||||
@@ -7,7 +7,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
<form method="POST" action="/login" class="login-form">
|
||||
<form method="POST" action="{{ url_for('auth.login_post') }}" class="login-form">
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
Username
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
<form method="POST" action="/signup" class="login-form">
|
||||
<form method="POST" action="{{ url_for('auth.signup_post') }}" class="login-form">
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
Username
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
{% extends 'layouts/index.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Edit Profile</h3>
|
||||
<h3>Edit Profile</h3>
|
||||
<form method="POST" action="{{ url_for('forms.edit_profile_post', username=user.username) }}" class="profile-form">
|
||||
<label>
|
||||
Name<br>
|
||||
<input type="text" name="name" value="{{ user.name }}">
|
||||
</label><br>
|
||||
<label>
|
||||
About Me
|
||||
<textarea type="text" name="about-me">{{ user.about_me }}</textarea>
|
||||
</label>
|
||||
<button class="button">Save & Submit</button>
|
||||
</form>
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
<div class="notification is-danger">
|
||||
{{ messages[0] }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user