oath-generators 1.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/NEWS.rdoc +20 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/lib/generators/oath/google_oauth2/google_oauth2_generator.rb +46 -0
- data/lib/generators/oath/migration/version.rb +11 -0
- data/lib/generators/oath/password_reset/password_reset_generator.rb +53 -0
- data/lib/generators/oath/scaffold/scaffold_generator.rb +49 -0
- data/lib/generators/oath/templates/app/controllers/external_credentials_controller.rb +13 -0
- data/lib/generators/oath/templates/app/controllers/password_resets_controller.rb +34 -0
- data/lib/generators/oath/templates/app/controllers/sessions_controller.rb +27 -0
- data/lib/generators/oath/templates/app/controllers/users_controller.rb +24 -0
- data/lib/generators/oath/templates/app/mailers/password_reset_mailer.rb +13 -0
- data/lib/generators/oath/templates/app/models/external_credential.rb +3 -0
- data/lib/generators/oath/templates/app/models/password_reset.rb +22 -0
- data/lib/generators/oath/templates/app/models/user.rb +4 -0
- data/lib/generators/oath/templates/app/services/external_authentication.rb +55 -0
- data/lib/generators/oath/templates/app/views/password_reset_mailer/change_password.html.erb +5 -0
- data/lib/generators/oath/templates/app/views/password_resets/create.html.erb +3 -0
- data/lib/generators/oath/templates/app/views/password_resets/edit.html.erb +16 -0
- data/lib/generators/oath/templates/app/views/password_resets/new.html.erb +16 -0
- data/lib/generators/oath/templates/app/views/sessions/new.html.erb +13 -0
- data/lib/generators/oath/templates/app/views/users/new.html.erb +23 -0
- data/lib/generators/oath/templates/config/initializers/omniauth.rb +4 -0
- data/lib/generators/oath/templates/config/locales/oath.en.yml +5 -0
- data/lib/generators/oath/templates/db/migrate/create_external_credentials.rb +11 -0
- data/lib/generators/oath/templates/db/migrate/create_password_resets.rb +10 -0
- data/lib/generators/oath/templates/db/migrate/create_users.rb +12 -0
- data/lib/generators/oath/templates/google_oauth2_readme +17 -0
- data/lib/generators/oath/templates/password_reset_readme +10 -0
- data/lib/generators/oath/templates/scaffold_readme +4 -0
- data/lib/oath/generators.rb +7 -0
- data/lib/oath/generators/version.rb +5 -0
- data/oath-generators.gemspec +24 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c08ce8a062758fcf1557a39d94f2745496ddd70
|
4
|
+
data.tar.gz: a31bb146ce2af0b557b662b615ce8ac2af2283e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc21f444f6a5f9c67f97ba16047e28ac1e81c0b5e2333de2b716478fa52c1ea9ec8eb086bb323727d218b7ad59a30b82ecb1cfe68520e40543c9822ba1ce3f20
|
7
|
+
data.tar.gz: ff5403914264f5734478200249b56ebb8200b6af3ed243b1f326b986a09299c574d99445c23d7e815ab29eeec8e45f70c4036a32018ac40c944403f0c7807179
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 halogenandtoast
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/NEWS.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
## 1.0.1
|
2
|
+
* Add backwards compatibility for Rails 4 migrations
|
3
|
+
|
4
|
+
## 1.0.0
|
5
|
+
* Update migrations to include migration version
|
6
|
+
|
7
|
+
## 0.0.6
|
8
|
+
* Add Google Oauth2
|
9
|
+
|
10
|
+
## 0.0.5
|
11
|
+
* Add `raise: false` to `before_action`s for Rails 5 compatibility
|
12
|
+
|
13
|
+
## 0.0.4
|
14
|
+
* Added locale file to generator
|
15
|
+
* Added display of error messages on users#new
|
16
|
+
|
17
|
+
## 0.0.3
|
18
|
+
* Fixed Version Constraint
|
19
|
+
* Made User model have validations by default to disallow NULL values
|
20
|
+
* Added NEWS.md
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Oath::Generators
|
2
|
+
|
3
|
+
Rails generators for adding in authentication components, using the
|
4
|
+
[Oath](https://github.com/halogenandtoast/oath) authentication library.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'oath-generators'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
## Generators
|
17
|
+
|
18
|
+
Currently these are the generators available:
|
19
|
+
|
20
|
+
### Scaffold
|
21
|
+
|
22
|
+
You can generate a basic starting point for any oath app by running the following:
|
23
|
+
|
24
|
+
rails g oath:scaffold
|
25
|
+
|
26
|
+
### Password Reset
|
27
|
+
|
28
|
+
If you'd like to generate basic password reset for your app, you can run:
|
29
|
+
|
30
|
+
rails g oath:password_reset
|
31
|
+
|
32
|
+
This will generate the necessary files for an implementation of resetting
|
33
|
+
a user's password. It will ask you for host names for development, test
|
34
|
+
and production environments in order to make the mailer work.
|
35
|
+
|
36
|
+
### Google Oauth 2
|
37
|
+
|
38
|
+
If you'd like setup basic google oauth authentication, you can run:
|
39
|
+
|
40
|
+
rails g oath:google_oauth2
|
41
|
+
|
42
|
+
This will generate the necessary files for an implementation of allowing users
|
43
|
+
to sign in either with an email/password or by using google oauth2.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. [Fork it](http://github.com/halogenandtoast/oath-generators/fork)
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/oath/migration/version'
|
3
|
+
|
4
|
+
module Oath
|
5
|
+
module Generators
|
6
|
+
class GoogleOauth2Generator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
include Oath::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.expand_path("../../templates", __FILE__)
|
11
|
+
|
12
|
+
def add_gems
|
13
|
+
gem "omniauth-google-oauth2"
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_services
|
17
|
+
template 'app/services/external_authentication.rb', 'app/services/external_authentication.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_initializer
|
21
|
+
template 'config/initializers/omniauth.rb', 'config/initializers/omniauth.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_routes
|
25
|
+
route(%{get "auth/:provider/callback" => "external_credentials#create"})
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_controllers
|
29
|
+
template 'app/controllers/external_credentials_controller.rb', 'app/controllers/external_credentials_controller.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.next_migration_number(dir)
|
33
|
+
ActiveRecord::Generators::Base.next_migration_number(dir)
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_model
|
37
|
+
template 'app/models/external_credential.rb', 'app/models/external_credential.rb'
|
38
|
+
migration_template "db/migrate/create_external_credentials.rb", "db/migrate/create_external_credentials.rb", migration_version: migration_version
|
39
|
+
end
|
40
|
+
|
41
|
+
def display_readme
|
42
|
+
readme 'google_oauth2_readme'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/oath/migration/version'
|
3
|
+
|
4
|
+
module Oath
|
5
|
+
module Generators
|
6
|
+
class PasswordResetGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
include Oath::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.expand_path("../../templates", __FILE__)
|
11
|
+
|
12
|
+
def add_config_options
|
13
|
+
%w(development test production).each do |env|
|
14
|
+
host = ask("What is the host to use for #{env}?")
|
15
|
+
application(%{config.action_mailer.default_url_options = { :host => "#{host}" }}, env: env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_routes
|
20
|
+
route("resources :password_resets, only: [:new, :create]")
|
21
|
+
route("resources :users, only: [:none] do\n resources :password_resets, only: [:edit, :update]\n end")
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_views
|
25
|
+
copy_file 'app/views/password_resets/create.html.erb'
|
26
|
+
copy_file 'app/views/password_resets/edit.html.erb'
|
27
|
+
copy_file 'app/views/password_resets/new.html.erb'
|
28
|
+
copy_file 'app/views/password_reset_mailer/change_password.html.erb'
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_mailers
|
32
|
+
template 'app/mailers/password_reset_mailer.rb', 'app/mailers/password_reset_mailer.rb'
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_controllers
|
36
|
+
template 'app/controllers/password_resets_controller.rb', 'app/controllers/password_resets_controller.rb'
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.next_migration_number(dir)
|
40
|
+
ActiveRecord::Generators::Base.next_migration_number(dir)
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_model
|
44
|
+
template 'app/models/password_reset.rb', 'app/models/password_reset.rb'
|
45
|
+
migration_template "db/migrate/create_password_resets.rb", "db/migrate/create_password_resets.rb", migration_version: migration_version
|
46
|
+
end
|
47
|
+
|
48
|
+
def display_readme
|
49
|
+
readme 'password_reset_readme'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/oath/migration/version'
|
3
|
+
|
4
|
+
module Oath
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
include Oath::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.expand_path("../../templates", __FILE__)
|
11
|
+
|
12
|
+
def add_routes
|
13
|
+
route("resources :users, only: [:new, :create]")
|
14
|
+
route("resource :session, only: [:new, :create, :destroy]")
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_views
|
18
|
+
copy_file 'app/views/users/new.html.erb'
|
19
|
+
copy_file 'app/views/sessions/new.html.erb'
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_controllers
|
23
|
+
template 'app/controllers/sessions_controller.rb', 'app/controllers/sessions_controller.rb'
|
24
|
+
template 'app/controllers/users_controller.rb', 'app/controllers/users_controller.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_helper_module_to_application_controller
|
28
|
+
inject_into_class "app/controllers/application_controller.rb", ApplicationController, " include Oath::ControllerHelpers\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.next_migration_number(dir)
|
32
|
+
ActiveRecord::Generators::Base.next_migration_number(dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_model
|
36
|
+
template 'app/models/user.rb', 'app/models/user.rb'
|
37
|
+
migration_template "db/migrate/create_users.rb", "db/migrate/create_users.rb", migration_version: migration_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_translations
|
41
|
+
template "config/locales/oath.en.yml"
|
42
|
+
end
|
43
|
+
|
44
|
+
def display_readme
|
45
|
+
readme 'scaffold_readme'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ExternalCredentialsController < ApplicationController
|
2
|
+
def create
|
3
|
+
credential = ExternalAuthentication.new(auth_hash).perform
|
4
|
+
sign_in credential.user
|
5
|
+
redirect_to root_path
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def auth_hash
|
11
|
+
request.env["omniauth.auth"]
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class PasswordResetsController < ApplicationController
|
2
|
+
skip_before_action :require_login, only: [:new, :create, :edit, :update], raise: false
|
3
|
+
|
4
|
+
def new
|
5
|
+
@password_reset = PasswordReset.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
user = User.find_by(email: params[:password_reset][:email])
|
10
|
+
if user
|
11
|
+
password_reset = PasswordReset.create(user: user)
|
12
|
+
PasswordResetMailer.change_password(password_reset).deliver_now # NOTE: You'll want to delay this
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@password_reset = PasswordReset.find_by!(token: params[:id], user_id: params[:user_id])
|
18
|
+
@user = @password_reset.user
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@password_reset = PasswordReset.find_by!(token: params[:id], user_id: params[:user_id])
|
23
|
+
@user = @password_reset.user
|
24
|
+
|
25
|
+
reset_password(@user, params[:password_reset][:password])
|
26
|
+
|
27
|
+
if @user.save
|
28
|
+
sign_in @user
|
29
|
+
redirect_to root_path
|
30
|
+
else
|
31
|
+
render :edit
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
skip_before_action :require_login, only: [:new, :create], raise: false
|
3
|
+
|
4
|
+
def new
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
user = authenticate_session(session_params)
|
9
|
+
|
10
|
+
if sign_in(user)
|
11
|
+
redirect_to root_path
|
12
|
+
else
|
13
|
+
render :new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
sign_out
|
19
|
+
redirect_to root_path
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def session_params
|
25
|
+
params.require(:session).permit(:email, :password)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
skip_before_action :require_login, only: [:new, :create], raise: false
|
3
|
+
|
4
|
+
def new
|
5
|
+
@user = User.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
@user = sign_up(user_params)
|
10
|
+
|
11
|
+
if @user.valid?
|
12
|
+
sign_in(@user)
|
13
|
+
redirect_to root_path
|
14
|
+
else
|
15
|
+
render :new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def user_params
|
22
|
+
params.require(:user).permit(:email, :password)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class PasswordResetMailer < ActionMailer::Base
|
2
|
+
default from: "noreply@example.com" # NOTE: You'll want to change this
|
3
|
+
|
4
|
+
def change_password(password_reset)
|
5
|
+
@password_reset = password_reset
|
6
|
+
@user = password_reset.user
|
7
|
+
|
8
|
+
mail(
|
9
|
+
to: @user.email,
|
10
|
+
subject: 'Change your password'
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class PasswordReset < ActiveRecord::Base
|
2
|
+
belongs_to :user
|
3
|
+
before_create :generate_unique_token
|
4
|
+
delegate :email, to: :user, allow_nil: true
|
5
|
+
|
6
|
+
def to_param
|
7
|
+
token
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def generate_unique_token
|
13
|
+
self.token = generate_token
|
14
|
+
while PasswordReset.exists?(token: self.token)
|
15
|
+
self.token = generate_token
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_token
|
20
|
+
SecureRandom.hex(20).encode('UTF-8')
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class ExternalAuthentication
|
2
|
+
def initialize(auth_hash)
|
3
|
+
@auth_hash = auth_hash
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
if scope.exists?
|
8
|
+
scope.first
|
9
|
+
else
|
10
|
+
transaction { scope.create(user: user) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :auth_hash
|
17
|
+
|
18
|
+
def user
|
19
|
+
User.find_by(email: email) || create_user
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_user
|
23
|
+
Oath::Services::SignUp.new(user_params).perform
|
24
|
+
end
|
25
|
+
|
26
|
+
def transaction(&block)
|
27
|
+
ExternalCredential.transaction(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_params
|
31
|
+
{
|
32
|
+
email: email,
|
33
|
+
password: random_password
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def email
|
38
|
+
auth_hash["info"]["email"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def random_password
|
42
|
+
SecureRandom.hex
|
43
|
+
end
|
44
|
+
|
45
|
+
def scope
|
46
|
+
ExternalCredential.where(credential_params)
|
47
|
+
end
|
48
|
+
|
49
|
+
def credential_params
|
50
|
+
{
|
51
|
+
provider: auth_hash["provider"],
|
52
|
+
uid: auth_hash["uid"]
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="password-reset">
|
2
|
+
<h2>Change your password</h2>
|
3
|
+
|
4
|
+
<p>Your password has been reset. Choose a new password below.</p>
|
5
|
+
|
6
|
+
<%= form_for [@user, @password_reset] do |form| %>
|
7
|
+
<div class="password-field">
|
8
|
+
<%= form.label :password %>
|
9
|
+
<%= form.password_field :password, require: true %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="submit-field">
|
13
|
+
<%= form.submit 'Update Password' %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="password-reset">
|
2
|
+
<h2>Reset your password</h2>
|
3
|
+
|
4
|
+
<p>To be emailed a link to reset your password, please enter your email address.</p>
|
5
|
+
|
6
|
+
<%= form_for @password_reset do |form| %>
|
7
|
+
<div class="text-field">
|
8
|
+
<%= form.label :email %>
|
9
|
+
<%= form.email_field :email, require: true %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="submit-field">
|
13
|
+
<%= form.submit 'Reset Password' %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= form_for :session, url: session_path do |form| %>
|
2
|
+
<div>
|
3
|
+
<%= form.label :email %>
|
4
|
+
<%= form.email_field :email %>
|
5
|
+
</div>
|
6
|
+
<div>
|
7
|
+
<%= form.label :password %>
|
8
|
+
<%= form.password_field :password %>
|
9
|
+
</div>
|
10
|
+
<div>
|
11
|
+
<%= form.submit "Sign in" %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= form_for @user do |form| %>
|
2
|
+
|
3
|
+
<% if @user.errors.any? %>
|
4
|
+
<%= pluralize(@user.errors.count, "error") %> prevented your account from being created:
|
5
|
+
<ul>
|
6
|
+
<% @user.errors.full_messages.each do |error_message| %>
|
7
|
+
<li><%= error_message %></li>
|
8
|
+
<% end %>
|
9
|
+
</ul>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div>
|
13
|
+
<%= form.label :email %>
|
14
|
+
<%= form.email_field :email, require: true %>
|
15
|
+
</div>
|
16
|
+
<div>
|
17
|
+
<%= form.label :password %>
|
18
|
+
<%= form.password_field :password, require: true %>
|
19
|
+
</div>
|
20
|
+
<div>
|
21
|
+
<%= form.submit "Sign up" %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :email, null: false
|
5
|
+
t.string :password_digest, null: false
|
6
|
+
|
7
|
+
t.timestamps null: false
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :users, :email, unique: true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Final Steps
|
2
|
+
Set the following environment variables:
|
3
|
+
- GOOGLE_CLIENT_ID
|
4
|
+
- GOOGLE_CLIENT_SECRET
|
5
|
+
|
6
|
+
These can be obtained from: https://console.developers.google.com
|
7
|
+
|
8
|
+
Run
|
9
|
+
|
10
|
+
rake db:migrate
|
11
|
+
|
12
|
+
Add the following to the correct sign in/up templates:
|
13
|
+
|
14
|
+
|
15
|
+
<%= link_to "Sign in with Google+", "/auth/google_oauth2" %>
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oath/generators/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oath-generators"
|
8
|
+
spec.version = Oath::Generators::VERSION
|
9
|
+
spec.authors = ["halogenandtoast"]
|
10
|
+
spec.email = ["halogenandtoast@gmail.com"]
|
11
|
+
spec.summary = %q{Rails generators for the oath authentication library}
|
12
|
+
spec.description = %q{Generators to add in different forms of user authentication to a rails application.}
|
13
|
+
spec.homepage = "http://github.com/halogenandtoast/oath-generators"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "oath", ">= 0.0.12"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oath-generators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- halogenandtoast
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oath
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.12
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.12
|
55
|
+
description: Generators to add in different forms of user authentication to a rails
|
56
|
+
application.
|
57
|
+
email:
|
58
|
+
- halogenandtoast@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- NEWS.rdoc
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/generators/oath/google_oauth2/google_oauth2_generator.rb
|
70
|
+
- lib/generators/oath/migration/version.rb
|
71
|
+
- lib/generators/oath/password_reset/password_reset_generator.rb
|
72
|
+
- lib/generators/oath/scaffold/scaffold_generator.rb
|
73
|
+
- lib/generators/oath/templates/app/controllers/external_credentials_controller.rb
|
74
|
+
- lib/generators/oath/templates/app/controllers/password_resets_controller.rb
|
75
|
+
- lib/generators/oath/templates/app/controllers/sessions_controller.rb
|
76
|
+
- lib/generators/oath/templates/app/controllers/users_controller.rb
|
77
|
+
- lib/generators/oath/templates/app/mailers/password_reset_mailer.rb
|
78
|
+
- lib/generators/oath/templates/app/models/external_credential.rb
|
79
|
+
- lib/generators/oath/templates/app/models/password_reset.rb
|
80
|
+
- lib/generators/oath/templates/app/models/user.rb
|
81
|
+
- lib/generators/oath/templates/app/services/external_authentication.rb
|
82
|
+
- lib/generators/oath/templates/app/views/password_reset_mailer/change_password.html.erb
|
83
|
+
- lib/generators/oath/templates/app/views/password_resets/create.html.erb
|
84
|
+
- lib/generators/oath/templates/app/views/password_resets/edit.html.erb
|
85
|
+
- lib/generators/oath/templates/app/views/password_resets/new.html.erb
|
86
|
+
- lib/generators/oath/templates/app/views/sessions/new.html.erb
|
87
|
+
- lib/generators/oath/templates/app/views/users/new.html.erb
|
88
|
+
- lib/generators/oath/templates/config/initializers/omniauth.rb
|
89
|
+
- lib/generators/oath/templates/config/locales/oath.en.yml
|
90
|
+
- lib/generators/oath/templates/db/migrate/create_external_credentials.rb
|
91
|
+
- lib/generators/oath/templates/db/migrate/create_password_resets.rb
|
92
|
+
- lib/generators/oath/templates/db/migrate/create_users.rb
|
93
|
+
- lib/generators/oath/templates/google_oauth2_readme
|
94
|
+
- lib/generators/oath/templates/password_reset_readme
|
95
|
+
- lib/generators/oath/templates/scaffold_readme
|
96
|
+
- lib/oath/generators.rb
|
97
|
+
- lib/oath/generators/version.rb
|
98
|
+
- oath-generators.gemspec
|
99
|
+
homepage: http://github.com/halogenandtoast/oath-generators
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.6.13
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Rails generators for the oath authentication library
|
123
|
+
test_files: []
|