revise_auth-jets 0.3.0 → 0.3.2
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 +4 -4
- data/README.md +1 -1
- data/app/config/routes.rb +7 -0
- data/app/controllers/api/base_controller.rb +42 -0
- data/app/controllers/api/v1/mes_controller.rb +11 -0
- data/app/controllers/revise_auth/registrations_controller.rb +1 -0
- data/app/controllers/revise_auth/sessions_controller.rb +1 -0
- data/app/stylesheet/theme.scss +1563 -0
- data/app/views/revise_auth/registrations/edit.html.erb +43 -52
- data/app/views/revise_auth/registrations/new.html.erb +29 -25
- data/app/views/revise_auth/sessions/new.html.erb +28 -13
- data/app/views/revise_auth/shared/_form_block.html.erb +7 -0
- data/app/views/shared/_error_messages.html.erb +18 -0
- data/lib/generators/revise_auth/model_generator.rb +13 -4
- data/lib/generators/revise_auth/templates/README +1 -2
- data/lib/generators/revise_auth/views_generator.rb +6 -0
- data/lib/revise_auth/api_model.rb +46 -0
- data/lib/revise_auth/version.rb +1 -1
- data/lib/revise_auth-jets.rb +1 -0
- metadata +8 -2
@@ -1,71 +1,62 @@
|
|
1
|
-
|
1
|
+
<% content_for :form_block do %>
|
2
|
+
<div class="mb-4 text-center">
|
3
|
+
<h2 class="mb-1">Profile</h2>
|
4
|
+
</div>
|
2
5
|
|
3
|
-
<%= form_with model: current_user, url: profile_email_path do |form| %>
|
4
|
-
<fieldset>
|
5
|
-
<legend>Change Email Address</legend>
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<ul>
|
13
|
-
<% form.object.errors.full_messages.each do |message| %>
|
14
|
-
<li><%= message %></li>
|
15
|
-
<% end %>
|
16
|
-
</ul>
|
17
|
-
<% end %>
|
18
|
-
|
19
|
-
<p>Your email address is: <%= current_user.email %>
|
20
|
-
<p>To change your email, we will send a confirmation email to your new address to complete the change.</p>
|
21
|
-
|
22
|
-
<div>
|
23
|
-
<%= form.label :unconfirmed_email, "Email address" %>
|
24
|
-
<%= form.email_field :unconfirmed_email, required: true %>
|
7
|
+
<%= form_with model: current_user, local: true, url: profile_email_path do |form| %>
|
8
|
+
<%= render "shared/error_messages", resource: current_user %>
|
9
|
+
<div class="form-group">
|
10
|
+
<%= form.label :name, "Full name" %>
|
11
|
+
<%= form.text_field :name, autofocus: true, autocomplete: "name", placeholder: "Steve Jobs", class: "form-control" %>
|
25
12
|
</div>
|
26
13
|
|
27
|
-
<div>
|
28
|
-
<%= form.
|
14
|
+
<div class="form-group">
|
15
|
+
<%= form.label :email %>
|
16
|
+
<%= form.email_field :email, autocomplete: "email", placeholder: "you@example.com", class: "form-control" %>
|
29
17
|
</div>
|
30
|
-
</fieldset>
|
31
|
-
<% end %>
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
<div class="mt-2 form-group">
|
20
|
+
<%= form.button "Update", disable_with: "Saving", class: "btn btn-primary" %>
|
21
|
+
</div>
|
22
|
+
<% end %>
|
36
23
|
|
37
|
-
<% if form.object.errors.any? %>
|
38
|
-
<ul>
|
39
|
-
<% form.object.errors.full_messages.each do |message| %>
|
40
|
-
<li><%= message %></li>
|
41
|
-
<% end %>
|
42
|
-
</ul>
|
43
|
-
<% end %>
|
44
24
|
|
45
|
-
|
25
|
+
<%= form_with model: current_user, local: true, url: profile_password_path do |form| %>
|
26
|
+
<%= render "shared/error_messages", resource: current_user %>
|
27
|
+
<div class="form-group">
|
46
28
|
<%= label_tag :current_password %>
|
47
|
-
<%= password_field_tag :current_password, nil, required: true %>
|
29
|
+
<%= password_field_tag :current_password, nil, required: true, class: "form-control" %>
|
48
30
|
</div>
|
49
31
|
|
50
|
-
<div>
|
32
|
+
<div class="form-group">
|
51
33
|
<%= form.label :password, "New password" %>
|
52
|
-
<%= form.password_field :password, required: true %>
|
34
|
+
<%= form.password_field :password, required: true, class: "form-control" %>
|
53
35
|
</div>
|
54
36
|
|
55
|
-
<div>
|
37
|
+
<div class="form-group">
|
56
38
|
<%= form.label :password_confirmation %>
|
57
|
-
<%= form.password_field :password_confirmation, required: true %>
|
39
|
+
<%= form.password_field :password_confirmation, required: true, class: "form-control" %>
|
58
40
|
</div>
|
59
|
-
|
60
|
-
|
61
|
-
<%= form.button "Save Changes" %>
|
41
|
+
<div class="mt-2 form-group">
|
42
|
+
<%= form.button "Update Password", disable_with: "Saving", class: "btn btn-primary" %>
|
62
43
|
</div>
|
63
|
-
|
64
|
-
|
44
|
+
<% end %>
|
45
|
+
|
46
|
+
<div class="flex flex-wrap flex-end">
|
47
|
+
<div class="flex-1">
|
48
|
+
<h3 class="mb-4">Cancel my account</h3>
|
49
|
+
<div class="mt-2">
|
50
|
+
<%= form_with url: profile_path, local: true, method: :delete do |form| %>
|
51
|
+
<fieldset>
|
52
|
+
<%= form.button "Delete account", class: "btn btn-danger btn-outline primary" %>
|
53
|
+
</fieldset>
|
54
|
+
<% end %>
|
55
|
+
</div>
|
56
|
+
</div>
|
57
|
+
</div>
|
58
|
+
|
59
|
+
|
65
60
|
|
66
|
-
<%= form_with url: profile_path, method: :delete do |form| %>
|
67
|
-
<fieldset>
|
68
|
-
<legend>Delete my account</legend>
|
69
|
-
<%= form.button "Delete account", data: { turbo_confirm: "Are you sure?" } %>
|
70
|
-
</fieldset>
|
71
61
|
<% end %>
|
62
|
+
<%= render "revise_auth/shared/form_block" %>
|
@@ -1,30 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
<ul>
|
6
|
-
<% form.object.errors.full_messages.each do |message| %>
|
7
|
-
<li><%= message %></li>
|
8
|
-
<% end %>
|
9
|
-
</ul>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
<div>
|
13
|
-
<%= form.label :email %>
|
14
|
-
<%= form.email_field :email, required: true, autofocus: true %>
|
1
|
+
<% content_for :form_block do %>
|
2
|
+
<div class="mb-4 text-center">
|
3
|
+
<h2 class="mb-1">Sign Up</h2>
|
4
|
+
<%= link_to "Log in", login_path, class: "font-semibold" %>
|
15
5
|
</div>
|
16
6
|
|
17
|
-
|
18
|
-
<%=
|
19
|
-
<%= form.password_field :password, required: true %>
|
20
|
-
</div>
|
7
|
+
<%= form_with local: true, model: @user, url: sign_up_path do |f| %>
|
8
|
+
<%= render "shared/error_messages", resource: @user %>
|
21
9
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
<div class="form-group">
|
11
|
+
<%= f.label :email %>
|
12
|
+
<%= f.email_field :email, autocomplete: "email", placeholder: true, class: "form-control" %>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<div class="form-group">
|
16
|
+
<%= f.label :password %>
|
17
|
+
<%= f.password_field :password, autocomplete: "new-password", placeholder: true, class: "form-control" %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="form-group">
|
21
|
+
<%= f.label :password_confirmation%>
|
22
|
+
<%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: true, required: true, class: "form-control" %>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
|
26
|
+
<div class="form-group">
|
27
|
+
<%= f.button "Sign Up", disable_with: "Submitting", class: "btn btn-primary btn-expanded" %>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
26
30
|
|
27
|
-
<div>
|
28
|
-
<%= form.button "Sign Up" %>
|
29
|
-
</div>
|
30
31
|
<% end %>
|
32
|
+
|
33
|
+
<%= render "revise_auth/shared/form_block" %>
|
34
|
+
|
@@ -1,17 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
<%= form.label :email %>
|
6
|
-
<%= form.email_field :email, required: true, autofocus: true %>
|
1
|
+
<% content_for :form_block do %>
|
2
|
+
<div class="mb-4 text-center">
|
3
|
+
<h2 class="mb-px">Log In</h2>
|
4
|
+
<%= link_to "Sign Up", sign_up_path, class: "font-semibold" %>
|
7
5
|
</div>
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
<%= form_with(url: login_path, local: true) do |f| %>
|
8
|
+
<div class="form-group">
|
9
|
+
<%= f.label :email %>
|
10
|
+
<%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: true, class: "form-control" %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="form-group">
|
14
|
+
<%= f.label :password %>
|
15
|
+
<%= f.password_field :password, autocomplete: "current-password", placeholder: true, class: "form-control" %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="form-group">
|
19
|
+
<%= f.check_box :remember_me, class: "form-checkbox" %>
|
20
|
+
<%= f.label :remember_me, class: "inline-block" %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="form-group">
|
24
|
+
<%= f.submit "SIgn In", class: "btn btn-primary btn-expanded" %>
|
25
|
+
</div>
|
26
|
+
<% end %>
|
13
27
|
|
14
|
-
<div>
|
15
|
-
<%= form.button "Login" %>
|
16
|
-
</div>
|
17
28
|
<% end %>
|
29
|
+
|
30
|
+
<%= render "revise_auth/shared/form_block" %>
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% if resource.errors.any? %>
|
2
|
+
<div class="alert alert-error mb-6 bg-red-500 text-white dark:bg-red-700 dark:text-red-200" role="alert">
|
3
|
+
<div class="flex items-start justify-start">
|
4
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" class="fill-current icon mr-4 mt-1 flex-no-shrink text-white dark:text-red-200" role="img" aria-labelledby="f1yx75u7nv0lvn6ck4z10w7lksjmk2f">
|
5
|
+
<title id="f1yx75u7nv0lvn6ck4z10w7lksjmk2f">Icons/close outline</title>
|
6
|
+
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm1.41-1.41A8 8 0 1 0 15.66 4.34 8 8 0 0 0 4.34 15.66zm9.9-8.49L11.41 10l2.83 2.83-1.41 1.41L10 11.41l-2.83 2.83-1.41-1.41L8.59 10 5.76 7.17l1.41-1.41L10 8.59l2.83-2.83 1.41 1.41z"></path>
|
7
|
+
</svg>
|
8
|
+
|
9
|
+
<div>
|
10
|
+
<ul class="dark:text-red-200">
|
11
|
+
<% resource.errors.full_messages.each do |message| %>
|
12
|
+
<li><%= message %></li>
|
13
|
+
<% end %>
|
14
|
+
</ul>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
@@ -11,20 +11,26 @@ module ReviseAuth
|
|
11
11
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
12
12
|
|
13
13
|
def initialize(args, *options)
|
14
|
-
@original_attributes = args[1..] || []
|
15
14
|
super
|
16
15
|
end
|
17
16
|
|
18
17
|
def generate_model
|
19
|
-
model_attributess = model_attributes.join(', ').gsub('
|
18
|
+
model_attributess = model_attributes.join(', ').gsub(',', '')
|
19
|
+
puts "Adding #{name}"
|
20
20
|
puts "jets g model #{name} #{model_attributess}"
|
21
21
|
system "jets g model #{name} #{model_attributess}"
|
22
|
+
puts "Adding ApiToken"
|
23
|
+
system "jets g model ApiTokens #{name.downcase}:references token:string:uniq name:string metadata:jsonb transient:boolean last_used_at:datetime expires_at:datetime"
|
22
24
|
#generate :model, name, *model_attributes
|
23
25
|
end
|
24
26
|
|
25
27
|
def add_revise_auth_model
|
28
|
+
prepend_to_file "app/models/api_token.rb", "require 'revise_auth-jets'\n"
|
29
|
+
inject_into_class "app/models/api_token.rb", "ApiToken", " include ReviseAuth::ApiModel\n"
|
30
|
+
|
26
31
|
prepend_to_file model_path, "require 'revise_auth-jets'\n"
|
27
32
|
inject_into_class model_path, class_name, " include ReviseAuth::Model\n"
|
33
|
+
inject_into_class model_path, class_name, " has_many :api_tokens, dependent: :destroy\n"
|
28
34
|
end
|
29
35
|
|
30
36
|
def add_uniq_to_email_index
|
@@ -51,13 +57,16 @@ module ReviseAuth
|
|
51
57
|
|
52
58
|
def model_attributes
|
53
59
|
[
|
54
|
-
"email:string:
|
60
|
+
"email:string:uniq",
|
55
61
|
"password_digest:string",
|
62
|
+
"first_name:string",
|
63
|
+
"last_name:string",
|
64
|
+
"admin:boolean",
|
56
65
|
"confirmation_token:string",
|
57
66
|
"confirmed_at:datetime",
|
58
67
|
"confirmation_sent_at:datetime",
|
59
68
|
"unconfirmed_email:string"
|
60
|
-
]
|
69
|
+
]
|
61
70
|
end
|
62
71
|
end
|
63
72
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
🚚 Your Revise auth database model has been generated!
|
2
2
|
|
3
3
|
Next step:
|
4
|
-
Add
|
4
|
+
Add t.jsonb :metadata, default: {} and t.boolean :transient, default: false into your ApiToken migration
|
5
5
|
Run "jets db:migrate"
|
6
|
-
Add ActiveRecord::Base.signed_id_verifier_secret = "custom_verfifier_secret" in your initializers/ Set this as an env var
|
7
6
|
Add your stmp settings in your development.rb
|
8
7
|
Run "jets g revise_auth:views"
|
@@ -11,6 +11,10 @@ module ReviseAuth
|
|
11
11
|
template "app/config/routes.rb", "config/routes.rb"
|
12
12
|
end
|
13
13
|
|
14
|
+
def copy_styles
|
15
|
+
template "app/stylesheet/theme.scss", "app/javascript/packs/theme.scss"
|
16
|
+
end
|
17
|
+
|
14
18
|
def copy_controllers
|
15
19
|
template "app/controllers/main_controller.rb", "app/controllers/main_controller.rb"
|
16
20
|
template "app/controllers/revise_auth_controller.rb", "app/controllers/revise_auth_controller.rb"
|
@@ -20,6 +24,7 @@ module ReviseAuth
|
|
20
24
|
end
|
21
25
|
else
|
22
26
|
directory "app/controllers/revise_auth"
|
27
|
+
directory "app/controllers/api"
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -31,6 +36,7 @@ module ReviseAuth
|
|
31
36
|
else
|
32
37
|
directory "app/views/revise_auth"
|
33
38
|
directory "app/views/main"
|
39
|
+
directory "app/views/shared"
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ReviseAuth
|
2
|
+
module ApiModel
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
DEFAULT_NAME = "api_token"
|
7
|
+
APP_NAME = "my_app"
|
8
|
+
|
9
|
+
belongs_to :user
|
10
|
+
|
11
|
+
scope :sorted, -> { order("last_used_at DESC NULLS LAST, created_at DESC") }
|
12
|
+
|
13
|
+
has_secure_token :token
|
14
|
+
|
15
|
+
validates :name, presence: true
|
16
|
+
|
17
|
+
def can?(permission)
|
18
|
+
Array.wrap(data("permissions")).include?(permission)
|
19
|
+
end
|
20
|
+
|
21
|
+
def cant?(permission)
|
22
|
+
!can?(permission)
|
23
|
+
end
|
24
|
+
|
25
|
+
def data(key, default: nil)
|
26
|
+
(metadata || {}).fetch(key, default)
|
27
|
+
end
|
28
|
+
|
29
|
+
def expired?
|
30
|
+
expires_at? && Time.current >= expires_at
|
31
|
+
end
|
32
|
+
|
33
|
+
def touch_last_used_at
|
34
|
+
return if transient?
|
35
|
+
update(last_used_at: Time.current)
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_token
|
39
|
+
loop do
|
40
|
+
self.token = SecureRandom.hex(16)
|
41
|
+
break unless ApiToken.where(token: token).exists?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/revise_auth/version.rb
CHANGED
data/lib/revise_auth-jets.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revise_auth-jets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremiah Parrack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -35,6 +35,8 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
37
|
- app/config/routes.rb
|
38
|
+
- app/controllers/api/base_controller.rb
|
39
|
+
- app/controllers/api/v1/mes_controller.rb
|
38
40
|
- app/controllers/main_controller.rb
|
39
41
|
- app/controllers/revise_auth/email_controller.rb
|
40
42
|
- app/controllers/revise_auth/password_controller.rb
|
@@ -42,12 +44,15 @@ files:
|
|
42
44
|
- app/controllers/revise_auth/sessions_controller.rb
|
43
45
|
- app/controllers/revise_auth_controller.rb
|
44
46
|
- app/mailers/revise_auth/mailer.rb
|
47
|
+
- app/stylesheet/theme.scss
|
45
48
|
- app/views/main/authenticated.html.erb
|
46
49
|
- app/views/main/index.html.erb
|
47
50
|
- app/views/revise_auth/mailer/confirm_email.html.erb
|
48
51
|
- app/views/revise_auth/registrations/edit.html.erb
|
49
52
|
- app/views/revise_auth/registrations/new.html.erb
|
50
53
|
- app/views/revise_auth/sessions/new.html.erb
|
54
|
+
- app/views/revise_auth/shared/_form_block.html.erb
|
55
|
+
- app/views/shared/_error_messages.html.erb
|
51
56
|
- config/locales/de.yml
|
52
57
|
- config/locales/el.yml
|
53
58
|
- config/locales/en.yml
|
@@ -59,6 +64,7 @@ files:
|
|
59
64
|
- lib/generators/revise_auth/templates/README
|
60
65
|
- lib/generators/revise_auth/views_generator.rb
|
61
66
|
- lib/revise_auth-jets.rb
|
67
|
+
- lib/revise_auth/api_model.rb
|
62
68
|
- lib/revise_auth/authentication.rb
|
63
69
|
- lib/revise_auth/backports.rb
|
64
70
|
- lib/revise_auth/current.rb
|