diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/oauth2/users.py | 26 | ||||
-rw-r--r-- | wqflask/wqflask/templates/oauth2/group_join_or_create.html | 2 |
2 files changed, 22 insertions, 6 deletions
diff --git a/wqflask/wqflask/oauth2/users.py b/wqflask/wqflask/oauth2/users.py index 4b267c9f..67d6b27f 100644 --- a/wqflask/wqflask/oauth2/users.py +++ b/wqflask/wqflask/oauth2/users.py @@ -1,8 +1,9 @@ -from flask import Blueprint, render_template +from flask import ( + flash, request, url_for, redirect, Response, Blueprint, render_template) from .checks import require_oauth2 -from .client import oauth2_get, oauth2_client -from .request_utils import user_details, request_error +from .client import oauth2_get, oauth2_post, oauth2_client +from .request_utils import user_details, request_error, process_error users = Blueprint("user", __name__) @@ -19,5 +20,20 @@ def user_profile(): @users.route("/request-add-to-group", methods=["POST"]) @require_oauth2 -def request_add_to_group(): - return "WOULD SEND MESSAGE TO HAVE YOU ADDED TO GROUP..." +def request_add_to_group() -> Response: + """Request to be added to a group.""" + form = request.form + group_id = form["group"] + + def __error__(error): + err = process_error(error) + flash(f"{err['error']}: {err['error_message']}", "alert-danger") + return redirect(url_for("oauth2.user.user_profile")) + + def __success__(response): + flash(f"{response['message']} (Response ID: {response['request_id']})", + "alert-success") + return redirect(url_for("oauth2.user.user_profile")) + + return oauth2_post(f"oauth2/group/requests/join/{group_id}", + data=form).either(__error__, __success__) diff --git a/wqflask/wqflask/templates/oauth2/group_join_or_create.html b/wqflask/wqflask/templates/oauth2/group_join_or_create.html index 0ec5674b..73f7a5de 100644 --- a/wqflask/wqflask/templates/oauth2/group_join_or_create.html +++ b/wqflask/wqflask/templates/oauth2/group_join_or_create.html @@ -27,7 +27,7 @@ <legend>Request to be added to group</legend> <div class="form-group"> <label class="control-label" for="group">Group</label> - <select class="form-control" id="group" required="required"> + <select class="form-control" id="group" required="required" name="group"> <option value="">Select a group</option> {%for group in groups%} <option value="{{group.group_id}}">{{group.group_name}}</option> |