avocado 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b2bf2a8946882c7f2c799f8f545f34d3d34c6d3a64a932258350e57b32fdabe
4
- data.tar.gz: 0f2430fff76f6912de3b1f09d08ab9b12858fa245e278e5542341eddfe116314
3
+ metadata.gz: '04228885896e7d922d727e6497a22a933f3910c96afad40b69bd21d209ab4a3c'
4
+ data.tar.gz: 8a71cb118b5d97513f506d44ee5b2e01a0af5747d9e8151c9d866a589565d660
5
5
  SHA512:
6
- metadata.gz: 547b8e2c1e35508a75828c4f735b021c1022fe6e9e70f4a41c33dbb2d823592ff86d65732475c72fb3ee5cac0a3bed3f74c1fc12521b4344cc743313b6ed922c
7
- data.tar.gz: 016be93303ef00a75c3e7a63e2a1d030f2955eb7eaf92d80ab03fed4704da6fecc5b194d6a73e567e524087063dd2b1e947799fd5f0f338eba20a6f25f585831
6
+ metadata.gz: 6ff80323ec0979cbfecaa008f7cca93a73c7e2e82df4ac5590caae93de5b3b903c9fc724ab8508c50d70299d118df94718d6c22d00b0f990798a0a3544091a7f
7
+ data.tar.gz: d39393b42cfc22511acecaceacce2dc345a65a1500fe3071c7b69f11876f479eb48d9d03beee052a0518b485da2ded599b6fe919454df7bb547a4e2d3ac67664
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-07-17
4
+
5
+ - Add an `Avocado::Mailer` which generates each of the signed ids
6
+ - Rename `password_recovery` to `password_reset`
7
+
3
8
  ## [0.2.0] - 2023-07-15
4
9
 
5
10
  - Validate presence, uniqueness, and format on `email` attribute
data/README.md CHANGED
@@ -29,11 +29,18 @@ This will do a few things behind the scenes:
29
29
  - Use the built-in `has_secure_password` to generate relevant password methods
30
30
  - Add some basic validations for the `email` and `password` fields on `User`
31
31
  - Normalize email values when records are saved
32
- - Provide a token generator for password recovery
32
+ - Provide signed token generators for `password_reset`, `email_verification`,
33
+ and `email_affirmation`
33
34
 
34
35
  It's sort of funny to do this because you genuinely just could have put this
35
36
  stuff right in your app, and yet here we are making gems instead!
36
37
 
38
+ There is an `Avocado::Mailer` which can be included in a mailer class and
39
+ provides some basic mailers.
40
+
41
+ The `spec/internal` app within this repo has some example usage of both model
42
+ and mailer.
43
+
37
44
  ## Development
38
45
 
39
46
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Avocado
6
+ module Mailer
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ before_action :set_user
11
+ before_action :set_signed_id
12
+
13
+ default to: -> { @user.email }
14
+ end
15
+
16
+ def email_affirmation
17
+ mail
18
+ end
19
+
20
+ def email_verification
21
+ mail
22
+ end
23
+
24
+ def password_reset
25
+ mail
26
+ end
27
+
28
+ private
29
+
30
+ def set_user
31
+ @user = params[:user]
32
+ end
33
+
34
+ def set_signed_id
35
+ @signed_id = @user.generate_token_for(action_name.to_sym)
36
+ end
37
+ end
38
+ end
data/lib/avocado/user.rb CHANGED
@@ -7,8 +7,11 @@ module Avocado
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- include UserEmailConcern
11
- include UserPasswordConcern
10
+ include UserEmail
11
+ include UserEmailAffirmation
12
+ include UserEmailVerification
13
+ include UserPassword
14
+ include UserPasswordReset
12
15
  end
13
16
  end
14
17
  end
@@ -3,7 +3,7 @@
3
3
  require "active_support/concern"
4
4
 
5
5
  module Avocado
6
- module UserEmailConcern
6
+ module UserEmail
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Avocado
6
+ module UserEmailAffirmation
7
+ extend ActiveSupport::Concern
8
+
9
+ TOKEN_EXPIRATION = 16.minutes
10
+
11
+ included do
12
+ generates_token_for :email_affirmation, expires_in: TOKEN_EXPIRATION
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Avocado
6
+ module UserEmailVerification
7
+ extend ActiveSupport::Concern
8
+
9
+ TOKEN_EXPIRATION = 2_048.minutes
10
+
11
+ included do
12
+ generates_token_for :email_verification, expires_in: TOKEN_EXPIRATION do
13
+ email
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,27 +3,16 @@
3
3
  require "active_support/concern"
4
4
 
5
5
  module Avocado
6
- module UserPasswordConcern
6
+ module UserPassword
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  REQUIRED_FORMAT = /\A(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*\z/x
10
10
  REQUIRED_LENGTH = 8
11
- TOKEN_EXPIRATION = 64.minutes
12
11
 
13
12
  included do
14
13
  has_secure_password
15
14
 
16
15
  validates :password, format: {with: REQUIRED_FORMAT}, length: {minimum: REQUIRED_LENGTH}, allow_nil: true
17
-
18
- generates_token_for :password_recovery, expires_in: TOKEN_EXPIRATION do
19
- password_digest_salt
20
- end
21
- end
22
-
23
- private
24
-
25
- def password_digest_salt
26
- BCrypt::Password.new(password_digest).salt[-10..]
27
16
  end
28
17
  end
29
18
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Avocado
6
+ module UserPasswordReset
7
+ extend ActiveSupport::Concern
8
+
9
+ TOKEN_EXPIRATION = 64.minutes
10
+
11
+ included do
12
+ generates_token_for :password_reset, expires_in: TOKEN_EXPIRATION do
13
+ password_digest_salt
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def password_digest_salt
20
+ password_from_digest.salt[-10..]
21
+ end
22
+
23
+ def password_from_digest
24
+ BCrypt::Password.new(password_digest)
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avocado
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/avocado.rb CHANGED
@@ -5,7 +5,11 @@ require_relative "avocado/version"
5
5
  module Avocado
6
6
  class Error < StandardError; end
7
7
 
8
+ autoload :Mailer, "avocado/mailer"
8
9
  autoload :User, "avocado/user"
9
- autoload :UserEmailConcern, "avocado/user_email_concern"
10
- autoload :UserPasswordConcern, "avocado/user_password_concern"
10
+ autoload :UserEmail, "avocado/user_email"
11
+ autoload :UserEmailAffirmation, "avocado/user_email_affirmation"
12
+ autoload :UserEmailVerification, "avocado/user_email_verification"
13
+ autoload :UserPassword, "avocado/user_password"
14
+ autoload :UserPasswordReset, "avocado/user_password_reset"
11
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avocado
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Jankowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-15 00:00:00.000000000 Z
11
+ date: 2023-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -82,9 +82,13 @@ files:
82
82
  - Rakefile
83
83
  - config.ru
84
84
  - lib/avocado.rb
85
+ - lib/avocado/mailer.rb
85
86
  - lib/avocado/user.rb
86
- - lib/avocado/user_email_concern.rb
87
- - lib/avocado/user_password_concern.rb
87
+ - lib/avocado/user_email.rb
88
+ - lib/avocado/user_email_affirmation.rb
89
+ - lib/avocado/user_email_verification.rb
90
+ - lib/avocado/user_password.rb
91
+ - lib/avocado/user_password_reset.rb
88
92
  - lib/avocado/version.rb
89
93
  - sig/avocado.rbs
90
94
  homepage: https://github.com/unicorngroomers/avocado