ConsorciAOC-PRJ/decidim-module-trusted-ids

View on GitHub
app/views/decidim/trusted_ids/devise/sessions/_new.html.erb

Summary

Maintainability
Test Coverage
<%
  provider = Decidim::TrustedIds.omniauth_provider&.to_sym
  provider_str = t("decidim.authorization_handlers.trusted_ids_handler.name")
  icon_path = current_organization.enabled_omniauth_providers[provider]&.dig(:icon_path)
  override_login = Decidim::TrustedIds.custom_login_screen? && Devise.mappings[:user].omniauthable? && current_organization.enabled_omniauth_providers&.include?(provider)
%>

<div class="row collapse">
  <div class="row collapse">
    <div class="columns large-6 large-centered page-title trusted-ids-login-box">

      <% if override_login %>
        <h2><%= t(".login") %></h2>
        <p><%= t(".login_subtitle") %></p>
        <h6><%= t(".verified_identity", provider: provider_str) %></h6>
        <%= t(".verified_identity_html") %>
        <p><%= link_to decidim.send("user_#{provider}_omniauth_authorize_path"), class: "button button--social button--#{normalize_provider_name(provider)}", method: :post do %>
          <span class="button--social__icon">
            <%= external_icon icon_path.presence || Decidim::TrustedIds.omniauth[:icon_path] %>
          </span>
          <span class="button--social__text">
            <%= t(".verified_login") %>
          </span>
        <% end %></p>
        <hr>
        <p><%= link_to t(".unverified_login"), "#", class: "button hollow secondary expanded", onclick: "document.querySelectorAll('.decidim-login').forEach((el) => el.classList.toggle('hide'));return false" %></p>
        <% else %>
          <h1><%= t("devise.sessions.new.sign_in") %></h1>
          <% if current_organization.sign_up_enabled? %>
            <p>
              <%= t("decidim.devise.sessions.new.are_you_new?") %>
              <%= link_to t("decidim.devise.sessions.new.register"), new_user_registration_path %>
            </p>
          <% elsif current_organization.sign_in_enabled? %>
            <p>
              <%= t("decidim.devise.sessions.new.sign_up_disabled") %>
            </p>
          <% else %>
            <p>
              <%= t("decidim.devise.sessions.new.sign_in_disabled") %>
            </p>
          <% end %>
      <% end %>
    </div>
  </div>

  <% if override_login %>
    <div class="decidim-login hide">
      <%= render "decidim/trusted_ids/devise/sessions/omniauth_buttons" %>
    </div>
  <% else %>
    <% cache current_organization do %>
      <%= render "decidim/devise/shared/omniauth_buttons" %>
    <% end %>
  <% end %>

  <% if current_organization.sign_in_enabled? %>
    <div class="row decidim-login<%= " hide " if override_login %>">
      <div class="columns large-6 medium-centered">
        <div class="card">
          <div class="card__content">
            <%= decidim_form_for(resource, namespace: "session", as: resource_name, url: session_path(resource_name), html: { class: "register-form new_user" }) do |f| %>
              <div>
                <div class="field">
                  <%= f.email_field :email, autocomplete: "email" %>
                </div>
                <div class="field">
                  <%= f.password_field :password, autocomplete: "current-password" %>
                </div>
              </div>
                <% if devise_mapping.rememberable? %>
                  <div class="field">
                    <%= f.check_box :remember_me %>
                  </div>
                <% end %>
              <div class="actions">
                <%= f.submit t("devise.sessions.new.sign_in"), class: "button expanded" %>
              </div>
            <% end %>
            <%= render "decidim/devise/shared/links" %>
          </div>
        </div>
      </div>
    </div>
  <% end %>
</div>