diff --git a/create_app.py b/create_app.py index c73bb7c..913fee1 100644 --- a/create_app.py +++ b/create_app.py @@ -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 diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..1d05b27 --- /dev/null +++ b/forms.py @@ -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//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)) diff --git a/templates/pages/auth/login.html b/templates/pages/auth/login.html index 6eaf838..2f1e799 100644 --- a/templates/pages/auth/login.html +++ b/templates/pages/auth/login.html @@ -7,7 +7,7 @@ {% endif %} {% endwith %} -
+
Username diff --git a/templates/pages/auth/signup.html b/templates/pages/auth/signup.html index 1a5cd90..030b4a5 100644 --- a/templates/pages/auth/signup.html +++ b/templates/pages/auth/signup.html @@ -8,7 +8,7 @@
{% endif %} {% endwith %} - +
Username diff --git a/templates/pages/user_edit.html b/templates/pages/user_edit.html index 778038d..02f4122 100644 --- a/templates/pages/user_edit.html +++ b/templates/pages/user_edit.html @@ -1,5 +1,23 @@ {% extends 'layouts/index.html' %} {% block content %} -

Edit Profile

+

Edit Profile

+ +
+ + + + {% with messages = get_flashed_messages() %} + {% if messages %} +
+ {{ messages[0] }} +
+ {% endif %} + {% endwith %} {% endblock %}