-
Notifications
You must be signed in to change notification settings - Fork 4
Show "Last login" label next to the login method #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2042860
0382b81
05e535e
6c0da56
2f839e2
af7c6e6
a089234
5ea2c4e
b57e447
8a5b4fa
688119a
5bece7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,9 @@ | |
| </div> | ||
| </div> | ||
|
|
||
| <div class="ui small stackable teal centered fluid wrapping menu" | ||
| data-bind="semanticui: {tabs: {history: true, autoTabActivation: false}}"> | ||
| <div class="ui small stackable teal centered fluid wrapping menu" data-bind="semanticui: {tabs: { | ||
| {% if last_login_tab %}autoTabActivation: '{{ last_login_tab }}'{% endif %} | ||
| }}"> | ||
|
|
||
| <a class="item" data-tab="vcs"> | ||
| <i class="fas fa-cloud icon"></i> | ||
|
|
@@ -42,6 +43,7 @@ | |
|
|
||
| {# If allowed providers is given, disable the email menu item #} | ||
| <a class="{% if allowed_providers %}disabled{% endif %} item" | ||
| {% if last_login_tab == "email" %} data-tooltip="Last used" data-variation="teal visible" data-position="top center" {% endif %} | ||
| data-tab="email"> | ||
| <i class="fas fa-envelope icon"></i> | ||
| {% block authentication_email_text %} | ||
|
|
@@ -50,8 +52,7 @@ | |
| </a> | ||
|
|
||
| {% if USE_ORGANIZATIONS %} | ||
| <a class="item" | ||
| href="{% url "saml_resolve_login" %}{% if redirect_field_value %}?{{ redirect_field_name }}={{ redirect_field_value }}{% endif %}"> | ||
| <a class="item" data-tab="sso"> | ||
| <i class="fas fa-shield-alt icon"></i> | ||
| {% trans "Single sign-on" %} | ||
| </a> | ||
|
|
@@ -100,14 +101,34 @@ | |
| <div class="ui stackable relaxed text menu"> | ||
| <a class="item" href="{% url 'account_reset_password' %}">{% trans "Forgot your password?" %}</a> | ||
| <div class="right menu"> | ||
| <button class="ui primary button" type="submit">{% trans "Log in" %}</button> | ||
| <button class="ui primary button" | ||
| data-bind="click: $root.save_login_method" | ||
| data-provider="email" | ||
| type="submit">{% trans "Log in" %}</button> | ||
| </div> | ||
| </div> | ||
|
|
||
| </form> | ||
| {% endblock authentication_email %} | ||
| </div> | ||
|
|
||
| {% if USE_ORGANIZATIONS %} | ||
| <div class="ui basic center aligned tab segment" data-tab="sso"> | ||
| <a href="{% url "saml_resolve_login" %}{% if redirect_field_value %}?{{ redirect_field_name }}={{ redirect_field_value }}{% endif %}"> | ||
|
|
||
| <button class="ui button" | ||
| data-bind="click: $root.save_login_method" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another mention of |
||
| data-provider="sso" | ||
| type="submit" | ||
| {% if last_login_method == "sso" %} data-tooltip="Last used" data-variation="teal visible" data-position="right center" {% endif %} | ||
| title="Single sign-on"> | ||
| <i class="fas fa-shield-alt icon" aria-hidden="true"></i> | ||
| {% trans "Log in using single sign-on" %} | ||
| </button> | ||
| </a> | ||
| </div> | ||
| {% endif %} | ||
|
|
||
| {% block authentication_extra %} | ||
| {% endblock authentication_extra %} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,26 @@ | |
| action="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}"> | ||
| {% csrf_token %} | ||
|
|
||
| {# djlint: off #} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use something less generic than |
||
| <button class="ui {{ button_classes }} button" | ||
| data-bind="click: $root.save_login_method" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another |
||
| data-provider="{{ provider.id }}" | ||
| type="submit" | ||
| title="{{ provider.name }}"> | ||
| <i class="fa-brands fa-{{ provider.name|lower }} icon"></i> | ||
| {% blocktrans trimmed with provider_name=provider.app.name|default:provider.name verbiage=verbiage|default:'Connect to' %} | ||
| {{ verbiage }} {{ provider_name }} | ||
| {% endblocktrans %} | ||
| </button> | ||
|
|
||
| </form> | ||
| {% if last_login_method == provider.id|lower %} | ||
| data-tooltip="Last used" | ||
| data-variation="teal visible" | ||
| data-position="right center" | ||
| {% endif %} | ||
|
|
||
| title="{{ provider.name }}"> | ||
| {# djlint: on #} | ||
|
|
||
| <i class="fa-brands fa-{{ provider.name|lower }} icon"></i> | ||
| {% blocktrans trimmed with provider_name=provider.app.name|default:provider.name verbiage=verbiage|default:'Connect to' %} | ||
| {{ verbiage }} {{ provider_name }} | ||
| {% endblocktrans %} | ||
| </button> | ||
|
|
||
| </form> | ||
| {% endif %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,16 @@ export class ApplicationView { | |
| if (found_modal.length === 0) { | ||
| console.debug("Modal not found:", selector); | ||
| } | ||
|
|
||
| // Remove "visible" variation property to remove "Last used" tooltip | ||
| const buttons = document.querySelectorAll("button.ui"); | ||
| for (const button of buttons) { | ||
| if (button.dataset.variation) { | ||
| const variation = button.dataset.variation.split(" "); | ||
| variation.pop("visible"); | ||
| button.dataset.variation = variation.join(" "); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should always use KO view code to manipulate the DOM. Using JS queries or jQuery to manipulate the DOM in addition is mixing patterns and should be always avoided. I'm a bit confused what this is trying to do though. What is the intention here? It also seems like this would affect all modals, which we don't want. |
||
| }; | ||
| } | ||
|
|
||
|
|
@@ -94,4 +104,30 @@ export class ApplicationView { | |
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Save the provider used for login. | ||
| * | ||
| * This could be used like: | ||
| * | ||
| * .. code:: html | ||
| * | ||
| * <form method="post" action="..."> | ||
| * <button data-bind="click: $root.save_login_method"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
| * Log in using GitHub | ||
| * </button> | ||
| * </form> | ||
| * | ||
| * @param {Object} data - Context data | ||
| * @param {Event} event - Click event | ||
| * @returns {knockout_click} | ||
| */ | ||
| save_login_method(data, event) { | ||
| const elem = event.currentTarget; | ||
| if (window.isSecureContext) { | ||
| console.debug("Setting last login method: ", elem.dataset.provider); | ||
| cookieStore.set("last-login-method", elem.dataset.provider); | ||
| } | ||
| return true; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be implemented on a dedicated view class, not on the main application view. The main application view is strictly a router to these dedicated views and a couple utility methods. You should look at any of the other templates that use a model view and work from those templates, they all follow the same pattern with a dedicated view class for each view. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use
$roothere, this method should be in a dedicated view class.$rootis currently only used for some utility methods that are shared across many views.