diff options
author | Frederick Muriuki Muriithi | 2024-08-19 13:56:56 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-08-19 13:56:56 -0500 |
commit | e686d9be8b4d78bcc7348323f0ddc45f5548178d (patch) | |
tree | aede5176187e2f927863882eb62e237b30982c1d /gn_auth | |
parent | bdcc9938343c838a8c0be98e6bf53d3bbc03d9df (diff) | |
download | gn-auth-e686d9be8b4d78bcc7348323f0ddc45f5548178d.tar.gz |
Show "Forgot Password" link.
Provide the user with the "Forgot Password" link, if the backend
supports it.
Diffstat (limited to 'gn_auth')
-rw-r--r-- | gn_auth/auth/authentication/oauth2/views.py | 12 | ||||
-rw-r--r-- | gn_auth/templates/oauth2/authorise-user.html | 11 |
2 files changed, 20 insertions, 3 deletions
diff --git a/gn_auth/auth/authentication/oauth2/views.py b/gn_auth/auth/authentication/oauth2/views.py index ca1cf5a..d0b55b4 100644 --- a/gn_auth/auth/authentication/oauth2/views.py +++ b/gn_auth/auth/authentication/oauth2/views.py @@ -47,6 +47,14 @@ def authorise(): flash("Invalid OAuth2 client.", "alert-danger") if request.method == "GET": + def __forgot_password_table_exists__(conn): + with db.cursor(conn) as cursor: + cursor.execute("SELECT name FROM sqlite_master " + "WHERE type='table' " + "AND name='forgot_password_tokens'") + return bool(cursor.fetchone()) + return False + client = server.query_client(request.args.get("client_id")) _src = urlparse(request.args["redirect_uri"]) return render_template( @@ -55,7 +63,9 @@ def authorise(): scope=client.scope, response_type=request.args["response_type"], redirect_uri=request.args["redirect_uri"], - source_uri=f"{_src.scheme}://{_src.netloc}/") + source_uri=f"{_src.scheme}://{_src.netloc}/", + display_forgot_password=with_db_connection( + __forgot_password_table_exists__)) form = request.form def __authorise__(conn: db.DbConnection): diff --git a/gn_auth/templates/oauth2/authorise-user.html b/gn_auth/templates/oauth2/authorise-user.html index d69bdd4..07edb73 100644 --- a/gn_auth/templates/oauth2/authorise-user.html +++ b/gn_auth/templates/oauth2/authorise-user.html @@ -29,7 +29,14 @@ <input type="password" name="user:password" id="user:password" required="required" class="form-control" /> </div> - - <input type="submit" value="authorise" class="btn btn-primary" /> + + <div class="form-group"> + <input type="submit" value="authorise" class="btn btn-primary" /> + {%if display_forgot_password%} + <a href="{{url_for('oauth2.users.forgot_password')}}" + title="Click here to change your password." + class="form-text text-danger">Forgot Password</a> + {%endif%} + </div> </form> {%endblock%} |