From 8b2018852e54a005a39234d6965e6268192718dc Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 4 Jun 2018 18:49:42 +0100 Subject: [PATCH] Add redirection to set password after login if not set --- app/scss/components.scss | 5 ++++ app/templates/flask_user/login.html | 25 ++++++++---------- app/templates/users/set_password.html | 38 ++++++++++++++++----------- app/views/githublogin.py | 5 +++- app/views/users.py | 2 +- 5 files changed, 43 insertions(+), 32 deletions(-) diff --git a/app/scss/components.scss b/app/scss/components.scss index 3259aa6..aac5e26 100644 --- a/app/scss/components.scss +++ b/app/scss/components.scss @@ -315,6 +315,11 @@ select:not([multiple]) { border: 1px solid #c96; } +.alert-primary { + background: #339; + border: 1px solid #66a; +} + .alert-success { background: #161; border: 1px solid #393; diff --git a/app/templates/flask_user/login.html b/app/templates/flask_user/login.html index 8409f79..a758011 100644 --- a/app/templates/flask_user/login.html +++ b/app/templates/flask_user/login.html @@ -11,10 +11,6 @@ Sign in

{%trans%}Sign in{%endtrans%}

-

Sign in with Github

-

GitHub

- -

Sign in with username/password

{{ form.hidden_tag() }} @@ -38,17 +34,13 @@ Sign in {# Password field #} {% set field = form.password %}
- {# Label on left, "Forgot your Password?" on right #}
-
- -
-
- {% if user_manager.enable_forgot_password %} +
+ [{%trans%}Forgot My Password{%endtrans%}] + {% endif %} +
{{ field(class_='form-control', tabindex=120) }} {% if field.errors %} @@ -64,7 +56,12 @@ Sign in {% endif %} {# Submit button #} - {{ render_submit_field(form.submit, tabindex=180) }} +

+ {{ render_submit_field(form.submit, tabindex=180) }} +

+ +

Sign in with Github

+

GitHub

diff --git a/app/templates/users/set_password.html b/app/templates/users/set_password.html index 510f9b3..6fe88e9 100644 --- a/app/templates/users/set_password.html +++ b/app/templates/users/set_password.html @@ -5,30 +5,36 @@ {% endblock %} {% block content %} + +{% if optional %} +
+ It is recommended that you set a password for your account. + + Skip +
+{% endif %} + +

Set Password

{% from "macros/forms.html" import render_field, render_submit_field %}
-
-
- {{ form.hidden_tag() }} + {{ form.hidden_tag() }} - {% if not current_user.email %} - {{ render_field(form.email, tabindex=230) }} + {% if not current_user.email %} + {{ render_field(form.email, tabindex=230) }} -

- Your email is needed to recover your account if you forget your - password, and to optionally send notifications. - Your email will never be shared to a third-party. -

- {% endif %} +

+ Your email is needed to recover your account if you forget your + password, and to optionally send notifications. + Your email will never be shared to a third-party. +

+ {% endif %} - {{ render_field(form.password, tabindex=230) }} - {{ render_field(form.password2, tabindex=240) }} + {{ render_field(form.password, tabindex=230) }} + {{ render_field(form.password2, tabindex=240) }} - {{ render_submit_field(form.submit, tabindex=280) }} -
-
+ {{ render_submit_field(form.submit, tabindex=280) }}
{% endblock %} diff --git a/app/views/githublogin.py b/app/views/githublogin.py index 7320163..defdad1 100644 --- a/app/views/githublogin.py +++ b/app/views/githublogin.py @@ -64,7 +64,10 @@ def github_authorized(oauth_token): flash("Unable to find an account for that Github user", "error") return redirect(url_for("user_claim_page")) elif loginUser(userByGithub): - return redirect(next_url or url_for("home_page")) + if current_user.password is None: + return redirect(next_url or url_for("set_password_page", optional=True)) + else: + return redirect(next_url or url_for("home_page")) else: flash("Authorization failed [err=gh-login-failed]", "danger") return redirect(url_for("user.login")) diff --git a/app/views/users.py b/app/views/users.py index 43dea8e..256f7d1 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -162,7 +162,7 @@ def set_password_page(): else: flash("Passwords do not match", "error") - return render_template("users/set_password.html", form=form) + return render_template("users/set_password.html", form=form, optional=request.args.get("optional")) @app.route("/user/claim/", methods=["GET", "POST"])