trestle-auth 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/trestle/auth/sessions_controller.rb +2 -2
- data/app/helpers/trestle/auth/user_helper.rb +2 -6
- data/app/views/trestle/auth/_userbox.html.erb +1 -1
- data/lib/generators/trestle/auth/install/install_generator.rb +33 -1
- data/lib/trestle/auth/configuration.rb +14 -3
- data/lib/trestle/auth/controller_methods.rb +4 -4
- data/lib/trestle/auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ef9ad52449a79a688c9ee2a6e7b86c35179b4c0bad12390f69cb31cf25704ff
|
4
|
+
data.tar.gz: 30f3172c89781a4baa176f1dffa233efbb1060a7cf5171aa93339b7aa27d1d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
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
|
-
|
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
|
-
|
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><%=
|
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
|
-
#
|
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
|
data/lib/trestle/auth/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trestle
|