trestle-auth 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e01368d321502dbe498b5bdf59088390bd6086aeef291013f0baaa0416ef4c2
4
- data.tar.gz: 9eaec32a25dc19056911f58982dcec072f426ca5835e30fe6501064c7374c68b
3
+ metadata.gz: 8ef9ad52449a79a688c9ee2a6e7b86c35179b4c0bad12390f69cb31cf25704ff
4
+ data.tar.gz: 30f3172c89781a4baa176f1dffa233efbb1060a7cf5171aa93339b7aa27d1d3f
5
5
  SHA512:
6
- metadata.gz: 0df58e37c7544874b4e4c72367933e2cec9729cb7aa68effcb6d35cd92abde4e53f73e3ad4abee0598fa3fcfe1fcaa0f6593af3ff75b5f7e6e2ddbe2b48b4b5b
7
- data.tar.gz: fb7e23d61644b5e88bd9a92ade6c0e16e52fbf8d71d76c2ef45445ef219550cd3443ffea6a9d116b49fe801fa3bdeaaa43b7d83fb0fea809277e4faa0cc0e203
6
+ metadata.gz: c51b04bb59d56bf4e65f268944fb1b1f0e92001ad83115f630a24381bc70f7474491456126bfffad1372612150d75481dd98bb46cbc2e200116efb4cc1983c89
7
+ data.tar.gz: f5dfe2f6cf6298d8b8ff39be723498951d40a77f53671e4845a85c23c7bfddc09f27ff21fdf06e583f33e8254d9f9c3e37faa33b873e2af732e91be0df776b06
@@ -10,7 +10,7 @@ class Trestle::Auth::SessionsController < Trestle::ApplicationController
10
10
  if user = Trestle.config.auth.authenticate(params)
11
11
  login!(user)
12
12
  remember_me! if params[:remember_me] == "1"
13
- redirect_to previous_location || Trestle.config.path
13
+ redirect_to previous_location || instance_exec(&Trestle.config.auth.redirect_on_login)
14
14
  else
15
15
  flash[:error] = t("admin.auth.error", default: "Incorrect login details.")
16
16
  redirect_to action: :new
@@ -19,6 +19,6 @@ class Trestle::Auth::SessionsController < Trestle::ApplicationController
19
19
 
20
20
  def destroy
21
21
  logout!
22
- redirect_to login_url
22
+ redirect_to instance_exec(&Trestle.config.auth.redirect_on_logout)
23
23
  end
24
24
  end
@@ -1,13 +1,9 @@
1
1
  module Trestle::Auth::UserHelper
2
2
  def format_user_name(user)
3
- if user.respond_to?(:first_name) && user.respond_to?(:last_name)
4
- safe_join([user.first_name, content_tag(:strong, user.last_name)], " ")
5
- else
6
- display(user)
7
- end
3
+ instance_exec(user, &Trestle.config.auth.format_user_name)
8
4
  end
9
5
 
10
6
  def avatar_for(user)
11
- avatar { instance_exec(user, &Trestle.config.auth.avatar) } if Trestle.config.auth.avatar
7
+ instance_exec(user, &Trestle.config.auth.avatar) if Trestle.config.auth.avatar
12
8
  end
13
9
  end
@@ -10,7 +10,7 @@
10
10
 
11
11
  <ul class="dropdown-menu dropdown-menu-right">
12
12
  <% if Trestle.config.auth.user_admin && user_admin = Trestle.lookup(Trestle.config.auth.user_admin) -%>
13
- <li><%= link_to t("admin.auth.my_account", default: "My Account"), user_admin.path(:show, id: current_user), class: "dropdown-item" %></li>
13
+ <li><%= admin_link_to t("admin.auth.my_account", default: "My Account"), current_user, admin: user_admin, class: "dropdown-item" %></li>
14
14
  <% end -%>
15
15
  <li><%= link_to t("admin.auth.logout", default: "Log out"), trestle.logout_path, class: "dropdown-item" %></li>
16
16
  </ul>
@@ -6,6 +6,12 @@ module Trestle
6
6
 
7
7
  argument :model, type: :string, default: "Administrator"
8
8
 
9
+ def check_trestle_installed
10
+ unless ::File.exist?("config/initializers/trestle.rb")
11
+ raise Thor::Error, "The file config/initializers/trestle.rb does not appear to exist. Please run `trestle:install` first."
12
+ end
13
+ end
14
+
9
15
  def insert_configuration
