Skip to content

Commit b37e07a

Browse files
committed
v0.1.1 Basic Authentication Solution
- Added ability to sign up - Added ability to sign in - Added ability to sign out - Added ability to reset password - Added ability to verify email address
1 parent 7e7ae61 commit b37e07a

File tree

109 files changed

+1032
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1032
-14
lines changed

.github/workflows/test.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Ruby
23+
uses: ruby/setup-ruby@v1.146.0
24+
with:
25+
ruby-version: ${{ matrix.ruby-version }}
26+
bundler-cache: true
27+
- name: Run tests
28+
run: bundle exec rails test

.gitignore

100644100755
File mode changed.

Gemfile

100644100755
File mode changed.

Gemfile.lock

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
PATH
2+
remote: .
3+
specs:
4+
action_auth (0.1.0)
5+
bcrypt (~> 3.1.0)
6+
rails (~> 7.1)
7+
8+
GEM
9+
remote: https://rubygems.org/
10+
specs:
11+
actioncable (7.1.1)
12+
actionpack (= 7.1.1)
13+
activesupport (= 7.1.1)
14+
nio4r (~> 2.0)
15+
websocket-driver (>= 0.6.1)
16+
zeitwerk (~> 2.6)
17+
actionmailbox (7.1.1)
18+
actionpack (= 7.1.1)
19+
activejob (= 7.1.1)
20+
activerecord (= 7.1.1)
21+
activestorage (= 7.1.1)
22+
activesupport (= 7.1.1)
23+
mail (>= 2.7.1)
24+
net-imap
25+
net-pop
26+
net-smtp
27+
actionmailer (7.1.1)
28+
actionpack (= 7.1.1)
29+
actionview (= 7.1.1)
30+
activejob (= 7.1.1)
31+
activesupport (= 7.1.1)
32+
mail (~> 2.5, >= 2.5.4)
33+
net-imap
34+
net-pop
35+
net-smtp
36+
rails-dom-testing (~> 2.2)
37+
actionpack (7.1.1)
38+
actionview (= 7.1.1)
39+
activesupport (= 7.1.1)
40+
nokogiri (>= 1.8.5)
41+
rack (>= 2.2.4)
42+
rack-session (>= 1.0.1)
43+
rack-test (>= 0.6.3)
44+
rails-dom-testing (~> 2.2)
45+
rails-html-sanitizer (~> 1.6)
46+
actiontext (7.1.1)
47+
actionpack (= 7.1.1)
48+
activerecord (= 7.1.1)
49+
activestorage (= 7.1.1)
50+
activesupport (= 7.1.1)
51+
globalid (>= 0.6.0)
52+
nokogiri (>= 1.8.5)
53+
actionview (7.1.1)
54+
activesupport (= 7.1.1)
55+
builder (~> 3.1)
56+
erubi (~> 1.11)
57+
rails-dom-testing (~> 2.2)
58+
rails-html-sanitizer (~> 1.6)
59+
activejob (7.1.1)
60+
activesupport (= 7.1.1)
61+
globalid (>= 0.3.6)
62+
activemodel (7.1.1)
63+
activesupport (= 7.1.1)
64+
activerecord (7.1.1)
65+
activemodel (= 7.1.1)
66+
activesupport (= 7.1.1)
67+
timeout (>= 0.4.0)
68+
activestorage (7.1.1)
69+
actionpack (= 7.1.1)
70+
activejob (= 7.1.1)
71+
activerecord (= 7.1.1)
72+
activesupport (= 7.1.1)
73+
marcel (~> 1.0)
74+
activesupport (7.1.1)
75+
base64
76+
bigdecimal
77+
concurrent-ruby (~> 1.0, >= 1.0.2)
78+
connection_pool (>= 2.2.5)
79+
drb
80+
i18n (>= 1.6, < 2)
81+
minitest (>= 5.1)
82+
mutex_m
83+
tzinfo (~> 2.0)
84+
base64 (0.2.0)
85+
bcrypt (3.1.19)
86+
bigdecimal (3.1.4)
87+
builder (3.2.4)
88+
concurrent-ruby (1.2.2)
89+
connection_pool (2.4.1)
90+
crass (1.0.6)
91+
date (3.3.4)
92+
drb (2.2.0)
93+
ruby2_keywords
94+
erubi (1.12.0)
95+
globalid (1.2.1)
96+
activesupport (>= 6.1)
97+
i18n (1.14.1)
98+
concurrent-ruby (~> 1.0)
99+
io-console (0.6.0)
100+
irb (1.8.3)
101+
rdoc
102+
reline (>= 0.3.8)
103+
loofah (2.21.4)
104+
crass (~> 1.0.2)
105+
nokogiri (>= 1.12.0)
106+
mail (2.8.1)
107+
mini_mime (>= 0.1.1)
108+
net-imap
109+
net-pop
110+
net-smtp
111+
marcel (1.0.2)
112+
mini_mime (1.1.5)
113+
minitest (5.20.0)
114+
mutex_m (0.2.0)
115+
net-imap (0.4.4)
116+
date
117+
net-protocol
118+
net-pop (0.1.2)
119+
net-protocol
120+
net-protocol (0.2.2)
121+
timeout
122+
net-smtp (0.4.0)
123+
net-protocol
124+
nio4r (2.5.9)
125+
nokogiri (1.15.4-arm64-darwin)
126+
racc (~> 1.4)
127+
psych (5.1.1.1)
128+
stringio
129+
puma (6.4.0)
130+
nio4r (~> 2.0)
131+
racc (1.7.3)
132+
rack (3.0.8)
133+
rack-session (2.0.0)
134+
rack (>= 3.0.0)
135+
rack-test (2.1.0)
136+
rack (>= 1.3)
137+
rackup (2.1.0)
138+
rack (>= 3)
139+
webrick (~> 1.8)
140+
rails (7.1.1)
141+
actioncable (= 7.1.1)
142+
actionmailbox (= 7.1.1)
143+
actionmailer (= 7.1.1)
144+
actionpack (= 7.1.1)
145+
actiontext (= 7.1.1)
146+
actionview (= 7.1.1)
147+
activejob (= 7.1.1)
148+
activemodel (= 7.1.1)
149+
activerecord (= 7.1.1)
150+
activestorage (= 7.1.1)
151+
activesupport (= 7.1.1)
152+
bundler (>= 1.15.0)
153+
railties (= 7.1.1)
154+
rails-dom-testing (2.2.0)
155+
activesupport (>= 5.0.0)
156+
minitest
157+
nokogiri (>= 1.6)
158+
rails-html-sanitizer (1.6.0)
159+
loofah (~> 2.21)
160+
nokogiri (~> 1.14)
161+
railties (7.1.1)
162+
actionpack (= 7.1.1)
163+
activesupport (= 7.1.1)
164+
irb
165+
rackup (>= 1.0.0)
166+
rake (>= 12.2)
167+
thor (~> 1.0, >= 1.2.2)
168+
zeitwerk (~> 2.6)
169+
rake (13.1.0)
170+
rdoc (6.6.0)
171+
psych (>= 4.0.0)
172+
reline (0.3.9)
173+
io-console (~> 0.5)
174+
ruby2_keywords (0.0.5)
175+
sprockets (4.2.1)
176+
concurrent-ruby (~> 1.0)
177+
rack (>= 2.2.4, < 4)
178+
sprockets-rails (3.4.2)
179+
actionpack (>= 5.2)
180+
activesupport (>= 5.2)
181+
sprockets (>= 3.0.0)
182+
sqlite3 (1.6.8-arm64-darwin)
183+
stringio (3.0.8)
184+
thor (1.3.0)
185+
timeout (0.4.1)
186+
tzinfo (2.0.6)
187+
concurrent-ruby (~> 1.0)
188+
webrick (1.8.1)
189+
websocket-driver (0.7.6)
190+
websocket-extensions (>= 0.1.0)
191+
websocket-extensions (0.1.5)
192+
zeitwerk (2.6.12)
193+
194+
PLATFORMS
195+
arm64-darwin-23
196+
197+
DEPENDENCIES
198+
action_auth!
199+
puma
200+
sprockets-rails
201+
sqlite3
202+
203+
BUNDLED WITH
204+
2.4.21

