1
0
Fork 0

Add UsersHelper

This commit is contained in:
Alex Kotov 2018-11-30 03:01:27 +05:00
parent 5c76bc85dd
commit 1126f28d02
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
3 changed files with 46 additions and 6 deletions

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
module UsersHelper
def display_sign_in_link?
controller_name != 'sessions'
end
def display_sign_up_link?
devise_mapping.registerable? &&
controller_name != 'registrations'
end
def display_password_reset_link?
devise_mapping.recoverable? &&
controller_name != 'passwords' &&
controller_name != 'registrations'
end
def display_email_confirmation_link?
devise_mapping.confirmable? &&
controller_name != 'confirmations'
end
def display_unlock_link?
devise_mapping.lockable? &&
resource_class.unlock_strategy_enabled?(:email) &&
controller_name != 'unlocks'
end
def display_omniauth_links?
devise_mapping.omniauthable?
end
end

View file

@ -1,29 +1,29 @@
<%- if controller_name != 'sessions' %> <%- if display_sign_in_link? %>
<%= link_to translate('.sign_in'), new_session_path(resource_name) %> <%= link_to translate('.sign_in'), new_session_path(resource_name) %>
<br/> <br/>
<% end -%> <% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %> <%- if display_sign_up_link? %>
<%= link_to translate('.sign_up'), new_registration_path(resource_name) %> <%= link_to translate('.sign_up'), new_registration_path(resource_name) %>
<br/> <br/>
<% end -%> <% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> <%- if display_password_reset_link? %>
<%= link_to translate('.forgot_your_password'), new_password_path(resource_name) %> <%= link_to translate('.forgot_your_password'), new_password_path(resource_name) %>
<br/> <br/>
<% end -%> <% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> <%- if display_email_confirmation_link? %>
<%= link_to translate('.didn_t_receive_confirmation_instructions'), new_confirmation_path(resource_name) %> <%= link_to translate('.didn_t_receive_confirmation_instructions'), new_confirmation_path(resource_name) %>
<br/> <br/>
<% end -%> <% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> <%- if display_unlock_link? %>
<%= link_to translate('.didn_t_receive_unlock_instructions'), new_unlock_path(resource_name) %> <%= link_to translate('.didn_t_receive_unlock_instructions'), new_unlock_path(resource_name) %>
<br/> <br/>
<% end -%> <% end -%>
<%- if devise_mapping.omniauthable? %> <%- if display_omniauth_links? %>
<%- resource_class.omniauth_providers.each do |provider| %> <%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to translate('.sign_in_with_provider', provider: OmniAuth::Utils.camelize(provider)), omniauth_authorize_path(resource_name, provider) %> <%= link_to translate('.sign_in_with_provider', provider: OmniAuth::Utils.camelize(provider)), omniauth_authorize_path(resource_name, provider) %>
<br/> <br/>

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe UsersHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end