10
16
  inject_into_file "config/initializers/trestle.rb", before: /^end/ do
11
17
  <<-RUBY.strip_heredoc.indent(2)
@@ -48,7 +54,17 @@ module Trestle
48
54
  # Defaults to the Gravatar based on the user's email address.
49
55
  #
50
56
  # config.auth.avatar = ->(user) {
51
- # image_tag(user.avatar_url, alt: user.name)
57
+ # avatar(fallback: user.initials) do
58
+ # image_tag(user.avatar_url, alt: user.name) if user.avatar_url?
59
+ # end
60
+ # }
61
+
62
+ # Customize the rendering of the current user's name in the main header.
63
+ # Defaults to the user's #first_name and #last_name (last name in bold),
64
+ # with a fallback to `display(user)` if those methods aren't defined.
65
+ #
66
+ # config.auth.format_user_name = ->(user) {
67
+ # content_tag(:strong, user.full_name)
52
68
  # }
53
69
 
54
70
  # Customize the method for determining the user's locale.
@@ -65,6 +81,22 @@ module Trestle
65
81
  # user.time_zone if user.respond_to?(:time_zone)
66
82
  # }
67
83
 
84
+ # Specify the redirect location after a successful login.
85
+ # Defaults to the main Trestle admin path.
86
+ #
87
+ # config.auth.redirect_on_login = -> {
88
+ # if admin = Trestle.lookup(Trestle.config.auth.user_admin)
89
+ # admin.instance_path(current_user)
90
+ # else
91
+ # Trestle.config.path
92
+ # end
93
+ # }
94
+
95
+ # Specify the redirect location after logging out.
96
+ # Defaults to the trestle-auth new login path.
97
+ #
98
+ # config.auth.redirect_on_logout = -> { "/" }
99
+
68
100
  # Enable or disable remember me functionality. Defaults to true.
69
101
  #
70
102
  # config.auth.remember.enabled = false
@@ -27,16 +27,27 @@ module Trestle
27
27
  }
28
28
 
29
29
  option :avatar, ->(user) {
30
- gravatar(user.email)
30
+ avatar { gravatar(user.email) }
31
+ }, evaluate: false
32
+
33
+ option :format_user_name, ->(user) {
34
+ if user.respond_to?(:first_name) && user.respond_to?(:last_name)
35
+ safe_join([user.first_name, content_tag(:strong, user.last_name)], " ")
36
+ else
37
+ display(user)
38
+ end
31
39
  }, evaluate: false
32
40
 
33
41
  option :locale, ->(user) {
34
42
  user.locale if user.respond_to?(:locale)
35
- }
43
+ }, evaluate: false
36
44
 
37
45
  option :time_zone, ->(user) {
38
46
  user.time_zone if user.respond_to?(:time_zone)
39
- }
47
+ }, evaluate: false
48
+
49
+ option :redirect_on_login, -> { Trestle.config.path }, evaluate: false
50
+ option :redirect_on_logout, -> { login_url }, evaluate: false
40
51
 
41
52
  option :remember, Rememberable.new
42
53
  end
@@ -8,8 +8,8 @@ module Trestle
8
8
 
9
9
  before_action :require_authenticated_user
10
10
 
11
- around_action :set_locale, if: :logged_in?
12
- around_action :set_time_zone, if: :logged_in?
11
+ around_action :set_locale, if: :logged_in? if Trestle.config.auth.locale
12
+ around_action :set_time_zone, if: :logged_in? if Trestle.config.auth.time_zone
13
13
  end
14
14
 
15
15
  protected
@@ -71,11 +71,11 @@ module Trestle
71
71
  end
72
72
 
73
73
  def set_locale
74
- I18n.with_locale(Trestle.config.auth.locale(current_user) || I18n.default_locale) { yield }
74
+ I18n.with_locale(Trestle.config.auth.locale.call(current_user) || I18n.default_locale) { yield }
75
75
  end
76
76
 
77
77
  def set_time_zone
78
- Time.use_zone(Trestle.config.auth.time_zone(current_user) || Rails.application.config.time_zone) { yield }
78
+ Time.use_zone(Trestle.config.auth.time_zone.call(current_user) || Rails.application.config.time_zone) { yield }
79
79
  end
80
80
  end
81
81
  end
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Auth
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trestle-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pohlenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trestle