MIT-LICENSE

100644100755
File mode changed.

README.md

100644100755
+18-11
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@ This is a placeholder for the ActionAuth gem. It is not yet ready for use.
55
Add this line to your application's Gemfile:
66

77
```ruby
8-
gem "action_auth"
8+
bundle add action_auth
9+
bin/rails action_auth:install:migrations
910
```
11+
## Usage
1012

11-
And then execute:
12-
```bash
13-
$ bundle
14-
```
13+
### Routes
1514

16-
Or install it yourself as:
17-
```bash
18-
$ gem install action_auth
19-
```
15+
Within your application, you'll have access to these routes. They have been styled to be consistent with Devise.
16+
17+
Method Verb Params Description
18+
user_sessions_path GET Device session management
19+
user_session_path DELETE [:id] Log Out
20+
new_user_session_path GET Log in
21+
new_user_registration_path GET Sign Up
22+
23+
### Helper Methods
24+
25+
Method Description
26+
current_user Returns the currently logged in user
27+
user_signed_in? Returns true if the user is logged in
28+
current_session Returns the current session
2029

21-
## Contributing
22-
Contribution directions go here.
2330

2431
## License
2532
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

100644100755
File mode changed.

action_auth.gemspec

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
2323
end
2424

2525
spec.add_dependency "rails", "~> 7.1"
26+
spec.add_dependency "bcrypt", "~> 3.1.0"
2627
end

