trestle-auth 0.2.4 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.browserslistrc +1 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.travis.yml +20 -3
- data/Gemfile +14 -0
- data/README.md +34 -7
- data/app/assets/bundle/trestle/auth/bundle.css +1 -0
- data/app/assets/bundle/trestle/auth/userbox.css +1 -0
- data/app/assets/stylesheets/trestle/_custom-auth.css +6 -0
- data/app/assets/stylesheets/trestle/auth.css +2 -0
- data/app/controllers/trestle/auth/sessions_controller.rb +4 -5
- data/app/helpers/trestle/auth/title_helper.rb +3 -1
- data/app/helpers/trestle/auth/user_helper.rb +2 -6
- data/app/views/layouts/trestle/auth.html.erb +11 -8
- data/app/views/trestle/auth/_userbox.html.erb +17 -6
- data/app/views/trestle/auth/sessions/_form.html.erb +32 -0
- data/app/views/trestle/auth/sessions/new.html.erb +8 -31
- data/bin/rails +20 -0
- data/config/{locale → locales}/en.yml +7 -0
- data/config/locales/es.yml +15 -0
- data/config/{locale → locales}/pl.yml +7 -0
- data/config/{locale → locales}/pt-BR.yml +7 -0
- data/config/{locale → locales}/zh-CN.yml +0 -0
- data/config/routes.rb +8 -3
- data/frontend/_form.scss +79 -0
- data/frontend/_layout.scss +35 -0
- data/{app/assets/stylesheets/trestle/auth/_defaults.scss → frontend/_variables.scss} +2 -6
- data/frontend/index.scss +5 -0
- data/{app/assets/stylesheets/trestle/auth → frontend}/userbox.scss +14 -12
- data/gemfiles/rails-4.2.gemfile +18 -0
- data/gemfiles/rails-5.0.gemfile +18 -0
- data/gemfiles/rails-5.1.gemfile +18 -0
- data/gemfiles/rails-5.2.gemfile +18 -0
- data/gemfiles/rails-6.0.gemfile +18 -0
- data/lib/generators/trestle/auth/account/account_generator.rb +32 -0
- data/lib/generators/trestle/auth/account/templates/admin.rb.erb +47 -0
- data/lib/generators/trestle/auth/admin/admin_generator.rb +15 -1
- data/lib/generators/trestle/auth/admin/templates/admin.rb.erb +28 -5
- data/lib/generators/trestle/auth/install/install_generator.rb +45 -82
- data/lib/generators/trestle/auth/install/templates/basic.rb.erb +121 -0
- data/lib/generators/trestle/auth/install/templates/devise.rb.erb +87 -0
- data/lib/trestle/auth.rb +14 -8
- data/lib/trestle/auth/backends.rb +34 -0
- data/lib/trestle/auth/backends/base.rb +28 -0
- data/lib/trestle/auth/backends/basic.rb +72 -0
- data/lib/trestle/auth/backends/devise.rb +14 -0
- data/lib/trestle/auth/backends/warden.rb +53 -0
- data/lib/trestle/auth/configuration.rb +41 -6
- data/lib/trestle/auth/configuration/warden.rb +11 -0
- data/lib/trestle/auth/controller/authentication.rb +58 -0
- data/lib/trestle/auth/controller/locale.rb +18 -0
- data/lib/trestle/auth/controller/time_zone.rb +18 -0
- data/lib/trestle/auth/controller_methods.rb +3 -74
- data/lib/trestle/auth/engine.rb +1 -1
- data/lib/trestle/auth/model_methods.rb +2 -3
- data/lib/trestle/auth/version.rb +1 -1
- data/package.json +29 -0
- data/trestle-auth.gemspec +14 -10
- data/webpack.config.js +49 -0
- data/yarn.lock +4765 -0
- metadata +66 -32
- data/app/assets/javascripts/trestle/auth.js +0 -0
- data/app/assets/stylesheets/trestle/_custom-auth.scss +0 -4
- data/app/assets/stylesheets/trestle/auth.scss +0 -13
- data/app/assets/stylesheets/trestle/auth/_form.scss +0 -138
- data/app/assets/stylesheets/trestle/auth/_layout.scss +0 -20
File without changes
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
Trestle::Engine.routes.draw do
|
2
2
|
controller "trestle/auth/sessions" do
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
if Trestle.config.auth.enable_login
|
4
|
+
get 'login' => :new, as: :login
|
5
|
+
post 'login' => :create
|
6
|
+
end
|
7
|
+
|
8
|
+
if Trestle.config.auth.enable_logout
|
9
|
+
get 'logout' => :destroy, as: :logout
|
10
|
+
end
|
6
11
|
end
|
7
12
|
end
|
data/frontend/_form.scss
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
.login-form {
|
2
|
+
.form-control, .input-group-text {
|
3
|
+
background: $auth-form-control-bg;
|
4
|
+
border: $auth-form-control-border;
|
5
|
+
}
|
6
|
+
|
7
|
+
.form-control {
|
8
|
+
color: $auth-form-control-color;
|
9
|
+
font-size: 1.1rem;
|
10
|
+
|
11
|
+
padding: 1.75rem 0.75rem;
|
12
|
+
|
13
|
+
&:focus {
|
14
|
+
outline-color: transparent;
|
15
|
+
outline-style: none;
|
16
|
+
box-shadow: none;
|
17
|
+
}
|
18
|
+
|
19
|
+
&::placeholder {
|
20
|
+
color: $auth-form-control-placeholder;
|
21
|
+
}
|
22
|
+
|
23
|
+
&:-webkit-autofill {
|
24
|
+
-webkit-text-fill-color: $auth-form-control-color;
|
25
|
+
|
26
|
+
&, &:hover, &:focus, &:active {
|
27
|
+
transition: background-color 9999999s ease-in-out 0s;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
.input-group-prepend {
|
33
|
+
margin-right: 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
.input-group-text {
|
37
|
+
color: $auth-form-control-icon-color;
|
38
|
+
padding: 0.375rem 0.25rem 0.375rem 1rem;
|
39
|
+
}
|
40
|
+
|
41
|
+
.btn-primary {
|
42
|
+
box-shadow: rgba(black, 0.1) 0 0 2px;
|
43
|
+
|
44
|
+
padding-top: 0.75rem;
|
45
|
+
padding-bottom: 0.75rem;
|
46
|
+
}
|
47
|
+
|
48
|
+
.alert-danger {
|
49
|
+
background-color: rgba($alert-danger-bg, 0.75);
|
50
|
+
}
|
51
|
+
|
52
|
+
.remember-me {
|
53
|
+
font-size: 0.95rem;
|
54
|
+
line-height: 1.5;
|
55
|
+
|
56
|
+
padding-left: 0;
|
57
|
+
|
58
|
+
.custom-control-label {
|
59
|
+
display: block;
|
60
|
+
cursor: pointer;
|
61
|
+
|
62
|
+
background: $auth-remember-me-bg;
|
63
|
+
color: $auth-remember-me-color;
|
64
|
+
|
65
|
+
border-radius: $border-radius;
|
66
|
+
padding: 0.75em 1.5em 0.75em 3.25em;
|
67
|
+
|
68
|
+
&:hover {
|
69
|
+
background: opacify($auth-remember-me-bg, 0.05);
|
70
|
+
}
|
71
|
+
|
72
|
+
&::before,
|
73
|
+
&::after {
|
74
|
+
top: 0.175em + 0.75em;
|
75
|
+
left: 1.1em;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
.auth-body {
|
2
|
+
display: flex;
|
3
|
+
color: white;
|
4
|
+
|
5
|
+
.container {
|
6
|
+
margin: auto;
|
7
|
+
width: 320px;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
.auth-header {
|
12
|
+
text-align: center;
|
13
|
+
margin-bottom: 20px;
|
14
|
+
|
15
|
+
h1 {
|
16
|
+
display: flex;
|
17
|
+
align-items: center;
|
18
|
+
justify-content: center;
|
19
|
+
|
20
|
+
font-size: 1.75rem;
|
21
|
+
font-weight: 500;
|
22
|
+
text-shadow: rgba(black, 0.5) 0 1px 1px;
|
23
|
+
|
24
|
+
padding: 0.75rem 1rem;
|
25
|
+
}
|
26
|
+
|
27
|
+
img {
|
28
|
+
max-width: 80%;
|
29
|
+
max-height: 100%;
|
30
|
+
}
|
31
|
+
|
32
|
+
span {
|
33
|
+
margin-left: 10px;
|
34
|
+
}
|
35
|
+
}
|
@@ -1,13 +1,9 @@
|
|
1
|
-
$auth-bg: $theme-bg !default;
|
2
|
-
|
3
1
|
$auth-form-control-color: white !default;
|
4
2
|
$auth-form-control-placeholder: rgba(white, 0.5) !default;
|
5
3
|
$auth-form-control-bg: rgba(white, 0.1) !default;
|
6
4
|
$auth-form-control-border: 0 !default;
|
7
5
|
|
6
|
+
$auth-form-control-icon-color: rgba(white, 0.5) !default;
|
7
|
+
|
8
8
|
$auth-remember-me-color: rgba(white, 0.75) !default;
|
9
9
|
$auth-remember-me-bg: rgba(black, 0.075) !default;
|
10
|
-
|
11
|
-
$auth-login-btn-color: $btn-primary-color !default;
|
12
|
-
$auth-login-btn-border: $btn-primary-border !default;
|
13
|
-
$auth-login-btn-bg: $btn-primary-bg !default;
|
data/frontend/index.scss
ADDED
@@ -1,16 +1,18 @@
|
|
1
|
-
@import "trestle/support";
|
1
|
+
@import "~trestle/frontend/css/support";
|
2
2
|
|
3
3
|
.userbox {
|
4
|
-
|
5
|
-
|
4
|
+
order: 99;
|
5
|
+
padding: 2px 0;
|
6
|
+
|
7
|
+
display: flex;
|
8
|
+
align-items: center;
|
6
9
|
|
7
10
|
> a {
|
8
|
-
color: $
|
11
|
+
color: $body-color;
|
9
12
|
|
10
13
|
display: block;
|
11
14
|
padding: 2px 0;
|
12
15
|
|
13
|
-
font-size: 14px;
|
14
16
|
font-weight: normal;
|
15
17
|
line-height: 40px;
|
16
18
|
|
@@ -24,26 +26,26 @@
|
|
24
26
|
margin-left: 6px;
|
25
27
|
}
|
26
28
|
|
27
|
-
.
|
28
|
-
|
29
|
+
.dropdown-toggle {
|
30
|
+
&::after {
|
31
|
+
vertical-align: middle;
|
32
|
+
}
|
29
33
|
}
|
30
34
|
}
|
31
35
|
|
32
|
-
@include
|
36
|
+
@include media-breakpoint-down(sm) {
|
33
37
|
.userbox {
|
38
|
+
display: block;
|
34
39
|
position: relative;
|
35
40
|
z-index: 5;
|
36
41
|
|
37
|
-
> a, .name {
|
38
|
-
color: white;
|
39
|
-
}
|
40
|
-
|
41
42
|
.name {
|
42
43
|
display: none;
|
43
44
|
}
|
44
45
|
|
45
46
|
.avatar {
|
46
47
|
border: 1px solid rgba(white, 0.25);
|
48
|
+
margin-left: 0;
|
47
49
|
}
|
48
50
|
}
|
49
51
|
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "coveralls", require: false
|
5
|
+
gem "capybara"
|
6
|
+
|
7
|
+
gem "sqlite3", "~> 1.3.13"
|
8
|
+
gem "devise"
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "rails", "~> 4.2.0"
|
12
|
+
gem "sassc-rails"
|
13
|
+
|
14
|
+
gem "rake", "~> 12.0"
|
15
|
+
|
16
|
+
gem "trestle", github: "TrestleAdmin/trestle"
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "coveralls", require: false
|
5
|
+
gem "capybara"
|
6
|
+
|
7
|
+
gem "sqlite3", "~> 1.3.13"
|
8
|
+
gem "devise"
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "rails", "~> 5.0.0"
|
12
|
+
gem "sassc-rails"
|
13
|
+
|
14
|
+
gem "rake", "~> 12.0"
|
15
|
+
|
16
|
+
gem "trestle", github: "TrestleAdmin/trestle"
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "coveralls", require: false
|
5
|
+
gem "capybara"
|
6
|
+
|
7
|
+
gem "sqlite3", "~> 1.3.13"
|
8
|
+
gem "devise"
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "rails", "~> 5.1.0"
|
12
|
+
gem "sassc-rails"
|
13
|
+
|
14
|
+
gem "rake", "~> 12.0"
|
15
|
+
|
16
|
+
gem "trestle", github: "TrestleAdmin/trestle"
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "coveralls", require: false
|
5
|
+
gem "capybara"
|
6
|
+
|
7
|
+
gem "sqlite3", "~> 1.3.13"
|
8
|
+
gem "devise"
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "rails", "~> 5.2.0"
|
12
|
+
gem "sassc-rails"
|
13
|
+
|
14
|
+
gem "rake", "~> 12.0"
|
15
|
+
|
16
|
+
gem "trestle", github: "TrestleAdmin/trestle"
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "coveralls", require: false
|
5
|
+
|
6
|
+
gem "capybara"
|
7
|
+
gem "sqlite3", "~> 1.4"
|
8
|
+
gem "devise"
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "rails", "~> 6.0.0"
|
12
|
+
gem "sassc-rails"
|
13
|
+
|
14
|
+
gem "rake", "~> 12.0"
|
15
|
+
|
16
|
+
gem "trestle", github: "TrestleAdmin/trestle"
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Trestle
|
2
|
+
module Auth
|
3
|
+
module Generators
|
4
|
+
class AccountGenerator < ::Rails::Generators::Base
|
5
|
+
desc "Creates a Trestle admin for managing the logged in user"
|
6
|
+
|
7
|
+
argument :model, type: :string, default: "Administrator"
|
8
|
+
|
9
|
+
class_option :devise, type: :boolean, default: false, desc: "Create admin for a Devise user model"
|
10
|
+
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
def create_admin
|
14
|
+
template "admin.rb.erb", "app/admin/auth/account_admin.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
def devise?
|
18
|
+
options[:devise]
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
def parameter_name
|
23
|
+
singular_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def singular_name
|
27
|
+
model.demodulize.underscore
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
Trestle.resource(:account, model: <%= model %>, scope: Auth, singular: true) do
|
2
|
+
instance do
|
3
|
+
current_user
|
4
|
+
end
|
5
|
+
|
6
|
+
remove_action :new, :edit, :destroy
|
7
|
+
|
8
|
+
form do |<%= parameter_name %>|
|
9
|
+
text_field :email
|
10
|
+
|
11
|
+
<%- unless devise? -%>
|
12
|
+
row do
|
13
|
+
col(sm: 6) { text_field :first_name }
|
14
|
+
col(sm: 6) { text_field :last_name }
|
15
|
+
end
|
16
|
+
|
17
|
+
<%- end -%>
|
18
|
+
row do
|
19
|
+
col(sm: 6) { password_field :password }
|
20
|
+
col(sm: 6) { password_field :password_confirmation }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
<%- if devise? -%>
|
24
|
+
|
25
|
+
# Ignore the password parameters if they are blank
|
26
|
+
update_instance do |instance, attrs|
|
27
|
+
if attrs[:password].blank?
|
28
|
+
attrs.delete(:password)
|
29
|
+
attrs.delete(:password_confirmation) if attrs[:password_confirmation].blank?
|
30
|
+
end
|
31
|
+
|
32
|
+
instance.assign_attributes(attrs)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Log the current user back in if their password was changed
|
36
|
+
after_action on: :update do
|
37
|
+
if instance.encrypted_password_previously_changed?
|
38
|
+
login!(instance)
|
39
|
+
end
|
40
|
+
end if Devise.sign_in_after_reset_password
|
41
|
+
<%- end -%>
|
42
|
+
|
43
|
+
# Limit the parameters that are permitted to be updated by the user
|
44
|
+
params do |params|
|
45
|
+
params.require(:account).permit(:email, <% unless devise? %>:first_name, :last_name, <% end %>:password, :password_confirmation)
|
46
|
+
end
|
47
|
+
end
|
@@ -6,15 +6,29 @@ module Trestle
|
|
6
6
|
|
7
7
|
argument :model, type: :string, default: "Administrator"
|
8
8
|
|
9
|
+
class_option :devise, type: :boolean, default: false, desc: "Create admin for a Devise user model"
|
10
|
+
|
9
11
|
source_root File.expand_path("../templates", __FILE__)
|
10
12
|
|
11
13
|
def create_admin
|
12
14
|
template "admin.rb.erb", File.join('app/admin/auth', "#{model.underscore.pluralize}_admin.rb")
|
13
15
|
end
|
14
16
|
|
17
|
+
def devise?
|
18
|
+
options[:devise]
|
19
|
+
end
|
20
|
+
|
15
21
|
protected
|
22
|
+
def parameter_name
|
23
|
+
singular_name
|
24
|
+
end
|
25
|
+
|
16
26
|
def plural_name
|
17
|
-
|
27
|
+
singular_name.pluralize
|
28
|
+
end
|
29
|
+
|
30
|
+
def singular_name
|
31
|
+
model.demodulize.underscore
|
18
32
|
end
|
19
33
|
end
|
20
34
|
end
|
@@ -1,33 +1,56 @@
|
|
1
|
-
Trestle.resource(:<%= plural_name %>, model:
|
1
|
+
Trestle.resource(:<%= plural_name %>, model: <%= model %>, scope: Auth) do
|
2
2
|
menu do
|
3
3
|
group :configuration, priority: :last do
|
4
|
-
item :<%= plural_name %>, icon: "
|
4
|
+
item :<%= plural_name %>, icon: "fas fa-users"
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
table do
|
9
|
-
column :avatar, header: false do
|
10
|
-
avatar_for(
|
9
|
+
column :avatar, header: false do |<%= parameter_name %>|
|
10
|
+
avatar_for(<%= parameter_name %>)
|
11
11
|
end
|
12
12
|
column :email, link: true
|
13
|
+
<%- unless devise? -%>
|
13
14
|
column :first_name
|
14
15
|
column :last_name
|
16
|
+
<%- end -%>
|
15
17
|
actions do |a|
|
16
18
|
a.delete unless a.instance == current_user
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
form do
|
22
|
+
form do |<%= parameter_name %>|
|
21
23
|
text_field :email
|
22
24
|
|
25
|
+
<%- unless devise? -%>
|
23
26
|
row do
|
24
27
|
col(sm: 6) { text_field :first_name }
|
25
28
|
col(sm: 6) { text_field :last_name }
|
26
29
|
end
|
27
30
|
|
31
|
+
<%- end -%>
|
28
32
|
row do
|
29
33
|
col(sm: 6) { password_field :password }
|
30
34
|
col(sm: 6) { password_field :password_confirmation }
|
31
35
|
end
|
32
36
|
end
|
37
|
+
<%- if devise? -%>
|
38
|
+
|
39
|
+
# Ignore the password parameters if they are blank
|
40
|
+
update_instance do |instance, attrs|
|
41
|
+
if attrs[:password].blank?
|
42
|
+
attrs.delete(:password)
|
43
|
+
attrs.delete(:password_confirmation) if attrs[:password_confirmation].blank?
|
44
|
+
end
|
45
|
+
|
46
|
+
instance.assign_attributes(attrs)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Log the current user back in if their password was changed
|
50
|
+
after_action on: :update do
|
51
|
+
if instance == current_user && instance.encrypted_password_previously_changed?
|
52
|
+
login!(instance)
|
53
|
+
end
|
54
|
+
end if Devise.sign_in_after_reset_password
|
55
|
+
<%- end -%>
|
33
56
|
end
|