Skip to content

Commit

Permalink
First working version
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jan 12, 2023
0 parents commit 88708b4
Show file tree
Hide file tree
Showing 83 changed files with 1,596 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.bundle/
/doc/
/log/*.log
/pkg/
/tmp/
/test/dummy/db/*.sqlite3
/test/dummy/db/*.sqlite3-*
/test/dummy/log/*.log
/test/dummy/storage/
/test/dummy/tmp/
15 changes: 15 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Specify your gem's dependencies in revise_auth.gemspec.
gemspec

gem "puma"
gem "sqlite3"
gem "web-console"
gem "sprockets-rails"
gem "turbo-rails"
gem "importmap-rails"

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
186 changes: 186 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
PATH
remote: .
specs:
revise_auth (0.1.0)
bcrypt (~> 3.1)
rails (>= 7.0.4)

GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.4)
actionpack (= 7.0.4)
activejob (= 7.0.4)
activerecord (= 7.0.4)
activestorage (= 7.0.4)
activesupport (= 7.0.4)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.4)
actionpack (= 7.0.4)
actionview (= 7.0.4)
activejob (= 7.0.4)
activesupport (= 7.0.4)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.4)
actionview (= 7.0.4)
activesupport (= 7.0.4)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.4)
actionpack (= 7.0.4)
activerecord (= 7.0.4)
activestorage (= 7.0.4)
activesupport (= 7.0.4)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.4)
activesupport (= 7.0.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.4)
activesupport (= 7.0.4)
globalid (>= 0.3.6)
activemodel (7.0.4)
activesupport (= 7.0.4)
activerecord (7.0.4)
activemodel (= 7.0.4)
activesupport (= 7.0.4)
activestorage (7.0.4)
actionpack (= 7.0.4)
activejob (= 7.0.4)
activerecord (= 7.0.4)
activesupport (= 7.0.4)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
bcrypt (3.1.18)
bindex (0.8.1)
builder (3.2.4)
concurrent-ruby (1.1.10)
crass (1.0.6)
date (3.3.3)
erubi (1.12.0)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.0)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.17.0)
net-imap (0.3.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.13.10-arm64-darwin)
racc (~> 1.4)
puma (6.0.2)
nio4r (~> 2.0)
racc (1.6.2)
rack (2.2.5)
rack-test (2.0.2)
rack (>= 1.3)
rails (7.0.4)
actioncable (= 7.0.4)
actionmailbox (= 7.0.4)
actionmailer (= 7.0.4)
actionpack (= 7.0.4)
actiontext (= 7.0.4)
actionview (= 7.0.4)
activejob (= 7.0.4)
activemodel (= 7.0.4)
activerecord (= 7.0.4)
activestorage (= 7.0.4)
activesupport (= 7.0.4)
bundler (>= 1.15.0)
railties (= 7.0.4)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.4)
loofah (~> 2.19, >= 2.19.1)
railties (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.5.4-arm64-darwin)
thor (1.2.1)
timeout (0.3.1)
turbo-rails (1.3.2)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.6)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
importmap-rails
puma
revise_auth!
sprockets-rails
sqlite3
turbo-rails
web-console

BUNDLED WITH
2.4.3
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2023 Chris Oliver

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ReviseAuth
Short description and motivation.

## Usage
How to use my plugin.

## Installation
Add this line to your application's Gemfile:

```ruby
gem "revise_auth"
```

And then execute:
```bash
$ bundle
```

Or install it yourself as:
```bash
$ gem install revise_auth
```

## Contributing
Contribution directions go here.

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "bundler/setup"

require "bundler/gem_tasks"
29 changes: 29 additions & 0 deletions app/controllers/revise_auth/email_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class ReviseAuth::EmailController < ReviseAuthController
before_action :authenticate_user!, except: [:show]

# GET /profile/email?confirmation_token=abcdef
def show
if User.find_by(confirmation_token: params[:confirmation_token])&.confirm_email_change
flash[:notice] = "Your email address has been successfully confirmed."
user_signed_in?
redirect_to (user_signed_in? ? profile_path : root_path)
else
redirect_to root_path, alert: "Unable to confirm email address."
end
end

def update
if current_user.update(email_params)
current_user.send_confirmation_instructions
flash[:notice] = "A confirmation email has been sent to #{current_user.unconfirmed_email}"
end

redirect_to profile_path
end

private

def email_params
params.require(:user).permit(:unconfirmed_email)
end
end
17 changes: 17 additions & 0 deletions app/controllers/revise_auth/password_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ReviseAuth::PasswordController < ReviseAuthController
before_action :validate_current_password, only: [:update]

def update
if current_user.update(password_params)
flash[:notice] = "Your password has been changed successfully."
end

redirect_to profile_path
end

private

def password_params
params.require(:user).permit(:password, :password_confirmation)
end
end
44 changes: 44 additions & 0 deletions app/controllers/revise_auth/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class ReviseAuth::RegistrationsController < ReviseAuthController
before_action :authenticate_user!, except: [:new, :create]

def new
@user = User.new
end

def create
@user = User.new(sign_up_params)
if @user.save
login(@user)
redirect_to root_path
else
render :new, status: :unprocessable_entity
end
end

def edit
end

def update
if current_user.update(profile_params)
redirect_to profile_path, notice: "Account updated successfully."
else
render :edit, status: :unprocessable_entity
end
end

def destroy
current_user.destroy
logout
redirect_to root_path, status: :see_other, alert: I18n.t("revise_auth.account_deleted")
end

private

def sign_up_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end

def profile_params
params.require(:user).permit(:name)
end
end
19 changes: 19 additions & 0 deletions app/controllers/revise_auth/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class ReviseAuth::SessionsController < ReviseAuthController
def new
end

def create
if user = User.find_by(email: params[:email])&.authenticate(params[:password])
login(user)
redirect_to root_path
else
flash[:alert] = I18n.t("revise_auth.invalid_email_or_password")
render :new, status: :unprocessable_entity
end
end

def destroy
logout
redirect_to root_path
end
end
8 changes: 8 additions & 0 deletions app/controllers/revise_auth_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ReviseAuthController < ApplicationController
def validate_current_password
unless current_user.authenticate(params[:current_password])
flash[:alert] = "Your current password is incorrect. Please try again."
render :edit, status: :unprocessable_entity
end
end
end
5 changes: 5 additions & 0 deletions app/mailers/revise_auth/mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ReviseAuth::Mailer < ApplicationMailer
def confirm_email
mail to: params[:user].unconfirmed_email
end
end
Loading

0 comments on commit 88708b4

Please sign in to comment.