authentication-zero 0.0.1 → 0.0.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: edcfb4270bbf35bdd9a0eeee95e9cc939d4e0254dea271d6fcdf3114b9c69c78
4
- data.tar.gz: e7c715c92ab3fd57f209c7a4db1e14f76b65551098c2e65207184d45457b85fa
3
+ metadata.gz: fbbdce3e39368908b25db1e2b98b1c6f7d8211c43099270f87e2d5905307033e
4
+ data.tar.gz: be7a32894d05d9796a3baa46a6cf0907e3d0dc4808687c6238e8cda262c5edd3
5
5
  SHA512:
6
- metadata.gz: c397a19049d0c44bef77ee1afe15966a3c51f3c53c5480e937dba4579ffd28f6eff178b54f2273aa32839a3d5ee4cc55f6bc8ca625e02ded7eec989af6be324f
7
- data.tar.gz: 6480cdc0b5f82da1d38c342fd27af1ab3948dbf67cb20d415123cdacaebdd6a4e1f338768f401566d9f8b1082eeb19cc28475578264e44a1136af95cc7aa2c1d
6
+ metadata.gz: e5db73d7da96f46cb79e4b2ea51fbd6d4698436ed234e50f535a7ad02b28f1cedbf1768d1b67d032ac070ac7bdec0ea7ab309141b9593a034497421f335f65b4
7
+ data.tar.gz: 840de055d1877b02c0e52af876730bf5c1a87aafe99faf956f34e26736ecf0aa39907d86071b4956844e062f4a8f413ad83d4d4b30e773b5a5f111ff18729be1
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ authentication-zero (0.0.5)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (12.3.3)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ authentication-zero!
16
+ rake (~> 12.0)
17
+
18
+ BUNDLED WITH
19
+ 2.1.4
data/README.md CHANGED
@@ -4,10 +4,47 @@ The purpose of authentication zero is to generate a pre-built authentication sys
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this lines to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'authentication-zero'
10
+ gem "bcrypt"
11
+ gem "authentication-zero"
12
+ ```
13
+
14
+ Then run `bundle install`
15
+
16
+ You'll need to set the root path in your routes.rb, for this example let's use the following:
17
+
18
+ ```ruby
19
+ root "home#index"
20
+ ```
21
+
22
+ ```
23
+ $ rails generate controller home index
24
+ ```
25
+
26
+ Add these lines to your `app/views/home/index.html.erb`:
27
+
28
+ ```html+erb
29
+ <p style="color: green"><%= notice %></p>
30
+
31
+ <p>Signed as <%= Current.user.email %></p>
32
+
33
+ <div>
34
+ <%= link_to "Change password", password_edit_path %>
35
+ </div>
36
+
37
+ <div>
38
+ <%= link_to "Cancel my account & delete my data", cancellation_new_path %>
39
+ </div>
40
+
41
+ <%= button_to "Log out", sign_out_path, method: :delete %>
42
+ ```
43
+
44
+ And you'll need to set up the default URL options for the mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
45
+
46
+ ```ruby
47
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
11
48
  ```
12
49
 
13
50
  ## Usage
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -5,10 +5,6 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
5
5
 
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
- def uncomment_bcrypt
9
- uncomment_lines 'Gemfile', /bcrypt/
10
- end
11
-
12
8
  def create_controllers
13
9
  directory "controllers/html", "app/controllers"
14
10
  end
@@ -47,17 +43,17 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
47
43
  end
48
44
 
49
45
  def add_application_controller_methods
50
- inject_into_class "app/controllers/application_controller.rb", "ApplicationController", verbose: false do <<~CODE
51
- before_action :authenticate
52
-
53
- private
54
- def authenticate
55
- if #{singular_table_name} = cookies[:session_token] && #{class_name}.find_by_session_token(cookies[:session_token])
56
- Current.user = #{singular_table_name}
57
- else
58
- redirect_to sign_in_path, alert: "You need to sign in or sign up before continuing"
59
- end
60
- end
46
+ inject_into_class "app/controllers/application_controller.rb", "ApplicationController", verbose: false do <<-CODE
47
+ before_action :authenticate
48
+
49
+ private
50
+ def authenticate
51
+ if #{singular_table_name} = cookies[:session_token] && #{class_name}.find_by_session_token(cookies[:session_token])
52
+ Current.user = #{singular_table_name}
53
+ else
54
+ redirect_to sign_in_path, alert: "You need to sign in or sign up before continuing"
55
+ end
56
+ end
61
57
  CODE
62
58
  end
63
59
  end
@@ -10,7 +10,7 @@ class PasswordResetsController < ApplicationController
10
10
 
11
11
  def create
12
12
  if @<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
13
- PasswordMailer.with(to: @<%= singular_table_name %>).reset.deliver_later
13
+ PasswordMailer.with(<%= singular_table_name %>: @<%= singular_table_name %>).reset.deliver_later
14
14
  redirect_to sign_in_path, notice: "You will receive an email with instructions on how to reset your password in a few minutes"
15
15
  else
16
16
  redirect_to password_reset_new_path, alert: "The email address doesn't exist in our database"
@@ -1,12 +1,14 @@
1
1
  class PasswordsController < ApplicationController
2
+ before_action :set_<%= singular_table_name %>
3
+
2
4
  def edit
3
5
  @<%= singular_table_name %> = Current.<%= singular_table_name %>
4
6
  end
5
7
 
6
8
  def update
7
- if !Current.<%= singular_table_name %>.authenticate(params[:current_password])
9
+ if !@<%= singular_table_name %>.authenticate(params[:current_password])
8
10
  redirect_to password_edit_path, alert: "The current password you entered is incorrect"
9
- elsif Current.<%= singular_table_name %>.update(password_params)
11
+ elsif @<%= singular_table_name %>.update(password_params)
10
12
  redirect_to root_path, notice: "Your password has been changed successfully"
11
13
  else
12
14
  render :edit, status: :unprocessable_entity
@@ -14,6 +16,10 @@ class PasswordsController < ApplicationController
14
16
  end
15
17
 
16
18
  private
19
+ def set_<%= singular_table_name %>
20
+ @<%= singular_table_name %> = Current.<%= singular_table_name %>
21
+ end
22
+
17
23
  def password_params
18
24
  params.require(:<%= singular_table_name %>).permit(:password, :password_confirmation)
19
25
  end
@@ -4,7 +4,7 @@ class <%= class_name %> < ApplicationRecord
4
4
 
5
5
  validates :email, presence: true, uniqueness: true
6
6
  validates :email, format: { with: /\A[^@\s]+@[^@\s]+\z/ }
7
- validates :password, length: 8..70, allow_blank: true
7
+ validates_length_of :password, minimum: 8, allow_blank: true
8
8
 
9
9
  before_validation { self.email = email.downcase.strip }
10
10
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  <p>Your account will be immediately closed. You won’t be able to sign in anymore.</p>
4
4
  <p>Your data will be permanently deleted from our servers.</p>
5
- <p><%%= link_to "Back", :back %></p>
5
+ <p><%%= link_to "Back", root_path %></p>
6
6
 
7
7
  <br>
8
8
 
@@ -14,7 +14,7 @@
14
14
  <%% end %>
15
15
 
16
16
  <div>
17
- <%%= form.label :password, "New password (6 characters minimum)", style: "display: block" %>
17
+ <%%= form.label :password, "New password (8 characters minimum)", style: "display: block" %>
18
18
  <%%= form.password_field :password, autofocus: true, autocomplete: "new-password" %>
19
19
  </div>
20
20
 
@@ -8,7 +8,7 @@
8
8
  <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
9
9
 
10
10
  <ul>
11
- <%% @<%%= singular_table_name %>.errors.each do |error| %>
11
+ <%% @<%= singular_table_name %>.errors.each do |error| %>
12
12
  <li><%%= error.full_message %></li>
13
13
  <%% end %>
14
14
  </ul>
@@ -17,11 +17,11 @@
17
17
 
18
18
  <div>
19
19
  <%%= label_tag :current_password, nil, style: "display: block" %>
20
- <%%= password_field_tag :current_password, autofocus: true, autocomplete: "current-password" %>
20
+ <%%= password_field_tag :current_password, nil, autofocus: true, autocomplete: "current-password" %>
21
21
  </div>
22
22
 
23
23
  <div>
24
- <%%= form.label :password, "New password (6 characters minimum)", style: "display: block" %>
24
+ <%%= form.label :password, "New password (8 characters minimum)", style: "display: block" %>
25
25
  <%%= form.password_field :password, autocomplete: "new-password" %>
26
26
  </div>
27
27
 
@@ -38,5 +38,5 @@
38
38
  <br>
39
39
 
40
40
  <div>
41
- <%%= link_to "Back", :back %>
41
+ <%%= link_to "Back", root_path %>
42
42
  </div>
@@ -19,7 +19,7 @@
19
19
  </div>
20
20
 
21
21
  <div>
22
- <%%= form.label :password, "Password (6 characters minimum)", style: "display: block" %>
22
+ <%%= form.label :password, "Password (8 characters minimum)", style: "display: block" %>
23
23
  <%%= form.password_field :password, autocomplete: "new-password" %>
24
24
  </div>
25
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-14 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -21,6 +21,7 @@ files:
21
21
  - CHANGELOG.md
22
22
  - CODE_OF_CONDUCT.md
23
23
  - Gemfile
24
+ - Gemfile.lock
24
25
  - LICENSE.txt
25
26
  - README.md
26
27
  - Rakefile