trestle-auth 0.2.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of trestle-auth might be problematic. Click here for more details.

Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.browserslistrc +1 -0
  3. data/.gitignore +5 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +20 -3
  6. data/Gemfile +14 -0
  7. data/README.md +35 -8
  8. data/app/assets/bundle/trestle/auth/bundle.css +1 -0
  9. data/app/assets/bundle/trestle/auth/userbox.css +1 -0
  10. data/app/assets/stylesheets/trestle/_custom-auth.css +6 -0
  11. data/app/assets/stylesheets/trestle/auth.css +2 -0
  12. data/app/controllers/trestle/auth/sessions_controller.rb +4 -5
  13. data/app/helpers/trestle/auth/title_helper.rb +20 -0
  14. data/app/helpers/trestle/auth/user_helper.rb +2 -6
  15. data/app/views/layouts/trestle/auth.html.erb +11 -16
  16. data/app/views/trestle/auth/_userbox.html.erb +17 -6
  17. data/app/views/trestle/auth/sessions/_form.html.erb +32 -0
  18. data/app/views/trestle/auth/sessions/new.html.erb +8 -31
  19. data/bin/rails +20 -0
  20. data/config/{locale → locales}/en.yml +7 -0
  21. data/config/locales/es.yml +15 -0
  22. data/config/{locale → locales}/pl.yml +7 -0
  23. data/config/{locale → locales}/pt-BR.yml +7 -0
  24. data/config/locales/zh-CN.yml +8 -0
  25. data/config/routes.rb +8 -3
  26. data/frontend/_form.scss +79 -0
  27. data/frontend/_layout.scss +35 -0
  28. data/{app/assets/stylesheets/trestle/auth/_defaults.scss → frontend/_variables.scss} +2 -6
  29. data/frontend/index.scss +5 -0
  30. data/{app/assets/stylesheets/trestle/auth → frontend}/userbox.scss +14 -12
  31. data/gemfiles/rails-4.2.gemfile +18 -0
  32. data/gemfiles/rails-5.0.gemfile +18 -0
  33. data/gemfiles/rails-5.1.gemfile +18 -0
  34. data/gemfiles/rails-5.2.gemfile +18 -0
  35. data/gemfiles/rails-6.0.gemfile +18 -0
  36. data/lib/generators/trestle/auth/account/account_generator.rb +32 -0
  37. data/lib/generators/trestle/auth/account/templates/admin.rb.erb +47 -0
  38. data/lib/generators/trestle/auth/admin/admin_generator.rb +15 -1
  39. data/lib/generators/trestle/auth/admin/templates/admin.rb.erb +28 -5
  40. data/lib/generators/trestle/auth/install/install_generator.rb +39 -83
  41. data/lib/generators/trestle/auth/install/templates/basic.rb.erb +121 -0
  42. data/lib/generators/trestle/auth/install/templates/devise.rb.erb +87 -0
  43. data/lib/trestle/auth.rb +14 -8
  44. data/lib/trestle/auth/backends.rb +34 -0
  45. data/lib/trestle/auth/backends/base.rb +28 -0
  46. data/lib/trestle/auth/backends/basic.rb +72 -0
  47. data/lib/trestle/auth/backends/devise.rb +14 -0
  48. data/lib/trestle/auth/backends/warden.rb +53 -0
  49. data/lib/trestle/auth/configuration.rb +41 -6
  50. data/lib/trestle/auth/configuration/warden.rb +11 -0
  51. data/lib/trestle/auth/controller/authentication.rb +55 -0
  52. data/lib/trestle/auth/controller/locale.rb +18 -0
  53. data/lib/trestle/auth/controller/time_zone.rb +18 -0
  54. data/lib/trestle/auth/controller_methods.rb +3 -74
  55. data/lib/trestle/auth/engine.rb +1 -1
  56. data/lib/trestle/auth/model_methods.rb +2 -3
  57. data/lib/trestle/auth/version.rb +1 -1
  58. data/package.json +29 -0
  59. data/trestle-auth.gemspec +14 -10
  60. data/webpack.config.js +49 -0
  61. data/yarn.lock +4765 -0
  62. metadata +67 -31
  63. data/app/assets/javascripts/trestle/auth.js +0 -0
  64. data/app/assets/stylesheets/trestle/_custom-auth.scss +0 -4
  65. data/app/assets/stylesheets/trestle/auth.scss +0 -13
  66. data/app/assets/stylesheets/trestle/auth/_form.scss +0 -120
  67. data/app/assets/stylesheets/trestle/auth/_layout.scss +0 -20
@@ -6,3 +6,10 @@ pt-BR:
6
6
  logout: "Sair"
7
7
  error: "Email ou Senha incorretos."
8
8
  remember_me: "Lembrar-me"
9
+
10
+ auth/account:
11
+ titles:
12
+ edit: "Minha Conta"
13
+
14
+ breadcrumbs:
15
+ index: "Minha Conta"
@@ -0,0 +1,8 @@
1
+ zh-CN:
2
+ admin:
3
+ auth:
4
+ my_account: "我的账号"
5
+ login: "登录"
6
+ logout: "退出登录"
7
+ error: "登录信息不正确。"
8
+ remember_me: "记住我"
@@ -1,7 +1,12 @@
1
1
  Trestle::Engine.routes.draw do
2
2
  controller "trestle/auth/sessions" do
3
- get 'login' => :new, as: :login
4
- post 'login' => :create
5
- get 'logout' => :destroy, as: :logout
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
@@ -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;
@@ -0,0 +1,5 @@
1
+ @import "~trestle/frontend/css/support";
2
+
3
+ @import "variables";
4
+ @import "layout";
5
+ @import "form";
@@ -1,16 +1,18 @@
1
- @import "trestle/support";
1
+ @import "~trestle/frontend/css/support";
2
2
 
3
3
  .userbox {
4
- margin-top: 2px;
5
- margin-bottom: 2px;
4
+ order: 99;
5
+ padding: 2px 0;
6
+
7
+ display: flex;
8
+ align-items: center;
6
9
 
7
10
  > a {
8
- color: $text-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
- .name {
28
- color: $text-color;
29
+ .dropdown-toggle {
30
+ &::after {
31
+ vertical-align: middle;
32
+ }
29
33
  }
30
34
  }
31
35
 
32
- @include mobile {
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
- model.demodulize.underscore.pluralize
27
+ singular_name.pluralize
28
+ end
29
+
30
+ def singular_name
31
+ model.demodulize.underscore
18
32
  end
19
33
  end
20
34
  end