diff --git a/frontends/etiquette_flask/backend/endpoints/user_endpoints.py b/frontends/etiquette_flask/backend/endpoints/user_endpoints.py index cdec035..54d69ad 100644 --- a/frontends/etiquette_flask/backend/endpoints/user_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/user_endpoints.py @@ -35,6 +35,23 @@ def get_user_id_redirect(user_id): url = request.url.replace(url_from, url_to) return flask.redirect(url) +@site.route('/user//edit', methods=['POST']) +def post_user_edit(username): + session = session_manager.get(request) + if not session: + return jsonify.make_json_response({}, status=403) + user = common.P_user(username, response_type='json') + if session.user != user: + return jsonify.make_json_response({}, status=403) + + display_name = request.form.get('display_name') + if display_name is not None: + user.set_display_name(display_name) + + common.P.commit() + + return jsonify.make_json_response(user.jsonify()) + # Login and logout ################################################################################# @site.route('/login', methods=['GET']) diff --git a/frontends/etiquette_flask/static/js/api.js b/frontends/etiquette_flask/static/js/api.js index 65c6c38..2d21201 100644 --- a/frontends/etiquette_flask/static/js/api.js +++ b/frontends/etiquette_flask/static/js/api.js @@ -387,6 +387,15 @@ function callback_go_to_tags(response) /**************************************************************************************************/ api.users = {}; +api.users.edit = +function edit(username, display_name, callback) +{ + const url = `/user/${username}/edit`; + const data = new FormData(); + data.append("display_name", display_name); + common.post(url, data, callback); +} + api.users.login = function login(username, password, callback) { diff --git a/frontends/etiquette_flask/templates/user.html b/frontends/etiquette_flask/templates/user.html index d68f9b6..64c5e3a 100644 --- a/frontends/etiquette_flask/templates/user.html +++ b/frontends/etiquette_flask/templates/user.html @@ -10,6 +10,8 @@ {% if theme %}{% endif %} + +