active_registration 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +95 -0
- data/Rakefile +8 -0
- data/lib/active_registration/engine.rb +4 -0
- data/lib/active_registration/user_extensions.rb +29 -0
- data/lib/active_registration/version.rb +3 -0
- data/lib/active_registration.rb +6 -0
- data/lib/generators/active_registration/install_generator.rb +48 -0
- data/lib/generators/active_registration/templates/add_active_registration_fields_to_users.rb +8 -0
- data/lib/generators/active_registration/templates/confirmation_mailer.rb +7 -0
- data/lib/generators/active_registration/templates/registrations_controller.rb +32 -0
- data/lib/generators/active_registration/templates/views/confirmation_mailer/confirmation_instructions.html.erb +4 -0
- data/lib/generators/active_registration/templates/views/registrations/new.html.erb +6 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 577eb04e3f980142f6288405a0115dd072b9e675810d429cb637f40192053067
|
4
|
+
data.tar.gz: 02d8d1944363101ac074fba10c5f4907b045c7c09e18ac480f4684c920acb752
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1faec3f65120b8f199c864bd8f39187f36c66e4ca3e90ce5d4909afe6c6ca9e6ae84ae853347b99d6dcdfdf7cdbbe33d287348c79f148468f44fa6099a13190d
|
7
|
+
data.tar.gz: 74af47d7e060a06eae18e68ced4c2b206d12f7bfaf760455aa8e71161ec49d64a8da345ab64cdcab32973294747034e500d99d996faaae2cb016ab74d9911850
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Salanoid
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# ActiveRegistration
|
2
|
+
|
3
|
+
A drop-in Rails engine that adds secure user registration with email confirmation to your rails 8+ application, that uses Rails Authentication Generator.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- 🚀 Registration flow (sign up, email confirmation)
|
8
|
+
- 📧 Email confirmation with token expiration
|
9
|
+
- 🧩 Easy integration with existing User models (from Rails Autehntication Generator)
|
10
|
+
- 🎨 Generated views for customization
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "active_registration"
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
gem install active_registration
|
30
|
+
```
|
31
|
+
|
32
|
+
Run the installation generator:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
rails generate active_registration:install
|
36
|
+
```
|
37
|
+
|
38
|
+
Apply database migrations:
|
39
|
+
```bash
|
40
|
+
rails db:migrate
|
41
|
+
```
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
### Development Environment
|
45
|
+
|
46
|
+
Add `letter_opener` to preview emails:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# Gemfile
|
50
|
+
gem 'letter_opener', group: :development
|
51
|
+
```
|
52
|
+
|
53
|
+
Configure mailer settings:
|
54
|
+
```ruby
|
55
|
+
# config/environments/development.rb
|
56
|
+
Rails.application.configure do
|
57
|
+
config.action_mailer.delivery_method = :letter_opener
|
58
|
+
config.action_mailer.default_url_options = {
|
59
|
+
host: 'localhost',
|
60
|
+
port: 3000
|
61
|
+
}
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
### Production Environment
|
66
|
+
|
67
|
+
Configure your SMTP settings:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# config/environments/production.rb
|
71
|
+
config.action_mailer.delivery_method = :smtp
|
72
|
+
config.action_mailer.smtp_settings = {
|
73
|
+
address: 'smtp.yourprovider.com',
|
74
|
+
port: 587,
|
75
|
+
user_name: ENV['SMTP_USER'],
|
76
|
+
password: ENV['SMTP_PASSWORD'],
|
77
|
+
authentication: :plain,
|
78
|
+
enable_starttls_auto: true
|
79
|
+
}
|
80
|
+
```
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
Fork the project
|
84
|
+
|
85
|
+
Create your feature branch (git checkout -b feature/amazing-feature)
|
86
|
+
|
87
|
+
Commit your changes (git commit -m 'Add some amazing feature')
|
88
|
+
|
89
|
+
Push to the branch (git push origin feature/amazing-feature)
|
90
|
+
|
91
|
+
Open a Pull Request
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActiveRegistration
|
2
|
+
module UserExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
validates :email_address, presence: true, uniqueness: true
|
7
|
+
before_create :generate_confirmation_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def confirm!
|
11
|
+
update(confirmed_at: Time.current, confirmation_token: nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def confirmed?
|
15
|
+
confirmed_at.present?
|
16
|
+
end
|
17
|
+
|
18
|
+
def confirmation_period_valid?
|
19
|
+
confirmation_sent_at >= 24.hours.ago
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def generate_confirmation_token
|
25
|
+
self.confirmation_token = SecureRandom.urlsafe_base64
|
26
|
+
self.confirmation_sent_at = Time.current
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ActiveRegistration
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
include Rails::Generators::Migration
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def self.next_migration_number(dirname)
|
7
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_migration
|
11
|
+
migration_template "add_active_registration_fields_to_users.rb", "db/migrate/add_active_registration_fields_to_users.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_controller
|
15
|
+
copy_file "registrations_controller.rb", "app/controllers/registrations_controller.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_views
|
19
|
+
directory "views/registrations", "app/views/registrations"
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_routes
|
23
|
+
# TODO implement edit and update in the future
|
24
|
+
# resource :registration, only: [:new, :create, :edit, :update] do
|
25
|
+
route <<~ROUTE
|
26
|
+
resource :registration, only: [:new, :create] do
|
27
|
+
get :confirm, on: :collection
|
28
|
+
end
|
29
|
+
ROUTE
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_mailer
|
33
|
+
copy_file "confirmation_mailer.rb", "app/mailers/confirmation_mailer.rb"
|
34
|
+
directory "views/confirmation_mailer", "app/views/confirmation_mailer"
|
35
|
+
end
|
36
|
+
|
37
|
+
def inject_user_extension
|
38
|
+
user_model_path = "app/models/user.rb"
|
39
|
+
return unless File.exist?(user_model_path)
|
40
|
+
|
41
|
+
inject_into_file user_model_path, after: "class User < ApplicationRecord\n" do
|
42
|
+
" include ActiveRegistration::UserExtensions\n"
|
43
|
+
end
|
44
|
+
rescue Errno::ENOENT
|
45
|
+
say "User model not found. Add 'include ActiveRegistration::UserExtensions' to your User model.", :yellow
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddActiveRegistrationFieldsToUsers < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
add_column :users, :confirmation_token, :string
|
4
|
+
add_column :users, :confirmed_at, :datetime
|
5
|
+
add_column :users, :confirmation_sent_at, :datetime
|
6
|
+
add_index :users, :confirmation_token, unique: true
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class RegistrationsController < ApplicationController
|
2
|
+
def new
|
3
|
+
@user = User.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def create
|
7
|
+
@user = User.new(user_params)
|
8
|
+
if @user.save
|
9
|
+
ConfirmationMailer.confirmation_instructions(@user).deliver_later
|
10
|
+
redirect_to root_path, notice: "Confirmation email sent!"
|
11
|
+
else
|
12
|
+
render :new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def confirm
|
17
|
+
@user = User.find_by(confirmation_token: params[:token])
|
18
|
+
|
19
|
+
if @user&.confirmation_period_valid?
|
20
|
+
@user.confirm!
|
21
|
+
redirect_to root_path, notice: "Email confirmed!"
|
22
|
+
else
|
23
|
+
redirect_to root_path, alert: "Invalid or expired confirmation link"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def user_params
|
30
|
+
params.require(:user).permit(:email_address, :password, :password_confirmation)
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_registration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Salanoid
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rails
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '8.0'
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 8.0.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '8.0'
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 8.0.2
|
32
|
+
description: "A drop-in Rails engine that adds secure user registration with email
|
33
|
+
confirmation to your rails 8+ application, that uses Rails Authentication Generator.\n\n"
|
34
|
+
email:
|
35
|
+
- salanoid@gmail.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- MIT-LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/active_registration.rb
|
44
|
+
- lib/active_registration/engine.rb
|
45
|
+
- lib/active_registration/user_extensions.rb
|
46
|
+
- lib/active_registration/version.rb
|
47
|
+
- lib/generators/active_registration/install_generator.rb
|
48
|
+
- lib/generators/active_registration/templates/add_active_registration_fields_to_users.rb
|
49
|
+
- lib/generators/active_registration/templates/confirmation_mailer.rb
|
50
|
+
- lib/generators/active_registration/templates/registrations_controller.rb
|
51
|
+
- lib/generators/active_registration/templates/views/confirmation_mailer/confirmation_instructions.html.erb
|
52
|
+
- lib/generators/active_registration/templates/views/registrations/new.html.erb
|
53
|
+
homepage: https://rubygems.org/gems/active_registration
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata:
|
57
|
+
allowed_push_host: https://rubygems.org/
|
58
|
+
homepage_uri: https://rubygems.org/gems/active_registration
|
59
|
+
source_code_uri: https://github.com/Salanoid/active_registration
|
60
|
+
changelog_uri: https://github.com/Salanoid/active_registration/blob/main/CHANGELOG.md
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.6.7
|
76
|
+
specification_version: 4
|
77
|
+
summary: A simple gem that adds generators for sign up Rails Authentication Generator.
|
78
|
+
test_files: []
|