app/assets/config/action_auth_manifest.js

100644100755
File mode changed.

app/assets/images/action_auth/.keep

100644100755
File mode changed.

app/assets/stylesheets/action_auth/application.css

100644100755
File mode changed.

app/controllers/action_auth/application_controller.rb

100644100755
File mode changed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module ActionAuth
2+
class PasswordsController < ApplicationController
3+
before_action :set_user
4+
5+
def edit
6+
end
7+
8+
def update
9+
if @user.update(user_params)
10+
redirect_to root_path, notice: "Your password has been changed"
11+
else
12+
render :edit, status: :unprocessable_entity
13+
end
14+
end
15+
16+
private
17+
18+
def set_user
19+
@user = Current.user
20+
end
21+
22+
def user_params
23+
params.permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
24+
end
25+
end
26+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module ActionAuth
2+
class RegistrationsController < ApplicationController
3+
def new
4+
@user = User.new
5+
end
6+
7+
def create
8+
@user = User.new(user_params)
9+
10+
if @user.save!
11+
session_record = @user.action_auth_sessions.create!
12+
cookies.signed.permanent[:session_token] = { value: session_record.id, httponly: true }
13+
14+
send_email_verification
15+
redirect_to main_app.root_path, notice: "Welcome! You have signed up successfully"
16+
else
17+
render :new, status: :unprocessable_entity
18+
end
19+
end
20+
21+
private
22+
def user_params
23+
params.permit(:email, :password, :password_confirmation)
24+
end
25+
26+
def send_email_verification
27+
UserMailer.with(user: @user).email_verification.deliver_later
28+
end
29+
end
30+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module ActionAuth
2+
class SessionsController < ApplicationController
3+
before_action :set_current_request_details
4+
def index
5+
@sessions = Current.user.action_auth_sessions.order(created_at: :desc)
6+
end
7+
8+
def new
9+
end
10+
11+
def create
12+
if user = User.authenticate_by(email: params[:email], password: params[:password])
13+
@session = user.action_auth_sessions.create
14+
cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true }
15+
redirect_to main_app.root_path, notice: "Signed in successfully"
16+
else
17+
redirect_to sign_in_path(email_hint: params[:email]), alert: "That email or password is incorrect"
18+
end
19+
end
20+
21+
def destroy
22+
session = Current.user.action_auth_sessions.find(params[:id])
23+
session.destroy
24+
redirect_to(main_app.root_path, notice: "That session has been logged out")
25+
end
26+
end
27+
end

app/controllers/concerns/.keep

100644100755
File mode changed.

app/helpers/action_auth/application_helper.rb

100644100755
File mode changed.

app/jobs/action_auth/application_job.rb

100644100755
File mode changed.

app/mailers/action_auth/application_mailer.rb

100644100755
File mode changed.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ActionAuth
2+
class UserMailer < ApplicationMailer
3+
def password_reset
4+
@user = params[:user]
5+
@signed_id = @user.generate_token_for(:password_reset)
6+
7+
mail to: @user.email, subject: "Reset your password"
8+
end
9+
10+
def email_verification
11+
@user = params[:user]
12+
@signed_id = @user.generate_token_for(:email_verification)
13+
14+
mail to: @user.email, subject: "Verify your email"
15+
end
16+
end
17+
end

app/models/action_auth/application_record.rb

100644100755
File mode changed.

app/models/action_auth/current.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module ActionAuth
2+
class Current < ActiveSupport::CurrentAttributes
3+
attribute :session
4+
attribute :user_agent, :ip_address
5+
6+
delegate :action_auth_user, to: :session, allow_nil: true
7+
8+
def user
9+
action_auth_user
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)